views:

310

answers:

2

I have a port that is bind()'d to INADDR_ANY. I am receiving datagrams successfully. After receipt, I need to read the IP header to get the source IP address.

+3  A: 

I don't believe you can get it if you're using the standard recv or read function calls. The recvfrom call as follows:

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 (the second to last field above) which will receive the source address which you can examine for whatever purposes you desire.

paxdiablo
A: 

won't work it is filter to receive a message not the address of coming packet

Onur Turhan