1BINDRESVPORT(3)            Linux Programmer's Manual           BINDRESVPORT(3)
2
3
4

NAME

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

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

29       bindresvport() returns 0 on success; otherwise -1 is returned and errno
30       is set to indicate the error.
31

ERRORS

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

ATTRIBUTES

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

CONFORMING TO

61       Not in POSIX.1.  Present on the BSDs, Solaris, and many other systems.
62

NOTES

64       Unlike  some  bindresvport()  implementations, the glibc implementation
65       ignores any value that the caller supplies in sin->sin_port.
66

SEE ALSO

68       bind(2), getsockname(2)
69

COLOPHON

71       This page is part of release 5.13 of the Linux  man-pages  project.   A
72       description  of  the project, information about reporting bugs, and the
73       latest    version    of    this    page,    can     be     found     at
74       https://www.kernel.org/doc/man-pages/.
75
76
77
78                                  2021-03-22                   BINDRESVPORT(3)
Impressum