How to set local IP address when sending TCP / IP connections?

Using Linux and glibc, when a TCP / IP connection occurs (call connect () on the socket), how can I explicitly choose which of the local IP addresses I want to create this connection if I have several interfaces (with different IP addresses ), where can I contact the remote host?

Is this possible, or does the IP stack of the operating system always automatically choose a route?

+3
source share
1 answer

Bind to a specific address instead of 0.0.0.0or ::.

+6
source

Source: https://habr.com/ru/post/1790211/


All Articles