3

I have a system with 6 interfaces (and 6 IP addresses). I want to set up a TCP client connection (C++) to a server. Is there a way to use a certain interface as a source address (without using RAW sockets)?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
wbadenhop
  • 31
  • 2
  • 5
    You can `bind` a socket to a specific interface. Use port `0` to get a random port (see e.g. [this old answer](http://stackoverflow.com/a/1077305/440558)). – Some programmer dude Jun 14 '16 at 08:06
  • I thought bind was only used when setting up a server connection? – wbadenhop Jun 14 '16 at 12:43
  • Indeed, bind does it. A code snippet: Socket s = new Socket; s.bind (new (InetSocketAddress (localAddress,localPort)); s.connect (new (InetSocketAddress (localAddress,localPort)); – wbadenhop Jun 15 '16 at 11:48

0 Answers0