我有开源 cod(这是它的链接) 在这部分 cod 中访问https://github.com/jtRIPper/dns-tcp-socks-proxy/blob/master/dns_proxy.c
while(1)
{
// receive a dns request from the client
printf("wait for a dns request from the client\n");
len = recvfrom(sock, buffer->buffer, 2048, 0, (struct sockaddr *)&dns_client, &dns_client_size);
printf("dns request received\n");
// fork so we can keep receiving requests
if (fork() != 0) { continue; }
// the tcp query requires the length to precede the packet, so we put the length there
query = malloc(len + 3);
query[0] = 0;
query[1] = len;
memcpy(query + 2, buffer->buffer, len);
// forward the packet to the tcp dns server
fprintf(LOG_FILE, "tcp query call\n");
tcp_query(query, buffer, len + 2);
// send the reply back to the client (minus the length at the beginning)
sendto(sock, buffer->buffer + 2, buffer->length - 2, 0, (struct sockaddr *)&dns_client, sizeof(dns_client));
free(buffer->buffer);
free(buffer);
free(query);
exit(0);
,recvfrom() 函数不起作用,我无法继续并显示“收到的 dns 请求\n”是什么问题?然后当我使用 netstat -upan inn 命令时我看到了这个
活动 Internet 连接(服务器和已建立) Proto Recv-Q Send-Q 本地地址 外部地址 状态 PID/程序名称 udp 0 0 127.0.0.1:951 0.0.0.0:* 1623/rpc.statd
udp 0 0 0.0.0.0:54721 0.0.0.0:* 2214/avahi-daemon: udp 0 0 0.0.0.0:45085 0.0.0.0:* 1623/rpc.statd
udp 0 0 127.0.0.1:53 0.0.0.0:* 4084/dns_proxy
udp 0 0 0.0。 0.0:68 0.0.0.0:* 1628/dhclient
udp 0 0 0.0.0.0:111 0.0.0.0:* 1582/rpcbind
udp 0 0 0.0.0.0:631 0.0.0.0:* 2323/cupsd
udp 0 0 0.0.0.0:5353 0.0.0.0:* 2214/avahi-daemon: udp 0 0 0.0.0.0:42756 0.0.0.0:* 1628/ dhclient
udp 0 0 0.0.0.0:1900 0.0.0.0:* 3306/minissdpd
udp 0 0 0.0.0.0:908 0.0.0.0:* 1582/rpcbind
udp6 0 0 :::111 :::* 1582/rpcbind
udp6 0 0 :::34443 :::* 1623/rpc.statd
udp6 0 0 :::5353 :::* 2214/avahi-daemon: udp6 0 0 :::62844 :::* 1628/dhclient
udp6 0 0 :::54654 :::* 2214/avahi-daemon: udp6 0 0 :::908 :::* 1582/rpcbind