1 .\" Copyright (C) 2007, Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" and Copyright (C) 2008, Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.com>
5 .\" %%%LICENSE_START(VERBATIM)
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.
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.
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
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
27 .\" 2007-05-31, mtk: Rewrite and substantial additional text.
28 .\" 2008-12-03, mtk: Rewrote some pieces and fixed some errors
30 .TH BINDRESVPORT 3 2013-06-21 "" "Linux Programmer's Manual"
32 bindresvport \- bind a socket to a privileged IP port
35 .B #include <sys/types.h>
36 .B #include <netinet/in.h>
38 .BI "int bindresvport(int " sockfd ", struct sockaddr_in *" sin );
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
55 returns the port number actually allocated.
58 can be NULL, in which case
60 is implicitly taken to be
62 However, in this case,
64 has no way to return the port number actually allocated.
65 (This information can later be obtained using
69 returns 0 on success; otherwise \-1 is returned and
71 set to indicate the cause of the error.
74 can fail for any of the same reasons as
76 In addition, the following errors may occur:
79 The caller did not have superuser privilege (to be precise: the
80 .B CAP_NET_BIND_SERVICE
81 capability is required).
84 All privileged ports are in use.
86 .BR EAFNOSUPPORT " (" EPFNOSUPPORT " in glibc 2.7 and earlier)"
93 .SS Multithreading (see pthreads(7))
94 Before glibc 2.17, the
96 function uses a static variable that is not protected,
97 so it is not thread-safe.
100 .\" commit f6da27e53695ad1cc0e2a9490358decbbfdff5e5
103 function uses a lock to protect static variable, so it is thread-safe.
106 Present on the BSDs, Solaris, and many other systems.
111 the glibc implementation ignores any value that the caller supplies in
117 This page is part of release 3.68 of the Linux
120 A description of the project,
121 information about reporting bugs,
122 and the latest version of this page,
124 \%http://www.kernel.org/doc/man\-pages/.