rresvport_af Subroutine

Purpose

Retrieves a socket with a privileged address.

Syntax

      int  rresvport_af(int *port, int family);

Description

The rresvport_af subroutine obtains a socket with a privileged address bound to the socket. A privileged Internet port is one that falls in a range between 0 and 1023.

This subroutine is similar to the existing rresvport() subroutine, except that rresvport_af also takes and address family as an argument. This function is capable of creating either an AF_INET/TCP or an AF_INET6/TCP socket.

Only processes with an effective user ID of root user can use the rresvport subroutine. An authentication scheme based on remote port numbers is used to verify permissions.

If the connection succeeds, a socket in the Internet domain of type SOCK_STREAM is returned to the calling process.

All applications containing the rresvport subroutine must be compiled with the _BSD macro set to a specific value. Acceptable values are 43 and 44. In addition, all socket applications must include the BSD libbsd.a library.

Parameters

Item Description
port Specifies the port to use for the connection.
family Specifies either AF_INET or AF_INET6 to accommodate the appropriate version.

Return Values

Upon successful completion, the rresvport_af subroutine returns a valid, bound socket descriptor.

If the rresvport_af subroutine is unsuccessful, the subroutine handler performs the following functions:
  • Returns a value of -1 to the calling program.
  • Moves an error code, indicating the specific error, into the errno global variable.

Error Codes

Item Description
EAFNOSUPPORT The address family is not supported.
EAGAIN All network ports are in use.
EMFILE Two hundred file descriptors are currently open.
ENFILE The system file table is full.
ENOBUFS Insufficient buffers are available in the system to complete the subroutine.

Files

Item Description
/etc/services Contains the service names.