The SockBind() call binds a local name to the socket.
is the socket descriptor returned by a previous call to SockSocket().
is a stem variable containing the address that is to be bound to socket.
SockBind() binds the unique local name address to the socket with descriptor socket. After calling SockSocket(), a descriptor does not have a name. However, it belongs to a particular address family that you specified when calling SockSocket().
Because socket was created in the AF_INET domain, the fields of the stem address are as follows:
The family field must be set to AF_INET. The port field is set to the port to which the application must bind. If port is set to 0, the caller allows the system to assign an available port. The application can call SockGetSockName() to discover the port number assigned. The addr field is set to the Internet address. On hosts with more than one network interface (called multihomed hosts), a caller can select the interface with which it is to bind.
Only UDP packets and TCP connection requests from this interface that match the bound name are routed to the application. This is important when a server offers a service to several networks. If addr is set to INADDR_ANY, the caller requests socket be bound to all network interfaces on the host. If you do not specify an address, the server can accept all UDP packets and TCP connection requests made to its port, regardless of the network interface on which the requests arrived.
The value 0 indicates successful execution of the call. The value -1 indicates an error. You can get the specific error code by calling SockSock_Errno() or SockPSock_Errno(). Possible values:
address is already in use. See the SO_REUSEADDR option described under SockGetSockOpt() and the SO_REUSEADDR option described under SockSetSockOpt().
The address specified is not valid on this host. For example, the Internet address does not specify a valid network interface.
The address family is not supported.
socket is not a valid socket descriptor.
socket is already bound to an address.
No buffer space available.
Note: SockBind() interfaces with the C function bind().