I have a Visual Studio 2008 C++ application where I connect to a remote TCP server using a socket. The code looks basically like this:
SOCKET s = socket( AF_INET, SOCK_STREAM, 0 );
addrinfo* ai = getaddrinfo( ... );
connect( s, ai->ai_addr, sizeof( sockaddr_in ) );
Assuming my local client has multiple adapters, how can I tell which local interface was used to make the connection?
I realize I can use bind() to pick the adapter used, I’m curious about the case where I just let the system choose.
You can use
getsocknameto find out the address.