- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有开源 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 命令时,我看到了这个
Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name 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
最佳答案
类似的修改(在 recvfrom()
之后添加 printf)对我来说效果很好。除了打印之外,您是否对程序进行了任何其他更改?
以下是我测试它所采取的步骤:
printf()
会在桌面上生成大量输出,而桌面上正在运行 www 浏览器或电子邮件客户端等其他应用程序,因此请小心。也许您可以使用其余源代码使用的日志记录约定,例如
if (LOG == 1) { fprintf(LOG_FILE, "Using DNS server: %s\n", inet_ntoa(*(struct in_addr *)&remote_dns)); }
顺便说一句2。如果您手动创建或编辑了/etc/resolv.conf,请记住在运行 dns_proxy 之前对其进行备份。使用 tailf "your_dns_proxy_logfile.log"查看发生了什么。
顺便说一句3。该程序不是很健壮。它泄漏了 fds,string_value()
中存在一个离一的情况,udp_listener()
执行 malloc()
和 memcpy()
而不检查 recvfrom()
的返回值。在我的机器上它出现很多段错误。不过,似乎几乎无法发挥作用。
编辑以下是我对原始版本所做的一些更改。 https://github.com/thuovila/dns-tcp-socks-proxy/经过这些修改后,每个中断的 recvfrom()
都不会出现段错误。更改已合并到上游存储库。
关于c - recvfrom() 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18623532/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!