How do I get the original IP address from the IP header of a datagram using Winsock?

I have a port that binds () 'd to INADDR_ANY. I am receiving datagrams successfully. Once received, I need to read the IP header to get the source IP.

+1


source to share


1 answer


I don't think you can get it if you use standard recv or read function calls. Calling recvfrom like this:

int recvfrom(
  __in         SOCKET s,
  __out        char *buf,
  __in         int len,
  __in         int flags,
  __out        struct sockaddr *from,
  __inout_opt  int *fromlen
);

      



includes a structure (second to the last field above) that will get the source address, which you can explore for whatever purposes you want.

+4


source







All Articles