通过ssl发送dns查询

时间:2013-12-25 05:47:55

标签: linux ssl dns resolve

我需要ds over ssl。 DNS查询是UDP打包的,我需要将其更改为SSL协议吗?

它在linux中工作。

ubuntu 12.04如何解析dns以及如何更改为SSL?

我尝试过创建ssl套接字并发送dns查询。

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <sys/socket.h>
#include <resolv.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <netdb.h>

#include <openssl/rsa.h> 
#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
//#include "server.h"
#define FAIL    -1

void initChild(int cli, SSL_CTX* ctx);

void error(const char *msg) {
    perror(msg);
    exit(1);
}

int main(int count, char *strings[]) {
    SSL_CTX *ctx;
    int server;
    char *portnum;
    SSL*     ssl;
    int cli;
    struct hostent *hp;
    int pid;
    if (count != 2)
    {
        printf("Usage: %s <portnum>\n", strings[0]);
        exit(0);
    }
    SSL_library_init();
    portnum = strings[1];
    ctx = InitServerCTX();
    LoadCertificates(ctx, "ser-cert.pem", "ser-key.pem");
    server = OpenListener(atoi(portnum));
    while (1) {
        struct sockaddr_in addr;
        int len = sizeof(addr);
        int cli = accept(server, (struct sockaddr*)&addr, &len);

        if (!(pid = fork())) {
            //Child process
            //close(server);
            initChild(cli, ctx);
            exit(0);
        }
        else if (pid > 0) {
            //Parent process
        }
        else {
            printf("Fork failed!!");
            //close(server);
        }
    }
    close(server);
    SSL_CTX_free(ctx);

    return 0;
}

void initChild(int cli, SSL_CTX* ctx) {
    SSL*     ssl;
    ssl = SSL_new(ctx);
    SSL_set_fd(ssl, cli);
    DnsData(ssl);
}

这适用于终端模式。现在我需要将终端模式更改为GUI模式。 GUI模式是Web浏览器。此代码使用由我生成的ssl证书。如何在c?

中编写简单的ssl dns查询Web浏览器

0 个答案:

没有答案
相关问题