# man > bindresvport(3)

[BINDRESVPORT(3)](https://www.chedong.com/phpMan.php/man/BINDRESVPORT/3/markdown)          BSD Library Functions Manual          [BINDRESVPORT(3)](https://www.chedong.com/phpMan.php/man/BINDRESVPORT/3/markdown)

## NAME
     **bindresvport**, **bindresvport**___**sa** — bind a socket to a privileged IP port

## SYNOPSIS
### #include <sys/types.h>
### #include <rpc/rpc.h>

     _int_
     **bindresvport**(_int_ _sd_, _struct_ _sockaddr_in_ _*sin_);

     _int_
     **bindresvport**___**sa**(_int_ _sd_, _struct_ _sockaddr_ _*sa_);

## DESCRIPTION
     The **bindresvport**() and **bindresvport**___**sa**() functions are used to bind a socket descriptor to a
     privileged IP port, that is, a port number in the range 0-1023.

     If _sin_ is a pointer to a _struct_ _sockaddr_in_ then the appropriate fields in the structure should
     be defined.  Note that _sin->sin_family_ must be initialized to the address family of the socket,
     passed by _sd_.  If _sin->sin_port_ is ‘0’ then an anonymous port (in the range 600-1023) will be
     chosen, and if [bind(2)](https://www.chedong.com/phpMan.php/man/bind/2/markdown) is successful, the _sin->sin_port_ will be updated to contain the allo‐
     cated port.

     If _sin_ is the NULL pointer, an anonymous port will be allocated (as above).  However, there is
     no way for **bindresvport**() to return the allocated port in this case.

     Only root can bind to a privileged port; this call will fail for any other users.

     Function prototype of **bindresvport**() is biased to AF_INET socket.  The **bindresvport**___**sa**() func‐
     tion acts exactly the same, with more neutral function prototype.  Note that both functions be‐
     have exactly the same, and both support AF_INET6 sockets as well as AF_INET sockets.

## RETURN VALUES
     The **bindresvport**() function returns the value 0 if successful; otherwise the value -1 is re‐
     turned and the global variable _errno_ is set to indicate the error.

## ERRORS
     [EPFNOSUPPORT]     If second argument was supplied, and address family did not match between
                        arguments.

     The **bindresvport**() function may also fail and set _errno_ for any of the errors specified for the
     calls [bind(2)](https://www.chedong.com/phpMan.php/man/bind/2/markdown), [getsockopt(2)](https://www.chedong.com/phpMan.php/man/getsockopt/2/markdown), or [setsockopt(2)](https://www.chedong.com/phpMan.php/man/setsockopt/2/markdown).

## AVAILABILITY
     The **bindresvport**() function is part of libtirpc.

## SEE ALSO
     [bind(2)](https://www.chedong.com/phpMan.php/man/bind/2/markdown), [getsockopt(2)](https://www.chedong.com/phpMan.php/man/getsockopt/2/markdown), [setsockopt(2)](https://www.chedong.com/phpMan.php/man/setsockopt/2/markdown)

BSD                            November 22, 1987                           BSD
