]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/bindresvport.3
fanotify_init.2, fanotify.7: Document FAN_REPORT_TID
[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.\"
4b8c67d9 30.TH BINDRESVPORT 3 2017-09-15 "" "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>
dd3568a1 37.PP
5cedb08f 38.BI "int bindresvport(int " sockfd ", struct sockaddr_in *" sin );
fea681da
MK
39.fi
40.SH DESCRIPTION
dd3568a1 41.PP
63aa9df0 42.BR bindresvport ()
3eec7952
MK
43is used to bind the socket referred to by the
44file descriptor
45.I sockfd
46to a privileged anonymous IP port,
5cedb08f
MK
47that is, a port number arbitrarily selected from the range 512 to 1023.
48.\" Glibc actually starts searching with a port # in the range 600 to 1023
847e0d88 49.PP
e6b5cd8f
MK
50If the
51.BR bind (2)
988db661 52performed by
e6b5cd8f 53.BR bindresvport ()
5cedb08f
MK
54is successful, and
55.I sin
56is not NULL, then
e6b5cd8f
MK
57.I sin\->sin_port
58returns the port number actually allocated.
847e0d88 59.PP
e6b5cd8f
MK
60.I sin
61can be NULL, in which case
62.I sin\->sin_family
63is implicitly taken to be
5cedb08f 64.BR AF_INET .
988db661 65However, in this case,
e6b5cd8f
MK
66.BR bindresvport ()
67has no way to return the port number actually allocated.
5cedb08f
MK
68(This information can later be obtained using
69.BR getsockname (2).)
e6b5cd8f
MK
70.SH RETURN VALUE
71.BR bindresvport ()
5cedb08f 72returns 0 on success; otherwise \-1 is returned and
1bf89c60 73.I errno
e6b5cd8f
MK
74set to indicate the cause of the error.
75.SH ERRORS
76.BR bindresvport ()
77can fail for any of the same reasons as
1fa3625a 78.BR bind (2).
5cedb08f
MK
79In addition, the following errors may occur:
80.TP
81.BR EACCES
ed1ba8a5
MK
82The calling process was not privileged
83(on Linux: the calling process did not have the
5cedb08f 84.B CAP_NET_BIND_SERVICE
ed1ba8a5 85capability in the user namespace governing its network namespace).
5cedb08f
MK
86.TP
87.B EADDRINUSE
88All privileged ports are in use.
e6b5cd8f 89.TP
2cbeeec3 90.BR EAFNOSUPPORT " (" EPFNOSUPPORT " in glibc 2.7 and earlier)"
e6b5cd8f
MK
91.I sin
92is not NULL and
5cedb08f 93.I sin->sin_family
988db661 94is not
e6b5cd8f 95.BR AF_INET .
9ed071a4 96.SH ATTRIBUTES
1ff0c445
MK
97For an explanation of the terms used in this section, see
98.BR attributes (7).
99.TS
100allbox;
101lb lb lb
102l l lw23.
103Interface Attribute Value
104T{
9ed071a4 105.BR bindresvport ()
1ff0c445
MK
106T} Thread safety T{
107glibc >= 2.17: MT-Safe
9ed071a4 108.\" commit f6da27e53695ad1cc0e2a9490358decbbfdff5e5
1ff0c445
MK
109.br
110glibc < 2.17: MT-Unsafe
111T}
112.TE
113.PP
114The
9ed071a4 115.BR bindresvport ()
1ff0c445
MK
116function uses a static variable that was not protected by a lock
117before glibc 2.17, rendering the function MT-Unsafe.
47297adb 118.SH CONFORMING TO
2a7e150e 119Not in POSIX.1.
5cedb08f
MK
120Present on the BSDs, Solaris, and many other systems.
121.SH NOTES
122Unlike some
123.BR bindresvport ()
124implementations,
125the glibc implementation ignores any value that the caller supplies in
126.IR sin\->sin_port .
e6b5cd8f 127.SH SEE ALSO
5cedb08f
MK
128.BR bind (2),
129.BR getsockname (2)