Getting the IP of the interface that received a recvfrom() UDP packet (Microsoft)
问题 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? 回答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