Protocols, Ports, and Sockets

15.1.3.1 Protocols, Ports, and Sockets

A protocol number is a single byte in the IP datagram header the third word — the protocol field. The value in the field identifies the protocol in the layer above IP, the transport layer, to which the data should be passed. UNIX specifies protocol numbers in the etcprotocols file. After IP passes incoming data to the corresponding transport protocol, the transport protocol passes the data to the correct application process. Port numbers identify application processes, which are also called network services. A port number is a 16−bit number in the header of the UDP packet message or TCP segment. The destination port number in the destination port field identifies the application protocol that is to receive the data; the source port number in the source port field identifies the application protocol that sent the data. UNIX specifies port numbers in the etcservices file. Well−known ports are standardized port numbers that enable remote hosts to know which port to connect to for a particular network service. This simplifies the connection process because both the sender and the recipient know in advance how and where to establish connection. For example, all systems that offer telnet offer it on port 23. The data flow through the TCPIP protocol stack in this case is presented in Figure 15.2. 346 Figure 15.2: Protocol and port numbers. However, the question is what to do when multiple users and multiple processes request the same service simultaneously. This situation can be handled only by using dynamically allocated ports, as seen in Figure 15.3. 347 Figure 15.3: Dynamically allocated port numbers. The source host has requested the telnet service from the designated host. The source host randomly generated the source port number for the user who initiated this request port 3408 in this case and sent out the TCP segment with this source port number; the destination port number is 23 the well−known service for telnet. The destination host has received the sent TCP segment on its port 23 and responded back to the remote hosts destination port 3408. A network−wide unique connection has been established. A combination of an IP address and a port number is called a socket. A socket uniquely identifies a single network process throughout the entire Internet. Sometimes the terms socket and port number are used interchangeably; well−known services are often referred as well−known sockets. However, this is not correct and should be avoided.

15.1.3.2 UNIX Database Files