xref: /dragonfly/lib/libc/sys/bind.2 (revision 6b5c5d0d)
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: src/lib/libc/sys/bind.2,v 1.11.2.9 2002/07/08 13:07:42 dannyboy Exp $
34.\" $DragonFly: src/lib/libc/sys/bind.2,v 1.3 2007/07/30 22:11:33 swildner Exp $
35.\"
36.Dd June 4, 1993
37.Dt BIND 2
38.Os
39.Sh NAME
40.Nm bind
41.Nd assign a local protocol address to a socket
42.Sh LIBRARY
43.Lb libc
44.Sh SYNOPSIS
45.In sys/types.h
46.In sys/socket.h
47.Ft int
48.Fn bind "int s" "const struct sockaddr *addr" "socklen_t addrlen"
49.Sh DESCRIPTION
50.Fn Bind
51assigns the local protocol address to a socket.
52When a socket is created
53with
54.Xr socket 2
55it exists in an address family space but has no protocol address assigned.
56.Fn Bind
57requests that
58.Fa addr
59be assigned to the socket.
60.Sh NOTES
61Binding an address in the
62.Ux
63domain creates a socket in the file
64system that must be deleted by the caller when it is no longer
65needed (using
66.Xr unlink 2 ) .
67.Pp
68The rules used in address binding vary between communication domains.
69Consult the manual entries in section 4 for detailed information.
70.Pp
71For maximum portability, you should always zero the socket address structure
72before populating it and passing it to
73.Fn bind .
74.Sh RETURN VALUES
75.Rv -std bind
76.Sh ERRORS
77The
78.Fn bind
79call will fail if:
80.Bl -tag -width Er
81.It Bq Er EAGAIN
82Kernel resources to complete the request are
83temporarily unavailable.
84.It Bq Er EBADF
85.Fa S
86is not a valid descriptor.
87.It Bq Er ENOTSOCK
88.Fa S
89is not a socket.
90.It Bq Er EADDRNOTAVAIL
91The specified address is not available from the local machine.
92.It Bq Er EADDRINUSE
93The specified address is already in use.
94.It Bq Er EACCES
95The requested address is protected, and the current user
96has inadequate permission to access it.
97.It Bq Er EFAULT
98The
99.Fa addr
100parameter is not in a valid part of the user
101address space.
102.El
103.Pp
104The following errors are specific to binding addresses in the
105.Ux
106domain.
107.Bl -tag -width EADDRNOTAVA
108.It Bq Er ENOTDIR
109A component of the path prefix is not a directory.
110.It Bq Er ENAMETOOLONG
111A component of a pathname exceeded 255 characters,
112or an entire path name exceeded 1023 characters.
113.It Bq Er ENOENT
114A prefix component of the path name does not exist.
115.It Bq Er ELOOP
116Too many symbolic links were encountered in translating the pathname.
117.It Bq Er EIO
118An I/O error occurred while making the directory entry or allocating the inode.
119.It Bq Er EROFS
120The name would reside on a read-only file system.
121.It Bq Er EISDIR
122An empty pathname was specified.
123.El
124.Sh SEE ALSO
125.Xr connect 2 ,
126.Xr getsockname 2 ,
127.Xr listen 2 ,
128.Xr socket 2
129.Sh HISTORY
130The
131.Fn bind
132function call appeared in
133.Bx 4.2 .
134