Vy Tran
Vy Tran

Reputation: 35

How do sockets handle local address changes?

In C, I can bind a client socket to a specific local address and a system-selected port. What would happen if any of the following happened?

  1. The local address of the machine is changed
  2. The program is moved to a host with a different local address

And what would happen if I attempt to bind after calling connect()?

Upvotes: 2

Views: 520

Answers (1)

Well, in general, a TCP socket connection is really identified by the source IP, source port, destination ip, destination port tuple. If say the source IP is not valid any more then neither end can recover from it and the destination host will not probably notice until after a timeout.

If on the other hand you're trying to bind to an address that is not local at that time, the bind system call should return an error (EADDRNOTAVAIL).

Finally, rebinding a connected TCP socket should result in an error because it doesn't make any sense.

Upvotes: 2

Related Questions