File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / usr / src / man / man2 / bind.2
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:26:26 2019 UTC (7 years ago) by root
Branches: bsd, MAIN
CVS tags: v121, HEAD
Power 6/32 Unix version 1.21

.TH BIND 2 "27 July 1983"
.UC 4
.SH NAME
bind \- bind a name to a socket
.SH SYNOPSIS
.nf
.ft B
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>                /* for Unix domain only */
#include <netinet/in.h>            /* for Internet domain only */
.PP
.ft B
bind(s, name, namelen)
int s;
struct sockaddr *name;
int namelen;
.fi
.SH DESCRIPTION
.I Bind
assigns a name to an unnamed socket.
After being created by the
.IR socket (2)
system call, a socket
exists in a name space (address family)
but has no name assigned.
.I Bind
requests the
.IR name
be assigned to the socket.
Since the system call is applicable to various communication domains,
the address formats varies. 
.PP
.I BINDING NAMES TO SOCKETS IN UNIX DOMAIN
.PP
The system creates a file of socket type in the file system
when binding name to a socket. This file must not have existed and
and must be deleted by the caller when it is no longer
needed (using
.IR unlink (2)).
The file created
is a side-effect of the current implementation,
and is not created in future versions
of the UNIX ipc domain.
.PP
The argument
.I name
points to the following structure in the file <sys/un.h>:

.RS
.nf
struct sockaddr_un {
       short   sun_family;
       char    sun_path[109];
};
.fi
.RE

.I Sun_family
is set with AF_UNIX, and 
.I sun_path
is set with the socket name. The name is null terminated if it is
less than 109 characters.
.I Namelen
argument must be at most 111 characters.

.I Notes

The Tahoe C-compiler operator
.I sizeof(struct sockaddr_un)
returns 112 (instead of 111!) since it always pads all C-structures
to make them multiple of long words. As a result, application programmers
must specify "sizeof(struct sockaddr_un) -1" as the value of the
.I namelen
argument when binding in the Unix domain.
.PP
.I BINDING NAMES TO SOCKETS IN INTERNET DOMAIN
.PP
The argument
.I namelen
must be at most 112.
The argument
.I name
points to the following structure in the file <inet/in.h>:

.RS
.nf
struct sockaddr_in {
       short    sin_family;
       u_short  sin_port;
       struct   in_addr   sin_addr;
       char     sin_zero[8];
};

.fi
.RE
The field 
.I sin_port
must be in Internet byte order.
If the field
.I sin_addr
is left unspecified  (NULL value), the system will assign a default
address. If the process reads or writes through a socket without
binding first, the system will assign that socket a default name.
.SH "RETURN VALUE
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 \fIerrno\fP.
.SH ERRORS
The \fIbind\fP call fails if:
.TP 20
[EBADF]
\fIS\fP is not a valid descriptor.
.TP 20
[ENOTSOCK]
\fIS\fP is not a socket.
.TP 20
[EADDRNOTAVAIL]
The specified address is not available from the local machine.
.TP 20
[EADDRINUSE]
The specified address is already in use.
.TP 20
[EINVAL]
The socket is already bound to an address.
.TP 20
[EACCESS]
The requested address is protected, and the current user
has inadequate permission to access it.
.TP 20
[EFAULT]
The \fIname\fP parameter is not in a valid part of the user
address space.
.SH SEE ALSO
connect(2), listen(2), socket(2), getsockname(2).
The rules used in name binding vary between communication domains.
Consult the manual entries in section 4 for detailed information.

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.