|int rresvport||(int * portToReservePtr);|
rresvport() is used to create a TCP socket and bind a reserved port to the socket starting with the port to reserve given by the user. The portToReservePtr parameter is a value result parameter. The integer pointed to by portToReservePtr is the first port number that the function attempts to bind to. The caller typically initializes the starting port number to IPPORT_RESERVED - 1. (IPPORT_RESERVED is defined as 1024.) If the bind() fails because that port is already used, then rresvport() decrements the port number and tries again. If it finally reaches IPPORT_RESERVEDSTART (defined as 600) and finds it already in use, it returns TM_SOCKET_ERROR and sets the socket error to TM_EAGAIN. If this function successfully binds to a reserved port number, it returns the socket descriptor to the user and stores the reserved port that the socket is bound to in the integer cell pointed to by portToReservePtr.
- A pointer to the port number to reserve. Upon return a pointer to the port number reserved.
- >= 0
- Valid socket descriptor.
|Note:|| TM_SOCKET_ERROR means that this socket call has failed and the errorCode has been set on the socket itself.
To retrieve the socket error the user must call tfGetSocketError(socketDescriptor).
Possible socket errors
- The stack could not find any port number available between IPPORT_RESERVEDSTART and the port number to reserve.
- portToReservePtr is 0 or less than IPPORT_RESERVEDSTART.