bind()

NAME

bind() - bind a name to a socket

SYNOPSIS

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

int bind (int s, const struct sockaddr *addr, int addrlen)

DESCRIPTION

The bind(2) function assigns an address addr to an unnamed socket s. When a socket is created with socket(2) it exists in a name space (address family) but has no name assigned. The bind(2) function requests that name be assigned to the socket.

The arguments are:

s
The socket to be bound.
addr
A pointer to a socket address structure. TCP/IP and UDP supports and sockets.
addrlen
The length of the sockaddr structure pointed to by addr.

RETURN VALUES

If the bind is successful, the function returns 0. If there is an error, the function returns -1, and sets errno to indicate the error.

ERRORS

The bind(2) call will fail if:

[EACCES]
The requested address is protected, and the current user has inadequate permission to access it. This error cannot occur in the INTERIX implementation, because there are no privileged ports (that is, ports 0-1024 are not restricted).
[EADDRNOTAVAIL]
The specified address is not available from the local machine.
[EADDRINUSE]
The specified address is already in use.
[EBADF]
The value of s is not a valid descriptor.
[EFAULT]
The addr parameter is not in a valid part of the user address space.
[EINVAL]
The socket is already bound to an address, or the call was applied against a device that doesn't support sockets.
[ENOTSOCK]
The value of s is not a socket.

The following errors are specific to sockets using the AF_LOCAL protocol family (previously known as AF_UNIX), and therefore will not appear on INTERIX:

[ENOTDIR]
A component of the path prefix is not a directory.
[EINVAL]
The pathname contains a character with the high-order bit set.
[EIO]
An I/O error occurred while making the directory entry or allocating the file serial number.
[EISDIR]
An empty pathname was specified.
[ELOOP]
Too many symbolic links were encountered in translating the pathname.
[ENAMETOOLONG]
A component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters.
[ENOENT]
A prefix component of the path name does not exist.
[EROFS]
The name would reside on a read-only file system.

SEE ALSO

connect(2)

listen(2)

socket(2)

getsockname(2)