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