]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/bind.2
libc: Fix most issues reported by mandoc
[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. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)bind.2      8.1 (Berkeley) 6/4/93
29 .\" $FreeBSD$
30 .\"
31 .Dd March 30, 2020
32 .Dt BIND 2
33 .Os
34 .Sh NAME
35 .Nm bind
36 .Nd assign a local protocol address to a socket
37 .Sh LIBRARY
38 .Lb libc
39 .Sh SYNOPSIS
40 .In sys/socket.h
41 .Ft int
42 .Fn bind "int s" "const struct sockaddr *addr" "socklen_t addrlen"
43 .Sh DESCRIPTION
44 The
45 .Fn bind
46 system call
47 assigns the local protocol address to a socket.
48 When a socket is created
49 with
50 .Xr socket 2
51 it exists in an address family space but has no protocol address assigned.
52 The
53 .Fn bind
54 system call requests that
55 .Fa addr
56 be assigned to the socket.
57 .Sh NOTES
58 Binding an address in the UNIX domain creates a socket in the file
59 system that must be deleted by the caller when it is no longer
60 needed (using
61 .Xr unlink 2 ) .
62 .Pp
63 The rules used in address binding vary between communication domains.
64 Consult the manual entries in section 4 for detailed information.
65 .Pp
66 For maximum portability, you should always zero the socket address structure
67 before populating it and passing it to
68 .Fn bind .
69 .Sh RETURN VALUES
70 .Rv -std bind
71 .Sh ERRORS
72 The
73 .Fn bind
74 system call will fail if:
75 .Bl -tag -width Er
76 .It Bq Er EAGAIN
77 Kernel resources to complete the request are
78 temporarily unavailable.
79 .It Bq Er EBADF
80 The
81 .Fa s
82 argument
83 is not a valid descriptor.
84 .It Bq Er EINVAL
85 The socket is already bound to an address, and the protocol does not support
86 binding to a new address; or the socket has been shut down.
87 .It Bq Er EINVAL
88 The
89 .Fa addrlen
90 argument is not a valid length for the address family.
91 .It Bq Er ENOTSOCK
92 The
93 .Fa s
94 argument
95 is not a socket.
96 .It Bq Er EADDRNOTAVAIL
97 The specified address is not available from the local machine.
98 .It Bq Er EADDRINUSE
99 The specified address is already in use.
100 .It Bq Er EAFNOSUPPORT
101 Addresses in the specified address family cannot be used with this socket.
102 .It Bq Er EACCES
103 The requested address is protected, and the current user
104 has inadequate permission to access it.
105 .It Bq Er EFAULT
106 The
107 .Fa addr
108 argument is not in a valid part of the user
109 address space.
110 .El
111 .Pp
112 The following errors are specific to binding addresses in the UNIX domain.
113 .Bl -tag -width EADDRNOTAVA
114 .It Bq Er ENOTDIR
115 A component of the path prefix is not a directory.
116 .It Bq Er ENAMETOOLONG
117 A component of a pathname exceeded 255 characters,
118 or an entire path name exceeded 1023 characters.
119 .It Bq Er ENOENT
120 A prefix component of the path name does not exist.
121 .It Bq Er ELOOP
122 Too many symbolic links were encountered in translating the pathname.
123 .It Bq Er EIO
124 An I/O error occurred while making the directory entry or allocating the inode.
125 .It Bq Er EINTEGRITY
126 Corrupted data was detected while reading from the file system.
127 .It Bq Er EROFS
128 The name would reside on a read-only file system.
129 .It Bq Er EISDIR
130 An empty pathname was specified.
131 .El
132 .Sh SEE ALSO
133 .Xr connect 2 ,
134 .Xr getsockname 2 ,
135 .Xr listen 2 ,
136 .Xr socket 2
137 .Sh HISTORY
138 The
139 .Fn bind
140 system call appeared in
141 .Bx 4.2 .