gtpc1m3lTransmission Control Protocol/Internet Protocol

bind -- Bind a Local Name to the Socket

The bind function binds a unique local name to the socket with descriptor s.

Format

#include <socket.h>
int      bind(int s,
              struct sockaddr *name,
              int namelen);

s
The socket descriptor.

name
Pointer to a sockaddr structure (buffer) containing the name that is to be bound to s.

namelen
Size of the buffer pointed to by name, in bytes.

Normal Return

Return code 0 indicates that the function was successful.

Error Return

The return code -1 indicates an error. You can get the specific error code by calling sock_errno. See Appendix C, Socket Error Return Codes for more information about socket errors.

Note:
Unless otherwise stated in the description, the following error codes can be returned for either TCP/IP offload support or TCP/IP native stack support.

Value
Description

SOCADDRINUSE
The address is already in use. See setsockopt -- Set Options Associated with a Socket for more information on the SO_REUSEADDR option.

SOCADDRNOTAVAIL
The address specified is not valid on this host.

SOCAFNOSUPPORT
The address family is not supported.

SOCFAULT
Using name and namelen would result in an attempt to copy the address into a protected address space. This error code is returned only for TCP/IP offload support.

SOCINVAL
The socket is already bound to an address. For example, you cannot bind a name to a socket that is in the connected state. This value is also returned if namelen is not the expected length.

SOCNOBUFS
There is not enough buffer space. This error code is returned only for TCP/IP offload support.

SOCNOTSOCK
The s parameter is not a valid socket descriptor.

SOCIPNOTFOUND
The TPF system could not locate the Internet Protocol (IP) table header. This error code is returned only for TCP/IP offload support.

EIBMIUCVERR
An error occurred when the function call was sent to the offload device. This error code is returned only for TCP/IP offload support.

E1052STATE
The socket was closed because the system was in or cycling down to 1052 state.

EINACT
All offload devices associated with the socket descriptor have been disconnected. The socket is closed. This error code is returned only for TCP/IP offload support.

EINACTWS
An offload device associated with the socket descriptor has been disconnected. The socket is still available. This error code is returned only for TCP/IP offload support.

ESYSTEMERROR
A system error has occurred and closed the socket. This error code is returned only for TCP/IP offload support.

OFFLOADTIMEOUT
No response was received from the offload device in a specified time period. This error code is returned only for TCP/IP offload support.

Programming Considerations

Examples

  1. Bind to a specific interface in the internet domain and make sure the sin_zero field is cleared:
    #include <socket.h>
    
    ·
    ·
    ·
    int rc; int s; struct sockaddr_in myname;
    ·
    ·
    ·
    memset(&myname, 0, sizeof(myname)); myname.sin_family = AF_INET; myname.sin_port = 5001; myname.sin_addr.s_addr = inetaddr("129.5.24.1"); /*specific interface*/ rc = bind(s, (struct sockaddr *) &myname, sizeof(myname));
  2. Bind to all network interfaces in the internet domain.
    memset(&myname, 0, sizeof(myname));
    myname.sin_family      = AF_INET;
    myname.sin_port        = 5001;
    myname.sin_addr.s_addr = INADDR_ANY; /* all interfaces */
    rc = bind(s, (struct sockaddr *) &myname, sizeof(myname));
    
  3. Bind to a specific interface in the internet domain and let the system choose a port.
    memset(&myname, 0, sizeof(myname));
    myname.sin_family      = AF_INET;
    myname.sin_port        = INADDR_ANY;
    myname.sin_addr.s_addr = inetaddr("129.5.24.1"); /*specific interface*/
    rc = bind(s, (struct sockaddr *) &myname, sizeof(myname));
    

Related Information