DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

bind(SSC)


bind -- bind a protocol address to a socket

Synopsis

cc [options] file -lsocket -lnsl
#include <sys/types.h>
#include <sys/socket.h>

int bind(int socket, const struct sockaddr *name, size_t namelen);

Description

bind assigns a protocol address to an unnamed socket. When a socket is created with socket, it exists in a name space (address family) but has no assigned address. bind requests that the protocol address pointed to by name be assigned to the socket. namelen specifies the length of the sockaddr structure pointed to by name.

Files

usr/lib/locale/locale/LC_MESSAGES/uxnsl

Return values

If the bind is successful, a 0 value is returned. A return value of -1 indicates an error, which is further specified in the global errno.

Errors

The bind call will fail if:

EBADF
s is not a valid descriptor.

ENOTSOCK
s is a descriptor for a file, not a socket.

EADDRNOTAVAIL
The specified address is not available on the local machine.

EADDRINUSE
The specified address is already in use.

EINVAL
namelen is not the size of a valid address for the specified address family.

EINVAL
The socket is already bound to an address, and the protocol does not support binding to a new address, or the socket has been shut down.

EACCES
The requested address is protected and the current user has inadequate permission to access it.

ENOSR
There were insufficient STREAMS resources for the operation to complete.

EAFNOSUPPORT
The specified address is not a valid address for the address family of the specified socket.

EOPNOTSUPP
The socket type of the specified socket does not support binding to an address.

EISCONN
The socket is already connected.

ENAMETOOLONG
Pathname resolution of a symbolic link produced an intermediate result whose length exceeds PATH_MAX.

ENOBUFS
Insufficient resources were available to complete the call.

The following errors are specific to binding names in the UNIX domain:


ENOTDIR
A component of the path prefix of the pathname in name is not a directory.

ENOENT
A component of the path prefix of the pathname in name does not exist, or the pathname is an empty string.

EACCES
Search permission is denied for a component of the path prefix of the pathname in name, or the requested name requires writing in a directory with a mode that denies write permission.

ELOOP
Too many symbolic links were encountered in translating the pathname in name.

ENAMETOOLONG
A component of the pathname exceeded NAME_MAX characters, or an entire pathname exceeded PATH_MAX characters.

EIO
An I/O error occurred while making the directory entry or allocating the inode.

EROFS
The inode would reside on a read-only file system.

EISDIR
A null pathname was specified.

References

connect(SSC), getsockname(SSC), listen(SSC), socket(SSC), unlink(S)

RFC 2133

Notices

Binding a name in the UNIX domain creates a socket in the file system that must be deleted by the caller when it is no longer needed (see unlink(S)).

The rules used in binding names vary between communication domains.

The type of address structure passed to bind depends on the address family. UNIX domain sockets (address family AF_UNIX) require a struct sockaddr_un as defined in sys/un.h; Internet domain IPv4 sockets (address family AF_INET) require a struct sockaddr_in as defined in netinet/in.h; Internet domain IPv6 sockets (address family AF_INET6) require a struct sockaddr_in6 as defined in netinet/in.h. Other address families may require other structures. Use the structure appropriate to the address family; cast the structure address to a struct sockaddr* in the call to bind and pass the size of the structure in the namelen argument.

The sockaddr structure has been modified from previous releases to support variable length sockets. The net result of this modification is that the family member has been shortened to 8 bits and a new 8-bit member inserted before it called len. For more information on the new sockaddr structures, see: unix(ADMP) and inet(ADMP).


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005