Binds an address to a specified socket.
#include <prio.h> PRStatus PR_Bind( PRFileDesc *fd, const PRNetAddr *addr);
The function has the following parameters:
fd
PRFileDesc
object representing a socket.addr
PRNetAddr
object representing the address to which the socket will be bound.The function returns one of the following values:
PR_SUCCESS
.PR_FAILURE
. Further information can be obtained by calling PR_GetError
.When a new socket is created, it has no address bound to it. PR_Bind
assigns the specified address (also known as name) to the socket. If you do not care about the exact IP address assigned to the socket, set the inet.ip
field of PRNetAddr
to PR_htonl
(PR_INADDR_ANY
). If you do not care about the TCP/UDP port assigned to the socket, set the inet.port
field of PRNetAddr
to 0.
Note that if PR_Connect
is invoked on a socket that is not bound, it implicitly binds an arbitrary address the socket.
Call PR_GetSockName
to obtain the address (name) bound to a socket.