bind.2 (2010 09)

b
bind(2) bind(2)
NAME
bind() - bind an address to a socket
SYNOPSIS
#include <sys/socket.h>
AF_CCITT only
#include <x25/x25addrstr.h>
AF_INET, AF_INET6 and AF_VME_LINK only
#include <netinet/in.h>
AF_UNIX only
#include <sys/un.h>
int bind(int s, const void *addr, int addrlen);
UNIX 03 only (X/Open Sockets)
int bind(int s, const struct sockaddr *addr, socklen_t addrlen);
Obsolescent UNIX 95 only (X/Open Sockets)
int bind(int s, const struct sockaddr *addr, size_t addrlen);
DESCRIPTION
The bind() system call assigns an address to an unbound socket. When a socket is created with
socket(), it exists in an address space (address family) but has no address assigned. bind()
causes
the socket whose descriptor is s to become bound to the address specified in the socket address structure
pointed to by addr.
addrlen must specify the size of the address structure. Since the size of the socket address structure
varies between socket address families, the correct socket address structure should be used with each
address family (for example,
struct sockaddr_in for AF_INET and AF_VME_LINK, struct
sockaddr_in6 for AF_INET6, and struct sockaddr_un for AF_UNIX). Typically, the
sizeof()
function is used to pass this value in the bind() call (for example, sizeof(struct
sockaddr_in)).
The rules used in address binding vary between communication domains. For example, when binding an
AF_UNIX socket to a path name (such as
/tmp/mysocket
), an open file having that name is created in
the file system. When the bound socket is closed, that file still exists unless it is removed or unlinked.
When binding an AF_INET socket or an AF_INET6 socket, sin_port can be a port number or it can be
zero. If sin_port is zero, the system assigns an unused port number automatically.
AF_VME_LINK Only
The
bind() system call is used only by servers and not clients.
X/Open Sockets Compilation Environment
See xopen_networking(7).
RETURN VALUE
bind() returns the following values:
0 Successful completion.
-1 Failure. errno is set to indicate the error.
ERRORS
If
bind() fails, errno is set to one of the following values.
[EACCES] The requested address is protected, and the current user has inadequate permission
to access it. (This error can be returned by AF_INET or AF_INET6 only.)
[EADDRINUSE] The specified address is already in use.
[EADDRNOTAVAIL] The specified address is invalid or not available from the local machine, or for
AF_CCITT sockets which use "wild card" addressing, the specified address space
overlays the address space of an existing bind.
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (2 pages)