1 |
27 |
unneback |
.\" $OpenBSD: bind.2,v 1.10 2000/10/18 05:12:08 aaron Exp $
|
2 |
|
|
.\" $NetBSD: bind.2,v 1.8 1995/10/12 15:40:46 jtc Exp $
|
3 |
|
|
.\"
|
4 |
|
|
.\" Copyright (c) 1983, 1993
|
5 |
|
|
.\" The Regents of the University of California. All rights reserved.
|
6 |
|
|
.\"
|
7 |
|
|
.\" Redistribution and use in source and binary forms, with or without
|
8 |
|
|
.\" modification, are permitted provided that the following conditions
|
9 |
|
|
.\" are met:
|
10 |
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
11 |
|
|
.\" notice, this list of conditions and the following disclaimer.
|
12 |
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
13 |
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
14 |
|
|
.\" documentation and/or other materials provided with the distribution.
|
15 |
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
16 |
|
|
.\" must display the following acknowledgement:
|
17 |
|
|
.\" This product includes software developed by the University of
|
18 |
|
|
.\" California, Berkeley and its contributors.
|
19 |
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
20 |
|
|
.\" may be used to endorse or promote products derived from this software
|
21 |
|
|
.\" without specific prior written permission.
|
22 |
|
|
.\"
|
23 |
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
24 |
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25 |
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26 |
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
27 |
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28 |
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
29 |
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30 |
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
31 |
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
32 |
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
33 |
|
|
.\" SUCH DAMAGE.
|
34 |
|
|
.\"
|
35 |
|
|
.\" @(#)bind.2 8.1 (Berkeley) 6/4/93
|
36 |
|
|
.\"
|
37 |
|
|
.Dd February 15, 1999
|
38 |
|
|
.Dt BIND 2
|
39 |
|
|
.Os
|
40 |
|
|
.Sh NAME
|
41 |
|
|
.Nm bind
|
42 |
|
|
.Nd bind a name to a socket
|
43 |
|
|
.Sh SYNOPSIS
|
44 |
|
|
.Fd #include
|
45 |
|
|
.Fd #include
|
46 |
|
|
.Ft int
|
47 |
|
|
.Fn bind "int s" "const struct sockaddr *name" "socklen_t namelen"
|
48 |
|
|
.Sh DESCRIPTION
|
49 |
|
|
.Fn bind
|
50 |
|
|
assigns a name to an unnamed socket.
|
51 |
|
|
When a socket is created with
|
52 |
|
|
.Xr socket 2
|
53 |
|
|
it exists in a name space (address family) but has no name assigned.
|
54 |
|
|
.Fn bind
|
55 |
|
|
requests that
|
56 |
|
|
.Fa name
|
57 |
|
|
be assigned to the socket.
|
58 |
|
|
.Sh NOTES
|
59 |
|
|
Binding a name in the UNIX domain creates a socket in the file
|
60 |
|
|
system that must be deleted by the caller when it is no longer
|
61 |
|
|
needed (using
|
62 |
|
|
.Xr unlink 2 ) .
|
63 |
|
|
.Pp
|
64 |
|
|
The rules used in name binding vary between communication domains.
|
65 |
|
|
Consult the manual entries in section 4 for detailed information.
|
66 |
|
|
.Sh RETURN VALUES
|
67 |
|
|
If the bind is successful, a 0 value is returned.
|
68 |
|
|
A return value of \-1 indicates an error, which is
|
69 |
|
|
further specified in the global
|
70 |
|
|
.Va errno .
|
71 |
|
|
.Sh ERRORS
|
72 |
|
|
The
|
73 |
|
|
.Fn bind
|
74 |
|
|
call will fail if:
|
75 |
|
|
.Bl -tag -width Er
|
76 |
|
|
.It Bq Er EBADF
|
77 |
|
|
.Fa S
|
78 |
|
|
is not a valid descriptor.
|
79 |
|
|
.It Bq Er ENOTSOCK
|
80 |
|
|
.Fa S
|
81 |
|
|
is not a socket.
|
82 |
|
|
.It Bq Er EADDRNOTAVAIL
|
83 |
|
|
The specified address is not available from the local machine.
|
84 |
|
|
.It Bq Er EADDRINUSE
|
85 |
|
|
The specified address is already in use.
|
86 |
|
|
.It Bq Er EINVAL
|
87 |
|
|
The socket is already bound to an address.
|
88 |
|
|
.It Bq Er EINVAL
|
89 |
|
|
The family of the socket and that requested in
|
90 |
|
|
.Va name->sa_family
|
91 |
|
|
are not equivalent.
|
92 |
|
|
.It Bq Er EACCES
|
93 |
|
|
The requested address is protected, and the current user
|
94 |
|
|
has inadequate permission to access it.
|
95 |
|
|
.It Bq Er EFAULT
|
96 |
|
|
The
|
97 |
|
|
.Fa name
|
98 |
|
|
parameter is not in a valid part of the user address space.
|
99 |
|
|
.El
|
100 |
|
|
.Pp
|
101 |
|
|
The following errors are specific to binding names in the UNIX domain.
|
102 |
|
|
.Bl -tag -width Er
|
103 |
|
|
.It Bq Er ENOTDIR
|
104 |
|
|
A component of the path prefix is not a directory.
|
105 |
|
|
.It Bq Er ENAMETOOLONG
|
106 |
|
|
A component of a pathname exceeded
|
107 |
|
|
.Dv {NAME_MAX}
|
108 |
|
|
characters, or an entire path name exceeded
|
109 |
|
|
.Dv {PATH_MAX}
|
110 |
|
|
characters.
|
111 |
|
|
.It Bq Er ENOENT
|
112 |
|
|
A prefix component of the path name does not exist.
|
113 |
|
|
.It Bq Er ELOOP
|
114 |
|
|
Too many symbolic links were encountered in translating the pathname.
|
115 |
|
|
.It Bq Er EIO
|
116 |
|
|
An I/O error occurred while making the directory entry or allocating the inode.
|
117 |
|
|
.It Bq Er EROFS
|
118 |
|
|
The name would reside on a read-only file system.
|
119 |
|
|
.It Bq Er EISDIR
|
120 |
|
|
An empty pathname was specified.
|
121 |
|
|
.El
|
122 |
|
|
.Sh SEE ALSO
|
123 |
|
|
.Xr connect 2 ,
|
124 |
|
|
.Xr getsockname 2 ,
|
125 |
|
|
.Xr listen 2 ,
|
126 |
|
|
.Xr socket 2
|
127 |
|
|
.Sh HISTORY
|
128 |
|
|
The
|
129 |
|
|
.Fn bind
|
130 |
|
|
function call appeared in
|
131 |
|
|
.Bx 4.2 .
|