2

If we create a listening socket it will return us a descriptor (let say root descriptor) and we are binding this descriptor to a address. Whenever a new client connection is available the root descriptor informs us and we accept that new connection and receive a unique descriptor (let say client descriptor) for each client. From now on wards we can communicate with that client using that descriptor. Client information is stored in the separate inode which is pointed out by the client descriptor. Due to this Linux was able to deliver respective client data to a respective descriptor.

If the above I mentioned is correct (kindly correct me if my understanding is wrong) then I got a doubt. What is the client information stored in the inode? How is the client uniquely identified by Linux?

8
  • 3
    IP address and remote port. Commented Mar 11, 2020 at 10:54
  • @Ned64 tnx for the response. I can understand the IP address but what is remote port. the process on the remote that going to connect does not necessary to listen on the port right? am I missing anything Commented Mar 11, 2020 at 11:00
  • 3
    en.wikipedia.org/wiki/Port_(computer_networking) Please read up on TCP Ports (and UDP Ports). On your computer please run, as root, netstat -tulpan to see current connections while having a web browser open to see examples. Commented Mar 11, 2020 at 11:02
  • 1
    Firefox and others have more than one connection open and distinguish by local and remote address+port. Commented Mar 11, 2020 at 11:03
  • 1
    Yes, but there can be 64k UDP and 64k TCP connections (for each own/local IP address). That is enough in most cases because they do not need to stay open for long. Commented Mar 11, 2020 at 11:30

2 Answers 2

2

The TCP/IP and UDP/IP protocols know a "session" which is defined by local and remote IP address and port [1]. A TCP/IP package, for example, will contain source and target IP address and port [2]. A server or client (say, Firefox) which has more than one connection open will distinguish at the OSI [3] session layer by address and port.

Please open a shell and run as root, while using a web browser

netstat -tulpan

to see current and active connections [4].

Example output:

# netstat -tulpan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1966/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1902/cupsd          
tcp        0      0 192.168.1.16:57374      172.217.23.165:443      ESTABLISHED 4730/firefox-bin     
tcp        0      0 192.168.1.16:55478      104.26.11.30:443        ESTABLISHED 4730/firefox-bin     
udp        0      0 127.0.0.1:53            0.0.0.0:*                           1996/named          

The lines show "ESTABLISHED" connections by firefox with differing local ports so that firefox will recognise which packet is the answer to which request.

Other lines with the LISTEN state are local programs running as a server process, including sshd (Secure Shell Server), cupsd (printer daemon) and named (Bind name server). These will accept incoming connections.

References to learn more:

[1] https://en.wikipedia.org/wiki/Port_(computer_networking)

[2] https://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure as well as https://en.wikipedia.org/wiki/IPv4_header#Header

[3] https://en.wikipedia.org/wiki/OSI_model

[4] https://en.wikipedia.org/wiki/Netstat

0

When you do a listen you specify a port, as the port has to be well known. This end has an IP (or more than one) and a port.

When you do a connect you specify the IP and port of the remote listener. The local IP is determined by the OS, and a port is assigned (it could be any number).

The connection can be identified by ( (remote IP, remote port), (local IP, local port) ) This puts an upper limit of 64K connections to each remote port, from any one IP address.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.