How to set local IP when originating TCP/IP connections?
Using Linux and glibc, wh开发者_StackOverflow中文版en originating a TCP/IP connection (calling connect() on a socket), how can I choose explicitly from which of my IP local adresses I want to originate that connection, providing I have more than one interface (with different IPs) from where I can reach the remote host?
Is it possible to do so, or it is always up to the operating system IP stack to chose the route automatically?
Bind to a specific address instead of 0.0.0.0
or ::
.
精彩评论