The getaddrinfo () function is no longer used, the static compilation libc dependency is removed, and the configuration file server address is no longer supported to fill in the domain name.
This commit is contained in:
parent
627051ac94
commit
9aa4d19547
0
Android.mk
Normal file → Executable file
0
Android.mk
Normal file → Executable file
0
Application.mk
Normal file → Executable file
0
Application.mk
Normal file → Executable file
@ -4,12 +4,11 @@ global {
|
||||
timeout=1;
|
||||
encode=128;
|
||||
tcp_listen=0124;
|
||||
tcp6_listen=0125;
|
||||
dns_listen=0126;
|
||||
}
|
||||
|
||||
http {
|
||||
http_ip="47.240.75.93";
|
||||
http_ip="2408:8221:9916:15e0:3cf9:3d8d:64ac:b880";
|
||||
http_port=127;
|
||||
http_del="Host";
|
||||
http_first="[M] http://[host][U] [V]\r\nHost: [H]\r\n";
|
||||
@ -18,7 +17,7 @@ http {
|
||||
}
|
||||
|
||||
https {
|
||||
https_ip="174.137.54.215";
|
||||
https_ip="127.0.0.1";
|
||||
https_port=127;
|
||||
https_del="Host,host,x-online-host";
|
||||
https_first="[M] [U] [V]\r\nHost: [host]\r\n";
|
||||
|
@ -33,12 +33,12 @@ httpdns {
|
||||
|
||||
|
||||
global模块
|
||||
uid=3004; //进程UID
|
||||
process=2; //进程数量(已经弃用)
|
||||
timeout=60; //超时时间(秒)
|
||||
sslencoding=128; //编码(非零生效)
|
||||
uid=3004; //进程UID
|
||||
process=2; //进程数量(已经弃用)
|
||||
timeout=60; //超时时间(秒)
|
||||
sslencoding=128; //编码(非零生效)
|
||||
tcp_listen=0124; //TCP监听端口
|
||||
tcp6_listen=0124; //TCP6监听端口 (TCP和TCP6可以使用同一个端口, IPV4的数据走内部IPV4程序结构, IPV6数据走内部IPV6程序结构.)
|
||||
tcp6_listen=0124; //TCP6监听端口 (TCP和TCP6可以使用同一个端口, IPV4的数据走内部IPV4程序结构, IPV6数据走内部IPV6程序结构.)(已经弃用)
|
||||
dns_listen=0125; //UDP监听端口
|
||||
|
||||
|
||||
@ -52,18 +52,19 @@ http、https 模块关键字: [M], [method], [uri], [U], [V], [version], [H], [h
|
||||
[port] 原请求端口
|
||||
[H] 原请求[host]:[port]
|
||||
|
||||
http_ip=cproxy.aixiao.me; //指定HTTP服务器IP
|
||||
http_port=124; //指定HTTP服务器端口
|
||||
http_del="x-online-host,X-Online-Host,host,Host"; //删除HTTP头字段,逗号分开
|
||||
http_first="[M] [U] [V]\r\nHost: [H]\r\n"; //自定义HTTP头
|
||||
http_ip=47.240.75.93; //指定HTTP服务器IP
|
||||
http_port=127; //指定HTTP服务器端口
|
||||
http_del="x-online-host,X-Online-Host,host,Host"; //删除HTTP头字段,逗号分开
|
||||
http_first="[M] [U] [V]\r\nHost: [H]\r\n"; //自定义HTTP请求头
|
||||
关键字strrep替换字符串指令.
|
||||
strrep = "Mi MIX 2->Linux"; 以"->"为分界符,"Mi MIX 2"字符串替换为"Linux"字符串.
|
||||
strrep = "Mi MIX 2->Linux"; //以"->"为分界符,"Mi MIX 2"字符串替换为"Linux"字符串.
|
||||
关键字regrep正则匹配替换字符串.
|
||||
regrep = "Host*.+?->Host: iread.wo.cn:443"; 以"->"为分界符,匹配到的内容"Host*.+?"替换为"Host: iread.wo.cn:443"字符串.
|
||||
regrep = "Host*.+?->Host: iread.wo.cn:443"; //以"->"为分界符,匹配到的内容"Host*.+?"替换为"Host: iread.wo.cn:443"字符串.
|
||||
|
||||
httpdns模块
|
||||
httpdns 模块关键字: [M], [D], [V], \r, \n, \v, \f, \b, \t, \a.
|
||||
默认 [M] 为 GET
|
||||
默认 [V] 为 HTTP/1.0
|
||||
addr=119.29.29.29:80; //HTTPDNS服务器IP
|
||||
addr=119.29.29.29:80; //HTTPDNS服务器IP
|
||||
http_req = "[M] [U] [V]\r\nHost: [H]\r\n\r\n"; //自定义HTTPDNS请求头
|
||||
|
||||
|
88
http_proxy.c
88
http_proxy.c
@ -121,7 +121,13 @@ static int8_t request_type(char *data)
|
||||
strncmp(data, "PUT", 3) == 0 ||
|
||||
strncmp(data, "OPTIONS", 7) == 0 ||
|
||||
strncmp(data, "MOVE", 4) == 0 ||
|
||||
strncmp(data, "COPY", 4) == 0 || strncmp(data, "TRACE", 5) == 0 || strncmp(data, "DELETE", 6) == 0 || strncmp(data, "LINK", 4) == 0 || strncmp(data, "UNLINK", 6) == 0 || strncmp(data, "PATCH", 5) == 0 || strncmp(data, "WRAPPED", 7) == 0)
|
||||
strncmp(data, "COPY", 4) == 0 ||
|
||||
strncmp(data, "TRACE", 5) == 0 ||
|
||||
strncmp(data, "DELETE", 6) == 0 ||
|
||||
strncmp(data, "LINK", 4) == 0 ||
|
||||
strncmp(data, "UNLINK", 6) == 0 ||
|
||||
strncmp(data, "PATCH", 5) == 0 ||
|
||||
strncmp(data, "WRAPPED", 7) == 0)
|
||||
return HTTP_TYPE;
|
||||
return OTHER_TYPE;
|
||||
}
|
||||
@ -138,12 +144,14 @@ int check_ipversion(char *address)
|
||||
return AF_INET6;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int create_connection6(char *remote_host, int remote_port)
|
||||
{
|
||||
struct addrinfo hints, *res = NULL;
|
||||
struct addrinfo hints;
|
||||
//struct addrinfo *res = NULL;
|
||||
int sock;
|
||||
int validfamily = 0;
|
||||
char portstr[CACHE_SIZE];
|
||||
@ -161,13 +169,16 @@ int create_connection6(char *remote_host, int remote_port)
|
||||
hints.ai_family = validfamily;
|
||||
hints.ai_flags |= AI_NUMERICHOST; // remote_host是有效的数字ip,跳过解析
|
||||
}
|
||||
|
||||
/*
|
||||
//getaddrinfo方法
|
||||
// 检查指定的主机是否有效。 如果remote_host是主机名,尝试解析地址
|
||||
if (getaddrinfo(remote_host, portstr, &hints, &res) != 0) {
|
||||
errno = EFAULT;
|
||||
perror("getaddrinfo");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if ((sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
|
||||
perror("socket");
|
||||
return -1;
|
||||
@ -178,9 +189,80 @@ int create_connection6(char *remote_host, int remote_port)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (res != NULL)
|
||||
freeaddrinfo(res);
|
||||
*/
|
||||
|
||||
//通用sockaddr_storage结构体
|
||||
struct sockaddr_storage remote_addr;
|
||||
memset(&remote_addr, 0, sizeof(struct sockaddr_storage));
|
||||
if (validfamily == AF_INET) {
|
||||
struct sockaddr_in *addr_v4 = (struct sockaddr_in *)&remote_addr;
|
||||
addr_v4->sin_family = AF_INET;
|
||||
addr_v4->sin_port = htons(remote_port);
|
||||
inet_aton(remote_host, &(addr_v4->sin_addr));
|
||||
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
perror("socket");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
struct sockaddr_in6 *addr_v6 = (struct sockaddr_in6 *)&remote_addr;
|
||||
addr_v6->sin6_family = AF_INET6;
|
||||
addr_v6->sin6_port = htons(remote_port);
|
||||
inet_pton(AF_INET6, remote_host, &(addr_v6->sin6_addr));
|
||||
if ((sock = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
|
||||
perror("socket");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (connect(sock, (struct sockaddr *)&remote_addr, sizeof(struct sockaddr_storage)) < 0) {
|
||||
perror("connect");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
//普通方法
|
||||
if (validfamily == AF_INET) {
|
||||
struct sockaddr_in remote_addr;
|
||||
memset(&remote_addr, 0, sizeof(remote_addr));
|
||||
remote_addr.sin_family = AF_INET;
|
||||
remote_addr.sin_port = htons(remote_port);
|
||||
remote_addr.sin_addr.s_addr = inet_addr(remote_host);
|
||||
|
||||
if ((sock = socket(validfamily, SOCK_STREAM, 0)) < 0) {
|
||||
perror("socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (connect(sock, (struct sockaddr *)&remote_addr, sizeof(remote_addr)) < 0) {
|
||||
perror("connect");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sock;
|
||||
} else {
|
||||
struct sockaddr_in6 remote_addr;
|
||||
memset(&remote_addr, 0, sizeof(remote_addr));
|
||||
remote_addr.sin6_family = AF_INET6;
|
||||
remote_addr.sin6_port = htons(remote_port);
|
||||
inet_pton(AF_INET6, remote_host, &(remote_addr.sin6_addr));
|
||||
|
||||
if ((sock = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
|
||||
perror("socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (connect(sock, (struct sockaddr *)&remote_addr, sizeof(remote_addr)) < 0) {
|
||||
perror("connect");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
*/
|
||||
return sock;
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,7 @@ int extract_host(char *header, char *host, char *port)
|
||||
|
||||
if (p2 && p2 < p1) {
|
||||
memcpy(port, p2 + 1, (int)(p1 - p2 - 1));
|
||||
memcpy(host, p + 5 + 1, (int)(p2 - p - 5 - 1 - 1));
|
||||
memcpy(host, p + 5 + 1, (int)(p2 - p - 5 - 1));
|
||||
} else {
|
||||
if (0 < (int)(p1 - p - 5 - 1 - 1)) {
|
||||
memcpy(host, p + 5 + 1, (p1 - p - 5 - 1 - 1));
|
||||
@ -285,6 +285,8 @@ int extract_host(char *header, char *host, char *port)
|
||||
memcpy(port, "80", 2);
|
||||
}
|
||||
}
|
||||
//printf("%s\n", host);
|
||||
//printf("%s\n", port);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -392,14 +394,14 @@ void parse_request_head(char *http_request_line, struct http_request *http_reque
|
||||
}
|
||||
|
||||
head_len = strlen(http_request_line) - strlen(p);
|
||||
head = (char *)malloc(sizeof(char) * head_len * 2);
|
||||
head = (char *)malloc(sizeof(char) * head_len + 1);
|
||||
if (head == NULL)
|
||||
free(head);
|
||||
memset(head, 0, head_len * 2);
|
||||
memset(head, 0, sizeof(char) * head_len + 1);
|
||||
memcpy(head, http_request_line, head_len);
|
||||
|
||||
http_request->method = (char *)malloc(sizeof(char) * 7);
|
||||
http_request->U = (char *)malloc(sizeof(char) * HTTP_HEAD_CACHE_SIZE);
|
||||
http_request->method = (char *)malloc(sizeof(char) * 8);
|
||||
http_request->U = (char *)malloc(sizeof(char) * head_len);
|
||||
http_request->version = (char *)malloc(10);
|
||||
if (http_request->method == NULL) {
|
||||
perror("malloc");
|
||||
@ -410,8 +412,8 @@ void parse_request_head(char *http_request_line, struct http_request *http_reque
|
||||
if (http_request->version == NULL) {
|
||||
perror("malloc");
|
||||
}
|
||||
memset(http_request->method, 0, 7);
|
||||
memset(http_request->U, 0, HTTP_HEAD_CACHE_SIZE);
|
||||
memset(http_request->method, 0, 8);
|
||||
memset(http_request->U, 0, sizeof(char) * head_len);
|
||||
memset(http_request->version, 0, 10);
|
||||
|
||||
m = strchr(head, ' ');
|
||||
|
@ -49,7 +49,7 @@ int8_t read_cache_file()
|
||||
char *buff, *cache_ptr;
|
||||
struct dns_cache *cache_temp;
|
||||
long file_size;
|
||||
int len;
|
||||
int len, fl=0;
|
||||
|
||||
cache_temp = NULL;
|
||||
cache_using = 0;
|
||||
@ -69,7 +69,8 @@ int8_t read_cache_file()
|
||||
if ((buff = (char *)alloca(file_size)) == NULL)
|
||||
return 1;
|
||||
rewind(cfp);
|
||||
fread(buff, file_size, 1, cfp);
|
||||
if ((fl = fread(buff, file_size, 1, cfp)) != 1)
|
||||
;
|
||||
fclose(cfp);
|
||||
|
||||
for (cache_ptr = buff; cache_ptr - buff < file_size; cache_ptr += len) {
|
||||
|
5
main.c
5
main.c
@ -18,6 +18,7 @@ int epollfd, server_sock, server_sock6, local_port, process;
|
||||
conn_t cts[MAX_CONNECTION];
|
||||
char local_host[CACHE_SIZE];
|
||||
|
||||
/*
|
||||
int create_connection(char *remote_host, int remote_port)
|
||||
{
|
||||
struct sockaddr_in server_addr;
|
||||
@ -39,6 +40,7 @@ int create_connection(char *remote_host, int remote_port)
|
||||
server_addr.sin_family = AF_INET;
|
||||
memmove(&server_addr.sin_addr.s_addr, server->h_addr, server->h_length);
|
||||
server_addr.sin_port = htons(remote_port);
|
||||
//server_addr.sin_addr.s_addr = inet_addr(remote_host);
|
||||
if (connect(sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
|
||||
perror("connect");
|
||||
close(sock);
|
||||
@ -48,6 +50,7 @@ int create_connection(char *remote_host, int remote_port)
|
||||
fcntl(sock, F_SETFL, O_NONBLOCK);
|
||||
return sock;
|
||||
}
|
||||
*/
|
||||
|
||||
int create_server_socket(int port)
|
||||
{
|
||||
@ -388,7 +391,7 @@ void initialize(conf * configure)
|
||||
copy_new_mem(configure->http_req, httpdns.http_req_len, &httpdns.http_req);
|
||||
|
||||
server_sock = create_server_socket(configure->tcp_listen); // IPV4
|
||||
server_sock6 = create_server_socket6(configure->tcp6_listen); // IPV6
|
||||
server_sock6 = create_server_socket6(configure->tcp_listen); // IPV6
|
||||
epollfd = epoll_create(MAX_CONNECTION);
|
||||
if (epollfd == -1) {
|
||||
perror("epoll_create");
|
||||
|
Loading…
Reference in New Issue
Block a user