BSD 4_3_Tahoe release
[unix-history] / usr / src / man / man2 / 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.\"
95f51977 5.\" @(#)bind.2 6.6 (Berkeley) 5/22/86
1418f8f7 6.\"
95f51977 7.TH BIND 2 "May 22, 1986"
1418f8f7
KM
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
efd03614
AH
32requests that
33.IR name
1418f8f7
KM
34be assigned to the socket.
35.SH NOTES
36Binding a name in the UNIX domain creates a socket in the file
d84f45ef 37system that must be deleted by the caller when it is no longer
1418f8f7
KM
38needed (using
39.IR unlink (2)).
1418f8f7
KM
40.PP
41The rules used in name binding vary between communication domains.
42Consult the manual entries in section 4 for detailed information.
43.SH "RETURN VALUE
44If the bind is successful, a 0 value is returned.
45A return value of \-1 indicates an error, which is
46further specified in the global \fIerrno\fP.
47.SH ERRORS
48The \fIbind\fP call will fail if:
49.TP 20
50[EBADF]
51\fIS\fP is not a valid descriptor.
52.TP 20
53[ENOTSOCK]
54\fIS\fP is not a socket.
55.TP 20
56[EADDRNOTAVAIL]
57The specified address is not available from the local machine.
58.TP 20
59[EADDRINUSE]
60The specified address is already in use.
61.TP 20
62[EINVAL]
63The socket is already bound to an address.
64.TP 20
435c3f78 65[EACCES]
1418f8f7
KM
66The requested address is protected, and the current user
67has inadequate permission to access it.
68.TP 20
69[EFAULT]
70The \fIname\fP parameter is not in a valid part of the user
71address space.
b5984ffe
KM
72.PP
73The following errors are specific to binding names in the UNIX domain.
b5984ffe
KM
74.TP 15
75[ENOTDIR]
76A component of the path prefix is not a directory.
77.TP 15
78[EINVAL]
79The pathname contains a character with the high-order bit set.
80.TP 15
81[ENAMETOOLONG]
82A component of a pathname exceeded 255 characters,
83or an entire path name exceeded 1023 characters.
84.TP 15
85[ENOENT]
86A prefix component of the path name does not exist.
87.TP 15
88[ELOOP]
89Too many symbolic links were encountered in translating the pathname.
90.TP 15
91[EIO]
92An I/O error occurred while making the directory entry or allocating the inode.
93.TP 15
94[EROFS]
95The name would reside on a read-only file system.
96.TP 15
97[EISDIR]
98A null pathname was specified.
1418f8f7
KM
99.SH SEE ALSO
100connect(2), listen(2), socket(2), getsockname(2)