UDP 套接字无法接收 ECONNREFUSED
我使用以下命令创建了一个套接字:socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)。
根据 this,如果我多次发送简单数据包(乘以 send() 和/或 sendto( )),我可能会收到 ECONNREFUSED。 ICMP 应告知先前的数据包未到达,并且应出现 ECONNREFUSED。但它失败了, errno 不报告任何错误,并且 send() 始终返回发送的字节数。
UDP 协议实际上不应该告诉数据包已发送。但据我了解ICMP可以给出建议。
那么,问题是——为什么它无法接收ECONNREFUSED?
一切都是使用 Winsock 完成的。
I created a socket using: socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP).
According to this, if I send simple packet several times (multiply send() and/or sendto()), I can get ECONNREFUSED. ICMP should tell that previous packet didn't arrive and ECONNREFUSED should appear. But it fails, errno doesn't report about any errors, and send() always returns number of bytes sent.
UDP protocol actually shouldn't tell that packet was sent. But ICMP can give advice as I understand.
So, the question is - why does it fail to receive ECONNREFUSED?
Everything is done using Winsock.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能有两个原因。
ICMP
ICMP
但winsock 不能正确解释它(我知道某些较旧的 Unix 会这样做)
简而言之,找出答案的最佳选择是使用嗅探器。尝试使用wireshark 并查看是否收到ICMP 返回。
There could be two reasons for this.
ICMP
backICMP
back butwinsock
doesn't correctly interpret it (I know that certain older Unixes did this)In short, your best bet to find out would be using a sniffer. Try wireshark and see if you get an ICMP back.
信息:Winsock 忽略 ICMP 端口无法访问控制消息
您必须启用
SIO_UDP_CONNRESET
通过WSAIoctl()
进行控制,以便 UDP 套接字对 ICMP 失败做出反应:WinSock Recvfrom() 现在返回 WSAECONNRESET,而不是阻塞或超时
INFO: Winsock Ignores ICMP Port Unreachable Control Messages
You have to enable the
SIO_UDP_CONNRESET
control viaWSAIoctl()
in order for UDP sockets to react to ICMP failures:WinSock Recvfrom() now returns WSAECONNRESET instead of blocking or timing out