*BSD News Article 98151


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!uunet!in1.uu.net!207.167.14.9!scanner.worldgate.com!not-for-mail
From: Marc Slemko <marcs@znep.com>
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Listening at a socket
Date: 19 Jun 1997 17:05:28 GMT
Organization: WorldGate Inc.  http://www.worldgate.com/
Lines: 24
Message-ID: <5oboso$m32$1@scanner.worldgate.com>
References: <5oblqi$4re@ui-gate.utell.co.uk>
NNTP-Posting-Host: valis.worldgate.com
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:43250

In <5oblqi$4re@ui-gate.utell.co.uk> brian@shift.utell.net (Brian Somers) writes:

>This *has* to be a dumb question, but can anyone tell me
>how an OS, once it's received a packet for a given port
>X, can distinguish which process of all the processes that
>are using that port should get that packet.

>For example, if I run an ftp server, I have my ftpd
>listening on *.21.  If I currently have 2 established
>connections from the same remote machine, I'll have two
>additional ftpd processes running (forked from the first).
>When a packet is received from the other machine destined
>for port 21, how does the OS decide which process to deliver
>the packet to ?

The origin port.  One view of a socket is a combination of four bits
of information; the local port, the remote port, the local IP, and 
the remote IP.  The combination of those uniquely identifies
the connection.

If you want an answer in terms of exactly what code the BSD stack
uses to do it, the source is the best place to find it... around
findpcb in netinet/tcp_input.c for TCP.