man-pages/man3/bindresvport.3.html
2021-03-31 01:06:50 +01:00

196 lines
4.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of BINDRESVPORT</TITLE>
</HEAD><BODY>
<H1>BINDRESVPORT</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
bindresvport - bind a socket to a privileged IP port
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>&gt;</B>
<B>#include &lt;<A HREF="file:///usr/include/netinet/in.h">netinet/in.h</A>&gt;</B>
<B>int bindresvport(int </B><I>sockfd</I><B>, struct sockaddr_in *</B><I>sin</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<P>
<B>bindresvport</B>()
is used to bind the socket referred to by the
file descriptor
<I>sockfd</I>
to a privileged anonymous IP port,
that is, a port number arbitrarily selected from the range 512 to 1023.
<P>
If the
<B><A HREF="/cgi-bin/man/man2html?2+bind">bind</A></B>(2)
performed by
<B>bindresvport</B>()
is successful, and
<I>sin</I>
is not NULL, then
<I>sin-&gt;sin_port</I>
returns the port number actually allocated.
<P>
<I>sin</I>
can be NULL, in which case
<I>sin-&gt;sin_family</I>
is implicitly taken to be
<B>AF_INET</B>.
However, in this case,
<B>bindresvport</B>()
has no way to return the port number actually allocated.
(This information can later be obtained using
<B><A HREF="/cgi-bin/man/man2html?2+getsockname">getsockname</A></B>(2).)
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
<B>bindresvport</B>()
returns 0 on success; otherwise -1 is returned and
<I>errno</I>
set to indicate the cause of the error.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<B>bindresvport</B>()
can fail for any of the same reasons as
<B><A HREF="/cgi-bin/man/man2html?2+bind">bind</A></B>(2).
In addition, the following errors may occur:
<DL COMPACT>
<DT id="1"><B>EACCES</B>
<DD>
The calling process was not privileged
(on Linux: the calling process did not have the
<B>CAP_NET_BIND_SERVICE</B>
capability in the user namespace governing its network namespace).
<DT id="2"><B>EADDRINUSE</B>
<DD>
All privileged ports are in use.
<DT id="3"><B>EAFNOSUPPORT</B> (<B>EPFNOSUPPORT</B> in glibc 2.7 and earlier)
<DD>
<I>sin</I>
is not NULL and
<I>sin-&gt;sin_family</I>
is not
<B>AF_INET</B>.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>bindresvport</B>()
</TD><TD>Thread safety</TD><TD>
glibc &gt;= 2.17: MT-Safe
<BR>
glibc &lt; 2.17: MT-Unsafe
<BR></TD></TR>
</TABLE>
<P>
The
<B>bindresvport</B>()
function uses a static variable that was not protected by a lock
before glibc 2.17, rendering the function MT-Unsafe.
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
Not in POSIX.1.
Present on the BSDs, Solaris, and many other systems.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
Unlike some
<B>bindresvport</B>()
implementations,
the glibc implementation ignores any value that the caller supplies in
<I>sin-&gt;sin_port</I>.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+bind">bind</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+getsockname">getsockname</A></B>(2)
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="4"><A HREF="#lbAB">NAME</A><DD>
<DT id="5"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="6"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="7"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="8"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="9"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="10"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="11"><A HREF="#lbAI">NOTES</A><DD>
<DT id="12"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="13"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:36 GMT, March 31, 2021
</BODY>
</HTML>