CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2013
    Posts
    2

    Question 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?

    Thanks,
    M

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

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

    Quote Originally Posted by mnbv0987 View Post
    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.
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2013
    Posts
    2

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

    Quote Originally Posted by VictorN View Post
    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())?

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

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

    System can create one and only one socket with the given (address family + host address + port number), and this socket is associated with the unique descriptor your application gets after calling either socket + bind functions or after calling accept (or similar ones)
    See also
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured