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

NAME

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

LIBRARY

7     Standard C Library (libc, -lc)
8

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUES

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

ERRORS

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

SEE ALSO

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