Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

bind() - assign a socket a name

&pagelevel(3)&pagelevel

#include <sys.types.h>
#include <sys.socket.h>

#include <netinet.in.h> /* only for AF_INET and AF_INET6 */
#include <iso.h> /* only for AF_ISO */
   
Kernighan-Ritchie-C: int bind(s, name, namelen);
int s;
int namelen;

struct sockaddr_in *name;  /* only for AF_INET  */
struct sockaddr_in6 *name; /* only for AF_INET6 */
struct sockaddr_iso *name; /* only for AF_ISO   */

ANSI-C: 
int bind(int s, struct sockaddr* name, int namelen);


Description

The bind() function assigns a name to a socket created with the socket() function that is initially nameless. After a socket has been created with the socket() function, the socket exists within a name area (address family) but it has no name.

The s parameter designates the socket to which a name is to be assigned with bind().namelen specifies the length of the data structure which describes the name.

Return value

0:

If successful.

-1:

If errors occur. errno is set to indicate the error.

Errors indicated by errno

EADDRINUSE

The specified name is already in use.

EADDRNOTAVAIL

The specified name cannot be bound to the socket by the local system.

EBADF

s is not a valid descriptor.

EFAULT

The length of the area for accepting the address is too small. 

EINVAL

The socket already has a name assigned to it or namelen does not have the size of a valid address for the specified address family.

ENETDOWN

The connection to the network is down.

See also

connect(), getsockname(), listen(), socket()