]>
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 | .\" |
fe0fefbf | 30 | .TH BINDRESVPORT 3 2015-03-02 "" "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> | |
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 |
43 | is used to bind a socket descriptor to a privileged anonymous IP port, |
44 | that 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 |
47 | If the |
48 | .BR bind (2) | |
988db661 | 49 | performed by |
e6b5cd8f | 50 | .BR bindresvport () |
5cedb08f MK |
51 | is successful, and |
52 | .I sin | |
53 | is not NULL, then | |
e6b5cd8f MK |
54 | .I sin\->sin_port |
55 | returns the port number actually allocated. | |
56 | ||
57 | .I sin | |
58 | can be NULL, in which case | |
59 | .I sin\->sin_family | |
60 | is implicitly taken to be | |
5cedb08f | 61 | .BR AF_INET . |
988db661 | 62 | However, in this case, |
e6b5cd8f MK |
63 | .BR bindresvport () |
64 | has 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 | 69 | returns 0 on success; otherwise \-1 is returned and |
1bf89c60 | 70 | .I errno |
e6b5cd8f MK |
71 | set to indicate the cause of the error. |
72 | .SH ERRORS | |
73 | .BR bindresvport () | |
74 | can fail for any of the same reasons as | |
1fa3625a | 75 | .BR bind (2). |
5cedb08f MK |
76 | In addition, the following errors may occur: |
77 | .TP | |
78 | .BR EACCES | |
79 | The caller did not have superuser privilege (to be precise: the | |
80 | .B CAP_NET_BIND_SERVICE | |
81 | capability is required). | |
82 | .TP | |
83 | .B EADDRINUSE | |
84 | All privileged ports are in use. | |
e6b5cd8f | 85 | .TP |
2cbeeec3 | 86 | .BR EAFNOSUPPORT " (" EPFNOSUPPORT " in glibc 2.7 and earlier)" |
e6b5cd8f MK |
87 | .I sin |
88 | is not NULL and | |
5cedb08f | 89 | .I sin->sin_family |
988db661 | 90 | is not |
e6b5cd8f | 91 | .BR AF_INET . |
9ed071a4 | 92 | .SH ATTRIBUTES |
1ff0c445 MK |
93 | For an explanation of the terms used in this section, see |
94 | .BR attributes (7). | |
95 | .TS | |
96 | allbox; | |
97 | lb lb lb | |
98 | l l lw23. | |
99 | Interface Attribute Value | |
100 | T{ | |
9ed071a4 | 101 | .BR bindresvport () |
1ff0c445 MK |
102 | T} Thread safety T{ |
103 | glibc >= 2.17: MT-Safe | |
9ed071a4 | 104 | .\" commit f6da27e53695ad1cc0e2a9490358decbbfdff5e5 |
1ff0c445 MK |
105 | .br |
106 | glibc < 2.17: MT-Unsafe | |
107 | T} | |
108 | .TE | |
109 | .PP | |
110 | The | |
9ed071a4 | 111 | .BR bindresvport () |
1ff0c445 MK |
112 | function uses a static variable that was not protected by a lock |
113 | before glibc 2.17, rendering the function MT-Unsafe. | |
47297adb | 114 | .SH CONFORMING TO |
2a7e150e | 115 | Not in POSIX.1. |
5cedb08f MK |
116 | Present on the BSDs, Solaris, and many other systems. |
117 | .SH NOTES | |
118 | Unlike some | |
119 | .BR bindresvport () | |
120 | implementations, | |
121 | the 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) |