How to get an IP address of the interface having its sockaddr_dl?

Hello,

I have registered a socket and I am getting UDP broadcast messages on it. I would like to know, on what interface (not an interface name, and not its MAC address, but rather its IP address) did I receive such a message.

I can get the struct sockaddr_dl with interface's low level characteristics (using setsockopt level IPPROTO_IP, sublevel IP_RECVIF).

Unfortunately I am not able to retrieve the IP address directly using setsockopt level IPPROTO_IP, sublevel IP_RECVDSTADDR, since it returns 255.255.255.255 - no wonder, since the packet did not contain any information about the interface's IP address).

Could you please help me?
Thanks,
Mike
 
Unless it's a DHCP Discover package you want to receive, I would obtain a list of all Interfaces with according Internet configuration and check which configuration has the network the sender's address was in.
 
Back
Top