manual page first distributed with 4.2BSD
[unix-history] / usr / src / lib / libc / sys / bind.2
CommitLineData
1418f8f7
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5.\" @(#)bind.2 5.1 (Berkeley) %G%
6.\"
7.TH BIND 2 "27 July 1983"
8.UC 5
9.SH NAME
10bind \- bind a name to a socket
11.SH SYNOPSIS
12.nf
13.ft B
14#include <sys/types.h>
15#include <sys/socket.h>
16.PP
17.ft B
18bind(s, name, namelen)
19int s;
20struct sockaddr *name;
21int namelen;
22.fi
23.SH DESCRIPTION
24.I Bind
25assigns a name to an unnamed socket.
26When a socket is created
27with
28.IR socket (2)
29it exists in a name space (address family)
30but has no name assigned.
31.I Bind
32requests the
33.IR name ,
34be assigned to the socket.
35.SH NOTES
36Binding a name in the UNIX domain creates a socket in the file
37system which must be deleted by the caller when it is no longer
38needed (using
39.IR unlink (2)).
40The file created
41is a side-effect of the current implementation,
42and will not be created in future versions
43of the UNIX ipc domain.
44.PP
45The rules used in name binding vary between communication domains.
46Consult the manual entries in section 4 for detailed information.
47.SH "RETURN VALUE
48If the bind is successful, a 0 value is returned.
49A return value of \-1 indicates an error, which is
50further specified in the global \fIerrno\fP.
51.SH ERRORS
52The \fIbind\fP call will fail if:
53.TP 20
54[EBADF]
55\fIS\fP is not a valid descriptor.
56.TP 20
57[ENOTSOCK]
58\fIS\fP is not a socket.
59.TP 20
60[EADDRNOTAVAIL]
61The specified address is not available from the local machine.
62.TP 20
63[EADDRINUSE]
64The specified address is already in use.
65.TP 20
66[EINVAL]
67The socket is already bound to an address.
68.TP 20
69[EACCESS]
70The requested address is protected, and the current user
71has inadequate permission to access it.
72.TP 20
73[EFAULT]
74The \fIname\fP parameter is not in a valid part of the user
75address space.
76.SH SEE ALSO
77connect(2), listen(2), socket(2), getsockname(2)