Getting the local address for connection on a multihomed machine.

Hi, I need to be find out the IP address which I will be using to talk to a given target address on a machine that can have multiple interfaces and multiple addresses on those interfaces. I need this because I have to state my own address in the payload I'm sending. (I don't need to work through NAT)

I have the IP helper functions GetBestInterface() and GetBestRoute() which will tell me the Interface that will be used to talk to a given host, but I can't find a way of getting which IP Address on that interface will be used. From what I can tell from the reference material, I cannot rely on there being only one IP address assigned to any one Interface.

I'm new to Windows, is it just a library function that I haven't found, or is it that I'm going about this in the wrong way? It seems like it should be a pretty common thing to want to do.

Any thoughts greatly appreciated.

-Graham Richards

[946 byte] By [GrahamRichards] at [2008-1-10]
# 1
GetAdaptersInfo returns a linked list of all adapters and information about them. If you know the adapter name or the interface index (via examination of routing table for example) then you can reference the associated IP address for that interface.
bjkl44 at 2007-10-3 > top of Msdn Tech,Windows Networking Development,Winsock Kernel (WSK)...