UDP socket fail to receive ECONNREFUSED

烈酒焚心 提交于 2019-12-11 07:32:01

问题


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.


回答1:


There could be two reasons for this.

  • The target machine does not (for some reason) send the ICMP back
  • The target machines does send the ICMP back but winsock 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.




回答2:


INFO: Winsock Ignores ICMP Port Unreachable Control Messages

You have to enable the SIO_UDP_CONNRESET control via WSAIoctl() in order for UDP sockets to react to ICMP failures:

WinSock Recvfrom() now returns WSAECONNRESET instead of blocking or timing out



来源:https://stackoverflow.com/questions/5762570/udp-socket-fail-to-receive-econnrefused

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!