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 name to a socket

&pagelevel(4)&pagelevel

#include <sys/socket.h>

int bind(int s, const struct sockaddr *name, size_t 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().

name points to the name (address) to be assigned to the socket.

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

EACCES

The specified name is protected and the calling user has no rights to access it.

EADDRINUSE

The specified name is already in use.

EADDRNOTAVAIL

The specified name cannot be bound to the socket by the local system (see also "Dependencies on the BS2000 transport system BCAM" for more information).

EAFNOSUPPORT

The specified address family does not match that of the socket.

EBADF

s is not a valid descriptor.

EFAULT

name does not point to the writable part of the user address range.

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.

ENOBUFS

Not enough resources to execute bind().

ENOTSOCK

The descriptor references a file and not a socket.

If the address family of the socket is AF_UNIX, executing bind() can also lead to an error for the following reasons:

EACCES

The specified name is protected or the calling user has no write rights for the specified name.

EDESTADDRREQ

The name parameter is the null pointer.

ENAMETOOLONG

A path name component exceeds NAME_MAX characters or the complete path name is longer than PATH_MAX characters.

ENOENT

A path name component refers to a non-existent file or the path name is blank.

ENOTDIR

A path name component is not a directory.

See also

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