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