using INADDR_ANY with UDP
I have a question about the interpretation of INADDR_ANY in conjunction with UDP. I have seen various questions and explanations about INADDR_ANY but none seem to quite match my exact circumstances, so I'm hoping someone can give me a clear explanation that applies to my particular applications. My understanding is that INADDR_ANY has different semantics depending upon whether you are a server or client, but since this is UDP and there is not any ongoing connection I'm not sure how that model applies to me.
We have various UDP talker processes on different machines on the network which write UDP datagrams containing data of interest, sometimes addressed to a particular host (e.g., xxx.xxx.xxx.someHostNumber) and sometimes addressed to the broadcast address (e.g., xxx.xxx.xxx.255). My listener process wants to receive these datagrams, possibly from multiple sources, on a machine with multiple Ethernet interfaces. If my listener does a bind() on some specific port number P using a sockaddr that has been set to INADDR_ANY, exactly what is that supposed to do? More particularly, if that socket then does a series of read()s, does it (1) read all packets addressed to port P on any of the interfaces, (2) read only packets addressed to port P on the default interface 0, (3) read the first packet addressed to port P on any of the interfaces and thereafter read only packets from the first interface where it saw a packet addressed to P, or perhaps something else entirely?
Thanks!
Roger Davis
|