Warm tip: This article is reproduced from serverfault.com, please click

how does a data packet know which process it belongs to?

发布于 2020-11-29 06:24:15

say i am using tcp protocol and i receive a data packet.my doubt is how will this packet be directed to its appropriate proccess.i have heard tcp uses port number so the process which is using current port number is given the data packet.but what if more than one process is using the same port number.i heard this is not possible i.e different process using same port number but what if i am using youtube from different windows of chrome and edge .all has to go to the same ip and same port number how will the incoming packet distinguish which process it goes to.

Questioner
moon shines
Viewed
0
Ron Maupin 2020-11-29 14:50:42

say i am using tcp protocol and i receive a data packet.my doubt is how will this packet be directed to its appropriate proccess.

Packets are directed to the correct process by the Protocol (IPv4) or Next Header (IPv6) field. For example, TCP is protocol 6, so the packet payload of a packet with 6 as the protocol number would be sent to the TCP process. If the protocol number is 17, then the payload of the packet is sent to the UDP process, etc. IANA maintains the Protocol Numbers page.

i have heard tcp uses port number so the process which is using current port number is given the data packet.

I think you are confusing the network layers. Packets are IP datagrams. TCP datagrams are segments because TCP segments a data stream. An application will register with TCP to get a port number, and that application has exclusive use of the port number until it releases it.

but what if more than one process is using the same port number.i heard this is not possible i.e different process using same port number but what if i am using youtube from different windows of chrome and edge .all has to go to the same ip and same port number how will the incoming packet distinguish which process it goes to.

A TCP port number is assigned to a single process. Your example would be incorrect because a browser will use ephemeral port numbers, where it lets TCP assign a random port number from the ephemeral range for the OS on which it is running. In fact, browsers will open multiple connections to the web server, each using a different source port number. It is the server side that must listen on a well-known port number.

Remember that port numbers are per protocol; TCP port 12345 is not UDP port 12345. Also, not all transport protocols use port numbers. Some use something else, and some use nothing because they are tied to a single application.