LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   What's a port ? (https://www.linuxquestions.org/questions/linux-general-1/whats-a-port-156549/)

wmcase 03-11-2004 10:00 PM

What's a port ?
 
Just another learning question.

I know basically what a physical port (socket, plugin) is? But for some reason everything I read goes all metaphorical and mystical after a certain point when explaining how ports for modem's and serial devices work.

Who or what is 'listening' for what at which port numbers and why?

Seriously, I don't expect an answer to the above question, but that represents how I feel after reading any one of the manuals. (eg. LDP, System Admin Guide, Network Admin Guides I and II, modem HOWTO, ISP HOWTO, serial devices HOWTO plus a couple not so good manuals I have).

Everything is easy to follow then all of a sudden it all turns anthropomorphic. Port numbers are given out (by who? -- what program?, the kernel??, to which program?? or driver? or module? Who decides on the specific number? and why? (I have the list of the usual assignments for IBM etc.) but what about the rest. In one manual a short number may be assigned to a port. In the next manual the number is five or six digits. Is there no restrictions?

Who is this mystical guy who 'listens' at the port? I assume some program has opened some electronic gates somewhere so that when the right bit combination flows through/by those bits activate something -- what? I assume that the same electronic gates or group of gates are used for different communication tasks but in different combinations and that the specific combinations are the port numbers our little guy is listening for. Is that true? But then why do the manuals keep warning about too many gates etc. ?

etc. etc. etc.

I have had no problem with FIFO device pipes, or devfs, I know enough about drivers to understand their function in principal, I think I could understand an explanation of how switches might be turned on or off, but for some reason when electricity comes in touch with metal every writer runs. Why?

So, anybody out there; what's a port?

Bill

DrOzz 03-11-2004 10:43 PM

i just scimmed through and went right to the point of your main question, so sorry if you asked anything within that paragraph, but i will just give you some general info ...

first and foremost ports range from 0 - 65534.
the ports 0 - 1023 are called well-known ports since
they represent commonly used services.
also by definition in the simplest terms i guess we can say :
port = the address on a host where an application makes itself
available to incoming data ...
port number = a unique number associated with a process running on a computer.
for example: 23 is the standard port number associated with the Telnet utility.

take a look at your /etc/services file to get a closer look of all kinds of ports and what
service runs on them ..
here is a list of well known TCP ports

Quote:

In TCP/IP and UDP networks, an endpoint to a logical connection. The port number identifies what type of port it is. For example, port 80 is used for HTTP traffic
above is a definition from webopedia.com

hw-tph 03-12-2004 05:09 AM

A port is pretty useless without a host to go with it, and the two together equals a socket.

The TCP/IP stack in the kernel handles sockets and ports, and a program can make a call to the kernel to ask for a listening socket of their own. This whole socket/port terminology is actually just a way of making things easy to understand and handle since what it comes down to is memory ranges.

A program, say an FTP server, establishes a listening port by asking the OS for the port it would like - TCP/21 is standard for the FTP command channel. If this is not already used, the OS (the TCP/IP stack in the kernel) will assign a memory range (if not already done) to "port 21" and monitor that space. When an incoming TCP targeted at port 21 arrives it is moved to the assigned memory area. This is what the port actually is - a memory area. Then the data is moved up through the stack to the application layer where it is handed to the FTP server program which had claimed TCP/21.

On Linux and other UNIX-like operating systems you will often see a master daemon of some sort that handles several different types of services and claims several listening sockets. This little daemon examines the data it is sent and invokes the proper application. inetd and xinetd are examples of this sort of master daemon.

Think of ports as mailboxes in a large house with several apartments - mail gets delivered daily to the house (in which everyone has the same address; the old address = host analogy) and then the janitor delivers the mail to the destination mailboxes so that Mrs Anderson gets her mailorder juicer that she had ordered.


Håkan

JZL240I-U 03-12-2004 07:59 AM

Thank you, Håkan for a simple, but good and easy to follow explanation (In particular I liked the mailbox analogy :)).

wmcase 03-12-2004 08:43 AM

To hw-tph

Thanks Hakan. That was exactly what I wanted to learn. Straight forward simple and non-anthropomorphic. I was beginning to worry about the little guys "listening" in my computer because I hadn't been feeding them.

I have saved a copy of your reply, printed it and put it on top of all my modem and Ethernet info.

Thanks again.

Genesee 03-12-2004 11:46 AM

well wmcase got me to learn a new word - figured I'd share:


Main Entry: an·thro·po·mor·phic
Pronunciation: "an(t)-thr&-p&-'mor-fik
Function: adjective
Etymology: Late Latin anthropomorphus of human form, from Greek anthrOpomorphos, from anthrOp- + -morphos -morphous

1 : described or thought of as having a human form or human attributes <anthropomorphic deities>
2 : ascribing human characteristics to nonhuman things <anthropomorphic supernaturalism>


:cool:

hw-tph 03-12-2004 01:32 PM

I am glad you found my input useful. :)

Genesee, thank you for clearing that up for me. I had no idea what it meant but it sure did sound educated. :)


Håkan

wmcase 03-12-2004 03:35 PM

Thank you Guys. You made my day.

It did sound educated, didn't it?

Well, it just shows what a 35 year old B.A. can do for you.

Bill

mikshaw 03-12-2004 07:35 PM

The B.A. is 35 years old? That would make you...~57?

itsjustme 03-12-2004 08:30 PM

Uh... I liked DrOzz's explanation too. :)

J.W. 03-13-2004 01:38 AM

Great thread, and a couple of excellent posts from hw-tph and DrOzz. However, while I understand how the well-known ports over time would have been standardized, what about the ones in the less-often-used upper ranges? In other words, suppose a given process wants to use, say, port 57324, and the memory is assigned, but then another process comes along and attempts to use that same port? How is contention for a single port resolved? What manages the assignment of the ports, or is it just a free-for-all, first-come-first-served type of deal?

To continue the analogy, what would the mailman in this apartment building do if he knew that Mrs. Anderson lived in #203, but he started getting hockey magazines addressed to Colonel Mustard also at #203. (Assume for purposes of this discussion that Mrs. Anderson and Colonel Mustard are not, uh, romantically involved.) -- J.W.

hw-tph 03-15-2004 03:25 AM

A port can only be used by one program or process at any given time - it basically is a first come, first served deal like you said. This is a pretty common issue - many Linux distrubutions come with an FTP server and when a new user tries to install the FTP server of her choice the install goes smoothly but the newly installed server won't start, often after giving a couple of more or less weird error messages. The same is also true when people try to upgrade to Apache2 but it cannot start since Apache(1) is listening on port 80 (the standard http port).

The mailman knows that one (and only one) person is the recipant for each mailbox in use. To him, the name of the person is irrelevant - #203 might be Mrs Anderson or Colonel Mustard, he only knows where to deliver the packages. If it's a Mrs Anderson or a Colonel Mustard picking up the package doesn't matter, it's none of his business. Even if the old lady in #203 doesn't want the NHL Enforcer's Weekly (current issue starring Eric Cairns of the Islanders with bloody fists on the cover) she will get it.

To get more technical - actually dealing with the incoming data is up to the application. If an FTP server gets an HTTP request (due to the FTP server listening to the wrong port, or the URL typed into the browser has an incorrect port) it will either respond with an error message or - more likely - just ignore it and not reply at all. This is application-specific.


Håkan


All times are GMT -5. The time now is 04:58 PM.