2020-06-20 16:59:51 +08:00
|
|
|
|
#ifndef _HTTPDNS_
|
|
|
|
|
#define _HTTPDNS_
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <sys/types.h>
|
2020-07-30 18:10:31 +08:00
|
|
|
|
#include <sys/socket.h>
|
2020-06-20 16:59:51 +08:00
|
|
|
|
#include <arpa/inet.h>
|
2020-07-30 18:10:31 +08:00
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
#include <errno.h>
|
2020-06-20 16:59:51 +08:00
|
|
|
|
#include <stdlib.h>
|
2020-07-30 18:10:31 +08:00
|
|
|
|
#include <string.h>
|
2020-06-20 16:59:51 +08:00
|
|
|
|
#include <netdb.h>
|
2020-07-30 18:10:31 +08:00
|
|
|
|
#include <unistd.h>
|
2020-06-20 16:59:51 +08:00
|
|
|
|
#include <pthread.h>
|
2020-07-30 18:10:31 +08:00
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <sys/epoll.h>
|
2020-06-20 16:59:51 +08:00
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
2020-07-30 18:10:31 +08:00
|
|
|
|
#include "conf.h"
|
|
|
|
|
|
|
|
|
|
#define DNS_MAX_CONNECTION 256 //此值的大小关系到respod_clients函数的效率
|
|
|
|
|
#define DATA_SIZE 512
|
|
|
|
|
#define HTTP_RSP_SIZE 1024
|
2020-06-20 16:59:51 +08:00
|
|
|
|
|
2020-07-30 18:10:31 +08:00
|
|
|
|
typedef struct dns_connection {
|
|
|
|
|
char dns_req[DATA_SIZE];
|
|
|
|
|
struct sockaddr_in src_addr;
|
|
|
|
|
char *reply; //回应内容
|
|
|
|
|
char *http_request, *host;
|
|
|
|
|
unsigned int http_request_len, dns_rsp_len;
|
2020-06-20 16:59:51 +08:00
|
|
|
|
int fd;
|
2020-07-30 18:10:31 +08:00
|
|
|
|
char query_type;
|
|
|
|
|
unsigned host_len :7; //域名最大长度64位
|
|
|
|
|
unsigned wait_response_client :1; //已构建好DNS回应,等待可写事件
|
2020-06-20 16:59:51 +08:00
|
|
|
|
} dns_t;
|
|
|
|
|
|
2020-07-30 18:10:31 +08:00
|
|
|
|
struct dns_cache {
|
|
|
|
|
int question_len;
|
|
|
|
|
char *question;
|
|
|
|
|
char *answer;
|
|
|
|
|
struct dns_cache *next;
|
2020-06-20 16:59:51 +08:00
|
|
|
|
};
|
|
|
|
|
|
2020-07-30 18:10:31 +08:00
|
|
|
|
dns_t dns_list[DNS_MAX_CONNECTION];
|
|
|
|
|
struct epoll_event evs[DNS_MAX_CONNECTION+1], ev;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void *httpdns_loop(void *p);
|
|
|
|
|
int httpdns_initialize(conf * configure);
|
|
|
|
|
|
2020-06-20 16:59:51 +08:00
|
|
|
|
|
|
|
|
|
#endif
|