If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

How are ICMP replies associated with the request socket?

Maybe this is a silly question, but if I create a socket and send an ICMP echo request with sendto(), I can receive the echo reply with recvfrom(). How does the underlying network system know that the incoming reply is associated with my socket? In other words, why do I receive my echo reply with recvfrom() and not other echo replies to other programs that are also sending echo requests? Is there some kind of ID field in some protocol header somewhere that the system has associated with my socket?

Re: How are ICMP replies associated with the request socket?

Originally Posted by mnbv0987

Maybe this is a silly question, but if I create a socket and send an ICMP echo request with sendto(), I can receive the echo reply with recvfrom(). How does the underlying network system know that the incoming reply is associated with my socket?

The socket received your request know your address due to the fifth parameter of the recvfrom function:

from [out]
An optional pointer to a buffer in a sockaddr structure that will hold the source address upon return.

Re: How are ICMP replies associated with the request socket?

Originally Posted by VictorN

The socket received your request know your address due to the fifth parameter of the recvfrom function:

The fifth parameter returns the address that the message was received from. But how does the system know that the incoming ICMP reply is associated with my socket? In other words, if I call recvfrom(), I don't receive incoming data intended for other applications - how does the system associate that incoming reply with my socket descriptor? (The first parameter to recvfrom())?

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.