COHERENT manpages

This page displays the COHERENT manpage for bind() [Bind a name to a socket].

List of available manpages
Index


bind() -- Sockets Function (libsocket)

Bind a name to a socket
#include <sys/types.h>
#include <sys/socket.h>
int bind (socket, name, namelen)
int socket, namelen; struct sockaddr *name;

Function bind() binds a name to an unnamed socket.

When  function socket()  creates a  socket, that socket  exists but  has no
name.  bind()  creates a special  file, assigns it  a name, and  binds that
file to  a socket.  Thereafter,  the socket can  be accessed by  reading or
writing the file.

socket is  a file  descriptor that identifies  the socket in  question.  It
must have been returned by a call to socket(). name points to the full path
name of the file to which  socket is to be bound.  The calling process must
unlink name when it no longer  needs it.  namelen gives the number of bytes
in the path name name to  which name points.  Under COHERENT, no element of
name can exceed 14 characters (not including separating `/' characters).

If all  goes well,  bind() returns zero.   If something goes  wrong, bind()
returns -1 and sets errno to an appropriate value.  The following lists the
errors that can occur, by the value to which bind() sets errno:

EBADF
     socket is somehow not a valid descriptor.

ENOTSOCK
     socket is not a socket.

EADDRNOTAVAIL
     name is not available from the local machine.

EADDRINUSE
     name is already bound to another socket.

EINVAL
     socket is already bound to a name.

EACCES
     The  memory to  which  name points  is  protected and  the user  lacks
     permission to access it.

EFAULT
     name points to an illegal address.

ENOTDIR
     The path name  to which name points contains an  element that is not a
     directory.

EINVAL
     The path name to which name points contains a character with the high-
     order bit set.

ENOENT
     A prefix component of the path name does not exist.

EIO  An I/O  error occurred while creating the directory  entry for name or
     allocating its inode.

EROFS
     name would reside on a read-only file system.

EISDIR
     name points to an empty path name.

Example

For an example of this function, see the Lexicon entry for libsocket.

See Also

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