2

I have looked up in BSD code but got lost somewhere :(

the reason I want to check is this:

TCP RFC (http://www.ietf.org/rfc/rfc793.txt) sec 2.7 states:

"To provide for unique addresses within each TCP, we concatenate an internet address identifying the TCP with a port identifier to create a socket which will be unique throughout all networks connected together. A connection is fully specified by the pair of sockets at the ends."

Does this mean: socket = local (ip + port) ?

If yes, then the accept function of Unix returns a new socket descriptor. Will it mean that a new socket is created (in turn a new port is created) for responding to client requests?

PS: I am a novice in network programming.

[UPDATE] I understood what I read @ How does the socket API accept() function work?. My only doubt is: if socket = (local port +local ip), then a new socket would mean a new port for the same IP. going by this logic, accept returns a new socket (thus a new port is created). so all sending should occur through this new port. Is what I understand here correct?

1
  • 'socket = (local port + local IP)' is already wrong. Your conclusion is based on a false premiss. Commented Nov 8, 2014 at 22:09

1 Answer 1

8

You are mostly correct. When you accept(), a new socket is created and the listening socket stays open to allow more incoming connections but the new socket uses the same local port number as the listening socket.

A connection is defined by a 5-tuple: protocol, local-addr, local-port, remote-addr, remote-port.

Therefore, each accepted connection is unique even though they all share the same local port number because the remote ip/port is always different. The listening socket has no remote ip/port and so is also unique.

Sign up to request clarification or add additional context in comments.

3 Comments

if indeed a socket is ip+port, then shouldn't a new socket have to have a new port associated with it ? (sry couldn't upvote ur ans coz of low reputation score...am a newbie)
@user1801732 that's the same as your original question, and the answer to that question is this answer.
The accepted connection socket must have the same port number as the listening socket. If it changed, the client would have no way of knowing the new value and the initial TCP handshake would fail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.