]>
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> | |
93015253 | 4 | .\" %%%LICENSE_START(VERBATIM) |
5cedb08f MK |
5 | .\" Permission is granted to make and distribute verbatim copies of this |
6 | .\" manual provided the copyright notice and this permission notice are | |
7 | .\" preserved on all copies. | |
f5fed0f6 | 8 | .\" |
5cedb08f MK |
9 | .\" Permission is granted to copy and distribute modified versions of this |
10 | .\" manual under the conditions for verbatim copying, provided that the | |
11 | .\" entire resulting derived work is distributed under the terms of a | |
12 | .\" permission notice identical to this one. | |
13 | .\" | |
14 | .\" Since the Linux kernel and libraries are constantly changing, this | |
15 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
16 | .\" responsibility for errors or omissions, or for damages resulting from | |
17 | .\" the use of the information contained herein. The author(s) may not | |
18 | .\" have taken the same level of care in the production of this manual, | |
19 | .\" which is licensed free of charge, as they might when working | |
20 | .\" professionally. | |
21 | .\" | |
22 | .\" Formatted or processed versions of this manual, if unaccompanied by | |
23 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 24 | .\" %%%LICENSE_END |
e6b5cd8f MK |
25 | .\" |
26 | .\" 2007-05-31, mtk: Rewrite and substantial additional text. | |
5cedb08f | 27 | .\" 2008-12-03, mtk: Rewrote some pieces and fixed some errors |
e6b5cd8f | 28 | .\" |
4510cb9d | 29 | .TH BINDRESVPORT 3 2008-12-03 "" "Linux Programmer's Manual" |
fea681da MK |
30 | .SH NAME |
31 | bindresvport \- bind a socket to a privileged IP port | |
32 | .SH SYNOPSIS | |
33 | .nf | |
34 | .B #include <sys/types.h> | |
35 | .B #include <netinet/in.h> | |
36 | .LP | |
5cedb08f | 37 | .BI "int bindresvport(int " sockfd ", struct sockaddr_in *" sin ); |
fea681da MK |
38 | .fi |
39 | .SH DESCRIPTION | |
40 | .LP | |
63aa9df0 | 41 | .BR bindresvport () |
5cedb08f MK |
42 | is used to bind a socket descriptor to a privileged anonymous IP port, |
43 | that is, a port number arbitrarily selected from the range 512 to 1023. | |
44 | .\" Glibc actually starts searching with a port # in the range 600 to 1023 | |
e6b5cd8f | 45 | |
e6b5cd8f MK |
46 | If the |
47 | .BR bind (2) | |
988db661 | 48 | performed by |
e6b5cd8f | 49 | .BR bindresvport () |
5cedb08f MK |
50 | is successful, and |
51 | .I sin | |
52 | is not NULL, then | |
e6b5cd8f MK |
53 | .I sin\->sin_port |
54 | returns the port number actually allocated. | |
55 | ||
56 | .I sin | |
57 | can be NULL, in which case | |
58 | .I sin\->sin_family | |
59 | is implicitly taken to be | |
5cedb08f | 60 | .BR AF_INET . |
988db661 | 61 | However, in this case, |
e6b5cd8f MK |
62 | .BR bindresvport () |
63 | has no way to return the port number actually allocated. | |
5cedb08f MK |
64 | (This information can later be obtained using |
65 | .BR getsockname (2).) | |
e6b5cd8f MK |
66 | .SH RETURN VALUE |
67 | .BR bindresvport () | |
5cedb08f | 68 | returns 0 on success; otherwise \-1 is returned and |
1bf89c60 | 69 | .I errno |
e6b5cd8f MK |
70 | set to indicate the cause of the error. |
71 | .SH ERRORS | |
72 | .BR bindresvport () | |
73 | can fail for any of the same reasons as | |
1fa3625a | 74 | .BR bind (2). |
5cedb08f MK |
75 | In addition, the following errors may occur: |
76 | .TP | |
77 | .BR EACCES | |
78 | The caller did not have superuser privilege (to be precise: the | |
79 | .B CAP_NET_BIND_SERVICE | |
80 | capability is required). | |
81 | .TP | |
82 | .B EADDRINUSE | |
83 | All privileged ports are in use. | |
e6b5cd8f | 84 | .TP |
2cbeeec3 | 85 | .BR EAFNOSUPPORT " (" EPFNOSUPPORT " in glibc 2.7 and earlier)" |
e6b5cd8f MK |
86 | .I sin |
87 | is not NULL and | |
5cedb08f | 88 | .I sin->sin_family |
988db661 | 89 | is not |
e6b5cd8f | 90 | .BR AF_INET . |
47297adb | 91 | .SH CONFORMING TO |
5cedb08f MK |
92 | Not in POSIX.1-2001. |
93 | Present on the BSDs, Solaris, and many other systems. | |
94 | .SH NOTES | |
95 | Unlike some | |
96 | .BR bindresvport () | |
97 | implementations, | |
98 | the glibc implementation ignores any value that the caller supplies in | |
99 | .IR sin\->sin_port . | |
e6b5cd8f | 100 | .SH SEE ALSO |
5cedb08f MK |
101 | .BR bind (2), |
102 | .BR getsockname (2) |