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 2021-03-22 "" "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 );
42 is used to bind the socket referred to by the
45 to a privileged anonymous IP port,
46 that is, a port number arbitrarily selected from the range 512 to 1023.
47 .\" Glibc actually starts searching with a port # in the range 600 to 1023
57 returns the port number actually allocated.
60 can be NULL, in which case
62 is implicitly taken to be
64 However, in this case,
66 has no way to return the port number actually allocated.
67 (This information can later be obtained using
71 returns 0 on success; otherwise \-1 is returned and
73 is set to indicate the error.
76 can fail for any of the same reasons as
78 In addition, the following errors may occur:
81 The calling process was not privileged
82 (on Linux: the calling process did not have the
83 .B CAP_NET_BIND_SERVICE
84 capability in the user namespace governing its network namespace).
87 All privileged ports are in use.
89 .BR EAFNOSUPPORT " (" EPFNOSUPPORT " in glibc 2.7 and earlier)"
96 For an explanation of the terms used in this section, see
104 Interface Attribute Value
108 glibc\ >=\ 2.17: MT-Safe;
109 .\" commit f6da27e53695ad1cc0e2a9490358decbbfdff5e5
110 glibc\ <\ 2.17: MT-Unsafe
119 function uses a static variable that was not protected by a lock
120 before glibc 2.17, rendering the function MT-Unsafe.
123 Present on the BSDs, Solaris, and many other systems.
128 the glibc implementation ignores any value that the caller supplies in