I'm writing a UPnP AV/DLNA DMS which needs to send and receive SSDP messages. In response to some M-SEARCH
packets I need to send a reply with the URL of a resource (in this case a HTTP server), which I've chosen to bind to INADDR_ANY
(0.0.0.0
). Of course this address is meaningless to the sender of the M-SEARCH
packet: The address of the interface on which the M-SEARCH
was received is most appropriate.
How can I determine the appropriate address to send in the reply packet?
Some ideas I've considered are:
- Binding a different receiver to each socket. When a receiver gets an
M-SEARCH
packet, the reply address can use the socket's local address in the reply. However this requires knowing and iterating over all the interfaces, and adding and removing receivers as interface availability changes. - Put a single receiver on
INADDR_ANY
, and iterate interface netmasks to determine the possible source. However more than one interface might share the same subnet. - Extract the packets IP target address upon receiving it. This would be IP specific, and may be lost somewhere in the network abstraction.