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