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
16       descriptor sockfd to a privileged anonymous IP port, that  is,  a  port
17       number 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
26       obtained using getsockname(2).)
27

RETURN VALUE

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

ERRORS

33       bindresvport()  can  fail  for  any of the same reasons as bind(2).  In
34       addition, 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
48       attributes(7).
49
50       ┌───────────────┬───────────────┬─────────────────────────┐
51Interface      Attribute     Value                   
52       ├───────────────┼───────────────┼─────────────────────────┤
53bindresvport() │ Thread safety │ glibc >= 2.17: MT-Safe  │
54       │               │               │ glibc < 2.17: MT-Unsafe │
55       └───────────────┴───────────────┴─────────────────────────┘
56       The  bindresvport()  function  uses a static variable that was not pro‐
57       tected by a lock before glibc 2.17, rendering the function MT-Unsafe.
58

CONFORMING TO

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

NOTES

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

SEE ALSO

67       bind(2), getsockname(2)
68

COLOPHON

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