]>
Commit | Line | Data |
---|---|---|
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 |
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> | |
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 |
43 | is used to bind the socket referred to by the |
44 | file descriptor | |
45 | .I sockfd | |
46 | to a privileged anonymous IP port, | |
5cedb08f MK |
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 | |
847e0d88 | 49 | .PP |
e6b5cd8f MK |
50 | If the |
51 | .BR bind (2) | |
988db661 | 52 | performed by |
e6b5cd8f | 53 | .BR bindresvport () |
5cedb08f MK |
54 | is successful, and |
55 | .I sin | |
56 | is not NULL, then | |
e6b5cd8f MK |
57 | .I sin\->sin_port |
58 | returns the port number actually allocated. | |
847e0d88 | 59 | .PP |
e6b5cd8f MK |
60 | .I sin |
61 | can be NULL, in which case | |
62 | .I sin\->sin_family | |
63 | is implicitly taken to be | |
5cedb08f | 64 | .BR AF_INET . |
988db661 | 65 | However, in this case, |
e6b5cd8f MK |
66 | .BR bindresvport () |
67 | has 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 | 72 | returns 0 on success; otherwise \-1 is returned and |
1bf89c60 | 73 | .I errno |
e6b5cd8f MK |
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 | |
1fa3625a | 78 | .BR bind (2). |
5cedb08f MK |
79 | In addition, the following errors may occur: |
80 | .TP | |
81 | .BR EACCES | |
ed1ba8a5 MK |
82 | The calling process was not privileged |
83 | (on Linux: the calling process did not have the | |
5cedb08f | 84 | .B CAP_NET_BIND_SERVICE |
ed1ba8a5 | 85 | capability in the user namespace governing its network namespace). |
5cedb08f MK |
86 | .TP |
87 | .B EADDRINUSE | |
88 | All privileged ports are in use. | |
e6b5cd8f | 89 | .TP |
2cbeeec3 | 90 | .BR EAFNOSUPPORT " (" EPFNOSUPPORT " in glibc 2.7 and earlier)" |
e6b5cd8f MK |
91 | .I sin |
92 | is not NULL and | |
5cedb08f | 93 | .I sin->sin_family |
988db661 | 94 | is not |
e6b5cd8f | 95 | .BR AF_INET . |
9ed071a4 | 96 | .SH ATTRIBUTES |
1ff0c445 MK |
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{ | |
9ed071a4 | 105 | .BR bindresvport () |
1ff0c445 MK |
106 | T} Thread safety T{ |
107 | glibc >= 2.17: MT-Safe | |
9ed071a4 | 108 | .\" commit f6da27e53695ad1cc0e2a9490358decbbfdff5e5 |
1ff0c445 MK |
109 | .br |
110 | glibc < 2.17: MT-Unsafe | |
111 | T} | |
112 | .TE | |
113 | .PP | |
114 | The | |
9ed071a4 | 115 | .BR bindresvport () |
1ff0c445 MK |
116 | function uses a static variable that was not protected by a lock |
117 | before glibc 2.17, rendering the function MT-Unsafe. | |
47297adb | 118 | .SH CONFORMING TO |
2a7e150e | 119 | Not in POSIX.1. |
5cedb08f MK |
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 . | |
e6b5cd8f | 127 | .SH SEE ALSO |
5cedb08f MK |
128 | .BR bind (2), |
129 | .BR getsockname (2) |