1bindresvport(3)            Library Functions Manual            bindresvport(3)
2
3
4

NAME

6       bindresvport - bind a socket to a privileged IP port
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/types.h>
13       #include <netinet/in.h>
14
15       int bindresvport(int sockfd, struct sockaddr_in *sin);
16

DESCRIPTION

18       bindresvport()  is  used to bind the socket referred to by the file de‐
19       scriptor sockfd to a privileged anonymous IP port, that is, a port num‐
20       ber arbitrarily selected from the range 512 to 1023.
21
22       If  the  bind(2)  performed by bindresvport() is successful, and sin is
23       not NULL, then sin->sin_port returns the  port  number  actually  allo‐
24       cated.
25
26       sin  can  be NULL, in which case sin->sin_family is implicitly taken to
27       be AF_INET.  However, in this case, bindresvport() has no way to return
28       the port number actually allocated.  (This information can later be ob‐
29       tained using getsockname(2).)
30

RETURN VALUE

32       bindresvport() returns 0 on success; otherwise -1 is returned and errno
33       is set to indicate the error.
34

ERRORS

36       bindresvport() can fail for any of the same reasons as bind(2).  In ad‐
37       dition, the following errors may occur:
38
39       EACCES The calling process was not privileged (on  Linux:  the  calling
40              process  did not have the CAP_NET_BIND_SERVICE capability in the
41              user namespace governing its network namespace).
42
43       EADDRINUSE
44              All privileged ports are in use.
45
46       EAFNOSUPPORT (EPFNOSUPPORT in glibc 2.7 and earlier)
47              sin is not NULL and sin->sin_family is not AF_INET.
48

ATTRIBUTES

50       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
51       tributes(7).
52
53       ┌───────────────┬───────────────┬──────────────────────────────────────┐
54Interface      Attribute     Value                                
55       ├───────────────┼───────────────┼──────────────────────────────────────┤
56bindresvport() │ Thread safety │ glibc >= 2.17: MT-Safe;              │
57       │               │               │ glibc < 2.17: MT-Unsafe              │
58       └───────────────┴───────────────┴──────────────────────────────────────┘
59
60       The bindresvport()  function  uses  a  static  variable  that  was  not
61       protected  by  a  lock  before  glibc  2.17, rendering the function MT-
62       Unsafe.
63

VERSIONS

65       Present on the BSDs, Solaris, and many other systems.
66

NOTES

68       Unlike some bindresvport() implementations,  the  glibc  implementation
69       ignores any value that the caller supplies in sin->sin_port.
70

STANDARDS

72       BSD.
73

SEE ALSO

75       bind(2), getsockname(2)
76
77
78
79Linux man-pages 6.05              2023-07-20                   bindresvport(3)
Impressum