bind
Purpose
Binds a name to a socket.
Library
Sockets Library (libsock.a)
Syntax
#include <sys/types.h>
#include <sys/socket.h>
int bind (s, name, namelen)
int s;
struct sockaddr *name;
int namelen;
Description
The bind subroutine assigns a name to an unnamed socket.
When a socket is created with the socket subroutine, it
belongs to the address family specified in the socket
call, but has no name assigned yet. The bind subroutine
requests that name be assigned to the socket.
Note that all named sockets must have unique names. A
socket does not have to have a name before it can make a
connection to another socket, and a socket returned by
the accept subroutine already has a name assigned to it
by the subroutine.
Note: Sockets in the AF_UNIX address family do not
create a name in the file system name space.
Return Value
Upon successful completion, a value of 0 is returned. If
the bind routine fails, a value of -1 is returned, and
errno is set to indicate the error.
Diagnostics
The subroutine fails if one or more of the following are
true:
EBADF The s parameter is not valid.
ENOTSOCK The s parameter refers to a file, not a
socket.
EADDRNOTAVAIL The specified address is not available
from the local machine.
EADDRINUSE The specified address is already in
use.
EINVAL The socket is already bound to an
address.
EACCESS The requested address is protected, and
the current user does not have permis-
sion to access it.
EFAULT The addr parameter is not in a writable
part of the user address space.
Related Information
In this book: "connect," "getsockname," "listen," and
"socket."