1BINDRESVPORT(3)          BSD Library Functions Manual          BINDRESVPORT(3)
2

NAME

4     bindresvport, bindresvport_sa — bind a socket to a privileged IP port
5

SYNOPSIS

7     #include <sys/types.h>
8     #include <rpc/rpc.h>
9
10     int
11     bindresvport(int sd, struct sockaddr_in *sin);
12
13     int
14     bindresvport_sa(int sd, struct sockaddr *sa);
15

DESCRIPTION

17     The bindresvport() and bindresvport_sa() functions are used to bind a
18     socket descriptor to a privileged IP port, that is, a port number in the
19     range 0-1023.
20
21     If sin is a pointer to a struct sockaddr_in then the appropriate fields
22     in the structure should be defined.  Note that sin->sin_family must be
23     initialized to the address family of the socket, passed by sd.  If
24     sin->sin_port is ‘0’ then an anonymous port (in the range 600-1023) will
25     be chosen, and if bind(2) is successful, the sin->sin_port will be
26     updated to contain the allocated port.
27
28     If sin is the NULL pointer, an anonymous port will be allocated (as
29     above).  However, there is no way for bindresvport() to return the allo‐
30     cated port in this case.
31
32     Only root can bind to a privileged port; this call will fail for any
33     other users.
34
35     Function prototype of bindresvport() is biased to AF_INET socket.  The
36     bindresvport_sa() function acts exactly the same, with more neutral func‐
37     tion prototype.  Note that both functions behave exactly the same, and
38     both support AF_INET6 sockets as well as AF_INET sockets.
39

RETURN VALUES

41     The bindresvport() function returns the value 0 if successful; otherwise
42     the value -1 is returned and the global variable errno is set to indicate
43     the error.
44

ERRORS

46     [EPFNOSUPPORT]     If second argument was supplied, and address family
47                        did not match between arguments.
48
49     The bindresvport() function may also fail and set errno for any of the
50     errors specified for the calls bind(2), getsockopt(2), or setsockopt(2).
51

AVAILABILITY

53     The bindresvport() function is part of libtirpc.
54

SEE ALSO

56     bind(2), getsockopt(2), setsockopt(2)
57
58BSD                            November 22, 1987                           BSD
Impressum