0

Using recvfrom() on a socket bound to INADDR_ANY on a Microsoft multihomed PC. when recvfrom() gets an UDP packet: how can I find the Interface (IP) that received the packet?

pnuts
  • 58,317
  • 11
  • 87
  • 139
  • Microsoft PC? That's a pretty wide range of possibilities, I'm assuming Windows - but still, what version? Win 3.11 and Win 7 are *slightly* different. Also, what have you tried? What results did you expect? What did you get instead? – Piskvor left the building Oct 27 '11 at 13:46
  • --for some reason I cannot edit the original post-- using recvfrom() from win2000 (I cannot use WSARecvMsg()) to Win7 so far I couldn't find anything to do this – user664239 Oct 27 '11 at 14:18

1 Answers1

1

There is no way to know the receiving IP when a single listening socket is bound to multiple IPs. Instead of binding a single socket to INADDR_ANY, you can query the machine's list of local IPs using GetAdaptersInfo() and/or GetAdapterAddresses(), then create a separate listening socket for each IP. You can use getsockname() to know which IP a given socket is bound to, but only when that socket is bound to a specific IP, not multiple IPs.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770