开发者

Windows firewall blocking ICMP port unreachable?

I'm attempting to determine whether or not a remote host is listening on a particular UDP port number. I do this (in C#) as follows:

 Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
  int sent = socket.SendTo(bufsend, bufsend.Length, SocketFlags.None, endpoint);
  int recv = socket.ReceiveFrom(bufrecv, ref endp开发者_JS百科oint);

If no one is listening, I get an ICMP "port unreachable" which is reported on the receive as a socket exception with ErrorCode WSAECONNRESET (10054). All that makes sense, BUT it only happens when the Windows firewall is disabled. If the firewall is enabled -- even if I make an exception for the program -- I get ErrorCode WSAETIMEDOUT (10060), presumably because the firewall has eaten the ICMP "port unreachable".

Any suggestions? I've examined the firewall "advanced security" settings, but to no avail.

Thanks...


See the comment above. You must apply the rule opening the firewall to "destination unreachable" messages to ALL programs, not just to the executable that implements the SendTo / ReceiveFrom test.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜