]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/bindresvport.3
locale.5, epoll.7: srcfix: Remove unneeded comment
[thirdparty/man-pages.git] / man3 / bindresvport.3
CommitLineData
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
31bindresvport \- 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
42is used to bind a socket descriptor to a privileged anonymous IP port,
43that 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
46If the
47.BR bind (2)
988db661 48performed by
e6b5cd8f 49.BR bindresvport ()
5cedb08f
MK
50is successful, and
51.I sin
52is not NULL, then
e6b5cd8f
MK
53.I sin\->sin_port
54returns the port number actually allocated.
55
56.I sin
57can be NULL, in which case
58.I sin\->sin_family
59is implicitly taken to be
5cedb08f 60.BR AF_INET .
988db661 61However, in this case,
e6b5cd8f
MK
62.BR bindresvport ()
63has 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 68returns 0 on success; otherwise \-1 is returned and
1bf89c60 69.I errno
e6b5cd8f
MK
70set to indicate the cause of the error.
71.SH ERRORS
72.BR bindresvport ()
73can fail for any of the same reasons as
1fa3625a 74.BR bind (2).
5cedb08f
MK
75In addition, the following errors may occur:
76.TP
77.BR EACCES
78The caller did not have superuser privilege (to be precise: the
79.B CAP_NET_BIND_SERVICE
80capability is required).
81.TP
82.B EADDRINUSE
83All privileged ports are in use.
e6b5cd8f 84.TP
2cbeeec3 85.BR EAFNOSUPPORT " (" EPFNOSUPPORT " in glibc 2.7 and earlier)"
e6b5cd8f
MK
86.I sin
87is not NULL and
5cedb08f 88.I sin->sin_family
988db661 89is not
e6b5cd8f 90.BR AF_INET .
47297adb 91.SH CONFORMING TO
5cedb08f
MK
92Not in POSIX.1-2001.
93Present on the BSDs, Solaris, and many other systems.
94.SH NOTES
95Unlike some
96.BR bindresvport ()
97implementations,
98the 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)