开发者

how TCP port bind

开发者 https://www.devze.com 2023-01-08 15:05 出处:网络
Any body knows how is the port number bound with a socket in detail and how is the port used to forward the packet received in tr开发者_如何学Cansport layer to a socket which is reading on this port?

Any body knows how is the port number bound with a socket in detail and how is the port used to forward the packet received in tr开发者_如何学Cansport layer to a socket which is reading on this port?

thanks.


The application binds to a local IP address and port using the bind() function. The remote IP address and port is determined by the other end of the connection at the time a connection is established.

In the kernel, at the time a tcp connection is established the socket is put into a hash table based on data including the local address, local port, remote address, and remote port. When an incoming tcp segment arrives, these values are extracted from the header and used to look up the corresponding socket in the hash table. In Linux this lookup occurs in the function inet_lookup_established(). A similar function, inet_lookup_listener() is used to look up a listening socket from a different hash table for a new connection; in that case the remote IP address and port are not used.

0

精彩评论

暂无评论...
验证码 换一张
取 消