]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/bindresvport.3
membarrier.2: Remove redundant mention of return value of MEMBARRIER_CMD_SHARED
[thirdparty/man-pages.git] / man3 / bindresvport.3
CommitLineData
c11b1abf 1.\" Copyright (C) 2007, Michael Kerrisk <mtk.manpages@gmail.com>
5cedb08f
MK
2.\" and Copyright (C) 2008, Linux Foundation, written by Michael Kerrisk
3.\" <mtk.manpages@gmail.com>
2297bf0e 4.\"
93015253 5.\" %%%LICENSE_START(VERBATIM)
5cedb08f
MK
6.\" Permission is granted to make and distribute verbatim copies of this
7.\" manual provided the copyright notice and this permission notice are
8.\" preserved on all copies.
f5fed0f6 9.\"
5cedb08f
MK
10.\" Permission is granted to copy and distribute modified versions of this
11.\" manual under the conditions for verbatim copying, provided that the
12.\" entire resulting derived work is distributed under the terms of a
13.\" permission notice identical to this one.
14.\"
15.\" Since the Linux kernel and libraries are constantly changing, this
16.\" manual page may be incorrect or out-of-date. The author(s) assume no
17.\" responsibility for errors or omissions, or for damages resulting from
18.\" the use of the information contained herein. The author(s) may not
19.\" have taken the same level of care in the production of this manual,
20.\" which is licensed free of charge, as they might when working
21.\" professionally.
22.\"
23.\" Formatted or processed versions of this manual, if unaccompanied by
24.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 25.\" %%%LICENSE_END
e6b5cd8f
MK
26.\"
27.\" 2007-05-31, mtk: Rewrite and substantial additional text.
5cedb08f 28.\" 2008-12-03, mtk: Rewrote some pieces and fixed some errors
e6b5cd8f 29.\"
fe0fefbf 30.TH BINDRESVPORT 3 2015-03-02 "" "Linux Programmer's Manual"
fea681da
MK
31.SH NAME
32bindresvport \- bind a socket to a privileged IP port
33.SH SYNOPSIS
34.nf
35.B #include <sys/types.h>
36.B #include <netinet/in.h>
37.LP
5cedb08f 38.BI "int bindresvport(int " sockfd ", struct sockaddr_in *" sin );
fea681da
MK
39.fi
40.SH DESCRIPTION
41.LP
63aa9df0 42.BR bindresvport ()
5cedb08f
MK
43is used to bind a socket descriptor to a privileged anonymous IP port,
44that is, a port number arbitrarily selected from the range 512 to 1023.
45.\" Glibc actually starts searching with a port # in the range 600 to 1023
e6b5cd8f 46
e6b5cd8f
MK
47If the
48.BR bind (2)
988db661 49performed by
e6b5cd8f 50.BR bindresvport ()
5cedb08f
MK
51is successful, and
52.I sin
53is not NULL, then
e6b5cd8f
MK
54.I sin\->sin_port
55returns the port number actually allocated.
56
57.I sin
58can be NULL, in which case
59.I sin\->sin_family
60is implicitly taken to be
5cedb08f 61.BR AF_INET .
988db661 62However, in this case,
e6b5cd8f
MK
63.BR bindresvport ()
64has no way to return the port number actually allocated.
5cedb08f
MK
65(This information can later be obtained using
66.BR getsockname (2).)
e6b5cd8f
MK
67.SH RETURN VALUE
68.BR bindresvport ()
5cedb08f 69returns 0 on success; otherwise \-1 is returned and
1bf89c60 70.I errno
e6b5cd8f
MK
71set to indicate the cause of the error.
72.SH ERRORS
73.BR bindresvport ()
74can fail for any of the same reasons as
1fa3625a 75.BR bind (2).
5cedb08f
MK
76In addition, the following errors may occur:
77.TP
78.BR EACCES
79The caller did not have superuser privilege (to be precise: the
80.B CAP_NET_BIND_SERVICE
81capability is required).
82.TP
83.B EADDRINUSE
84All privileged ports are in use.
e6b5cd8f 85.TP
2cbeeec3 86.BR EAFNOSUPPORT " (" EPFNOSUPPORT " in glibc 2.7 and earlier)"
e6b5cd8f
MK
87.I sin
88is not NULL and
5cedb08f 89.I sin->sin_family
988db661 90is not
e6b5cd8f 91.BR AF_INET .
9ed071a4 92.SH ATTRIBUTES
1ff0c445
MK
93For an explanation of the terms used in this section, see
94.BR attributes (7).
95.TS
96allbox;
97lb lb lb
98l l lw23.
99Interface Attribute Value
100T{
9ed071a4 101.BR bindresvport ()
1ff0c445
MK
102T} Thread safety T{
103glibc >= 2.17: MT-Safe
9ed071a4 104.\" commit f6da27e53695ad1cc0e2a9490358decbbfdff5e5
1ff0c445
MK
105.br
106glibc < 2.17: MT-Unsafe
107T}
108.TE
109.PP
110The
9ed071a4 111.BR bindresvport ()
1ff0c445
MK
112function uses a static variable that was not protected by a lock
113before glibc 2.17, rendering the function MT-Unsafe.
47297adb 114.SH CONFORMING TO
2a7e150e 115Not in POSIX.1.
5cedb08f
MK
116Present on the BSDs, Solaris, and many other systems.
117.SH NOTES
118Unlike some
119.BR bindresvport ()
120implementations,
121the glibc implementation ignores any value that the caller supplies in
122.IR sin\->sin_port .
e6b5cd8f 123.SH SEE ALSO
5cedb08f
MK
124.BR bind (2),
125.BR getsockname (2)