3
  1. When receiving a packet on an unconnected UDP socket bound to 0.0.0.0/INADDR_ANY, how can I determine what the local IP it was sent to?
  2. Can I determine what interface it was received on?
  3. Can this be also be done for connection-oriented sockets such as TCP?

Update0

  1. Platform is Linux, so language is irrelevant but C is native.
  2. UDP sockets are bound to INADDR_ANY host, so getsockname() returns 0.0.0.0.
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526

2 Answers2

1

Hmmm, have a look at this. So looks like there is probably a socket option, at least in the Linux/Unix world. What OSes does it need to work on?

vulcan
  • 706
  • 5
  • 8
1

I've had to deal with the same issue on Windows platforms. My solution was to explicitly listen on all available interfaces as that way getsockname() works as expected.

Len Holgate
  • 21,282
  • 4
  • 45
  • 92