]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/bindresvport.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[thirdparty/man-pages.git] / man3 / bindresvport.3
1 .\" Copyright (C) 2007, Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" and Copyright (C) 2008, Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
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.
9 .\"
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.
25 .\" %%%LICENSE_END
26 .\"
27 .\" 2007-05-31, mtk: Rewrite and substantial additional text.
28 .\" 2008-12-03, mtk: Rewrote some pieces and fixed some errors
29 .\"
30 .TH BINDRESVPORT 3 2017-09-15 "" "Linux Programmer's Manual"
31 .SH NAME
32 bindresvport \- 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 .PP
38 .BI "int bindresvport(int " sockfd ", struct sockaddr_in *" sin );
39 .fi
40 .SH DESCRIPTION
41 .PP
42 .BR bindresvport ()
43 is used to bind the socket referred to by the
44 file descriptor
45 .I sockfd
46 to a privileged anonymous IP port,
47 that 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
49 .PP
50 If the
51 .BR bind (2)
52 performed by
53 .BR bindresvport ()
54 is successful, and
55 .I sin
56 is not NULL, then
57 .I sin\->sin_port
58 returns the port number actually allocated.
59 .PP
60 .I sin
61 can be NULL, in which case
62 .I sin\->sin_family
63 is implicitly taken to be
64 .BR AF_INET .
65 However, in this case,
66 .BR bindresvport ()
67 has no way to return the port number actually allocated.
68 (This information can later be obtained using
69 .BR getsockname (2).)
70 .SH RETURN VALUE
71 .BR bindresvport ()
72 returns 0 on success; otherwise \-1 is returned and
73 .I errno
74 set to indicate the cause of the error.
75 .SH ERRORS
76 .BR bindresvport ()
77 can fail for any of the same reasons as
78 .BR bind (2).
79 In addition, the following errors may occur:
80 .TP
81 .BR EACCES
82 The calling process was not privileged
83 (on Linux: the calling process did not have the
84 .B CAP_NET_BIND_SERVICE
85 capability in the user namespace governing its network namespace).
86 .TP
87 .B EADDRINUSE
88 All privileged ports are in use.
89 .TP
90 .BR EAFNOSUPPORT " (" EPFNOSUPPORT " in glibc 2.7 and earlier)"
91 .I sin
92 is not NULL and
93 .I sin->sin_family
94 is not
95 .BR AF_INET .
96 .SH ATTRIBUTES
97 For an explanation of the terms used in this section, see
98 .BR attributes (7).
99 .TS
100 allbox;
101 lb lb lb
102 l l lw23.
103 Interface Attribute Value
104 T{
105 .BR bindresvport ()
106 T} Thread safety T{
107 glibc >= 2.17: MT-Safe
108 .\" commit f6da27e53695ad1cc0e2a9490358decbbfdff5e5
109 .br
110 glibc < 2.17: MT-Unsafe
111 T}
112 .TE
113 .PP
114 The
115 .BR bindresvport ()
116 function uses a static variable that was not protected by a lock
117 before glibc 2.17, rendering the function MT-Unsafe.
118 .SH CONFORMING TO
119 Not in POSIX.1.
120 Present on the BSDs, Solaris, and many other systems.
121 .SH NOTES
122 Unlike some
123 .BR bindresvport ()
124 implementations,
125 the glibc implementation ignores any value that the caller supplies in
126 .IR sin\->sin_port .
127 .SH SEE ALSO
128 .BR bind (2),
129 .BR getsockname (2)