bind()

associate local address with socket 

Function


SYNOPSIS

#include <sys/types.h>

#include <sys/socket.h>

int bind(int s, const struct sockaddr *name, socklen_t namelen);


DESCRIPTION

The bind() function associates a local address with a socket. Specifically, bind() assigns a local name to an unnamed socket. This routine is used on an unconnected datagram or stream socket, before a subsequent connect() or listen(). When socket() creates a socket, it exists in a name space (address family) but it has no name assigned. The bind() call requests that the name pointed to by name be assigned to the socket. The interpretation of name depends upon the address family of the socket.


PARAMETERS

s 

Specifies the integer descriptor of the unbounded socket.

name 

Points to a sockaddr structure containing the address to be bound to the socket. The length and format of the address depend on the address family of the socket.

namelen 

Specifies the length of name in bytes.


RETURN VALUES

If successful, bind() returns a value of zero. On failure, it returns -1 and sets errno to one of the following values:

EACCES 

For sockets in the AF_UNIX address family, the specified address does not specify a disk file local to the machine.

  

For sockets in the AF_UNIX address family, a component of the path prefix denies search permission, or the requested name requires writing in a directory with a mode that denies write permission.

EADDRINUSE 

The specified address is already in use. [See the SO_REUSEADDR socket option under setsockopt().]

EAFNOSUPPORT 

The protocol used in the creation of specified socket does not support the specified address family.

EBADF 

s is not a valid descriptor.

EFAULT 

name is an invalid pointer or the namelen parameter is too small (less than the size of a struct sockaddr).

EINVAL 

The socket is already bound to an address.

ENETDOWN 

The Windows sockets implementation has detected that the network subsystem has failed.

ENOBUFS 

Not enough buffers are available; there are too many connections.

ENOTSOCK 

The descriptor is not a socket.


CONFORMANCE

UNIX98, with exceptions.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

The NuTCRACKER Platform supports all the address families that WinSock 2.0 supports. Sockets from the AF_UNIX address family are bound to file system objects. The NuTCRACKER Platform requires that the paths be local to the system on which bind() is called. In addition, UNC paths cannot be used to bind AF_UNIX sockets.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
connect(), getsockname(), listen(), socket()


PTC MKS Toolkit 10.4 Documentation Build 39.