blob: 5bae2218dfc15f3ed9a5737e15a92edd2a55f6af [file] [log] [blame]
<html lang="en">
<head>
<title>Ports - The GNU C Library</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="The GNU C Library">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Internet-Namespace.html#Internet-Namespace" title="Internet Namespace">
<link rel="prev" href="Protocols-Database.html#Protocols-Database" title="Protocols Database">
<link rel="next" href="Services-Database.html#Services-Database" title="Services Database">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This file documents the GNU C library.
This is Edition 0.12, last updated 2007-10-27,
of `The GNU C Library Reference Manual', for version
2.8 (Sourcery G++ Lite 2011.03-41).
Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002,
2003, 2007, 2008, 2010 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software Needs Free Documentation''
and ``GNU Lesser General Public License'', the Front-Cover texts being
``A GNU Manual'', and with the Back-Cover Texts as in (a) below. A
copy of the license is included in the section entitled "GNU Free
Documentation License".
(a) The FSF's Back-Cover Text is: ``You have the freedom to
copy and modify this GNU manual. Buying copies from the FSF
supports it in developing GNU and promoting software freedom.''-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
<link rel="stylesheet" type="text/css" href="../cs.css">
</head>
<body>
<div class="node">
<a name="Ports"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Services-Database.html#Services-Database">Services Database</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Protocols-Database.html#Protocols-Database">Protocols Database</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Internet-Namespace.html#Internet-Namespace">Internet Namespace</a>
<hr>
</div>
<h4 class="subsection">16.6.3 Internet Ports</h4>
<p><a name="index-port-number-1732"></a>
A socket address in the Internet namespace consists of a machine's
Internet address plus a <dfn>port number</dfn> which distinguishes the
sockets on a given machine (for a given protocol). Port numbers range
from 0 to 65,535.
<p>Port numbers less than <code>IPPORT_RESERVED</code> are reserved for standard
servers, such as <code>finger</code> and <code>telnet</code>. There is a database
that keeps track of these, and you can use the <code>getservbyname</code>
function to map a service name onto a port number; see <a href="Services-Database.html#Services-Database">Services Database</a>.
<p>If you write a server that is not one of the standard ones defined in
the database, you must choose a port number for it. Use a number
greater than <code>IPPORT_USERRESERVED</code>; such numbers are reserved for
servers and won't ever be generated automatically by the system.
Avoiding conflicts with servers being run by other users is up to you.
<p>When you use a socket without specifying its address, the system
generates a port number for it. This number is between
<code>IPPORT_RESERVED</code> and <code>IPPORT_USERRESERVED</code>.
<p>On the Internet, it is actually legitimate to have two different
sockets with the same port number, as long as they never both try to
communicate with the same socket address (host address plus port
number). You shouldn't duplicate a port number except in special
circumstances where a higher-level protocol requires it. Normally,
the system won't let you do it; <code>bind</code> normally insists on
distinct port numbers. To reuse a port number, you must set the
socket option <code>SO_REUSEADDR</code>. See <a href="Socket_002dLevel-Options.html#Socket_002dLevel-Options">Socket-Level Options</a>.
<p><a name="index-netinet_002fin_002eh-1733"></a>These macros are defined in the header file <samp><span class="file">netinet/in.h</span></samp>.
<!-- netinet/in.h -->
<!-- BSD -->
<div class="defun">
&mdash; Macro: int <b>IPPORT_RESERVED</b><var><a name="index-IPPORT_005fRESERVED-1734"></a></var><br>
<blockquote><p>Port numbers less than <code>IPPORT_RESERVED</code> are reserved for
superuser use.
</p></blockquote></div>
<!-- netinet/in.h -->
<!-- BSD -->
<div class="defun">
&mdash; Macro: int <b>IPPORT_USERRESERVED</b><var><a name="index-IPPORT_005fUSERRESERVED-1735"></a></var><br>
<blockquote><p>Port numbers greater than or equal to <code>IPPORT_USERRESERVED</code> are
reserved for explicit use; they will never be allocated automatically.
</p></blockquote></div>
</body></html>