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  a socket descriptor to a privileged
16       anonymous IP port, that is, a port number arbitrarily selected from the
17       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 caller did not have superuser privilege (to be precise:  the
37              CAP_NET_BIND_SERVICE capability is required).
38
39       EADDRINUSE
40              All privileged ports are in use.
41
42       EAFNOSUPPORT (EPFNOSUPPORT in glibc 2.7 and earlier)
43              sin is not NULL and sin->sin_family is not AF_INET.
44

ATTRIBUTES

46   Multithreading (see pthreads(7))
47       Before  glibc  2.17, the bindresvport() function uses a static variable
48       that is not protected, so it is not thread-safe.
49
50       Since glibc 2.17, the bindresvport() function uses a  lock  to  protect
51       static variable, so it is thread-safe.
52

CONFORMING TO

54       Not in POSIX.1-2001.  Present on the BSDs, Solaris, and many other sys‐
55       tems.
56

NOTES

58       Unlike some bindresvport() implementations,  the  glibc  implementation
59       ignores any value that the caller supplies in sin->sin_port.
60

SEE ALSO

62       bind(2), getsockname(2)
63

COLOPHON

65       This  page  is  part of release 3.53 of the Linux man-pages project.  A
66       description of the project, and information about reporting  bugs,  can
67       be found at http://www.kernel.org/doc/man-pages/.
68
69
70
71                                  2013-06-21                   BINDRESVPORT(3)
Impressum