开发者

how do I get the IP of incoming ICMP due to UDP-send to dead client in Ruby?

so.. I'm doing a small multiplayer game with blocking UDP and IO.select. To my problem.. (In the server) reading from a UDP socket (packet, sender = @socket.recvfrom(1000)) which have just sent a packet to a dead client results in a ICMP unreachable (and exception Errno::ECONNRESET in ruby). 开发者_如何转开发The problem is that I can't find any way whatsoever to extract the IP of that ICMP.. so I can clean out that dead client.

Anyone know how to achieve this?

thanks


You'll need to call recvmsg for the socket, and pass MSG_ERRQUEUE as the flag.

The original destination address of the datagram that caused the error is supplied via msg_name.


It's worth noting that the source IP address of the ICMP packet will not always be the same address as your client. Any router that handles packets for this connection could be the source, and the payload of the ICMP packet would contain the IP header + the first 8 bytes of the packet it relates to.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜