1.\" Copyright (c) 1983 The Regents of the University of California. 2.\" 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.\" from: @(#)bind.2 6.9 (Berkeley) 3/10/91 33.\" $Id: bind.2,v 1.6 1994/04/22 00:13:25 jtc Exp $ 34.\" 35.Dd March 10, 1991 36.Dt BIND 2 37.Os BSD 4.2 38.Sh NAME 39.Nm bind 40.Nd bind a name to a socket 41.Sh SYNOPSIS 42.Fd #include <sys/types.h> 43.Fd #include <sys/socket.h> 44.Ft int 45.Fn bind "int s" "struct sockaddr *name" "int namelen" 46.Sh DESCRIPTION 47.Fn Bind 48assigns a name to an unnamed socket. 49When a socket is created 50with 51.Xr socket 2 52it exists in a name space (address family) 53but has no name assigned. 54.Fn Bind 55requests that 56.Fa name 57be assigned to the socket. 58.Sh NOTES 59Binding a name in the UNIX domain 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 name binding vary between communication domains. 65Consult the manual entries in section 4 for detailed information. 66.Sh RETURN VALUES 67If the bind is successful, a 0 value is returned. 68A return value of -1 indicates an error, which is 69further specified in the global 70.Va errno . 71.Sh ERRORS 72The 73.Fn bind 74call will fail if: 75.Bl -tag -width Er 76.It Bq Er EBADF 77.Fa S 78is not a valid descriptor. 79.It Bq Er ENOTSOCK 80.Fa S 81is not a socket. 82.It Bq Er EADDRNOTAVAIL 83The specified address is not available from the local machine. 84.It Bq Er EADDRINUSE 85The specified address is already in use. 86.It Bq Er EINVAL 87The socket is already bound to an address. 88.It Bq Er EACCES 89The requested address is protected, and the current user 90has inadequate permission to access it. 91.It Bq Er EFAULT 92The 93.Fa name 94parameter is not in a valid part of the user 95address space. 96.El 97.Pp 98The following errors are specific to binding names in the UNIX domain. 99.Bl -tag -width Er 100.It Bq Er ENOTDIR 101A component of the path prefix is not a directory. 102.It Bq Er ENAMETOOLONG 103A component of a pathname exceeded 104.Dv {NAME_MAX} 105characters, or an entire path name exceeded 106.Dv {PATH_MAX} 107characters. 108.It Bq Er ENOENT 109A prefix component of the path name does not exist. 110.It Bq Er ELOOP 111Too many symbolic links were encountered in translating the pathname. 112.It Bq Er EIO 113An I/O error occurred while making the directory entry or allocating the inode. 114.It Bq Er EROFS 115The name would reside on a read-only file system. 116.It Bq Er EISDIR 117An empty pathname was specified. 118.El 119.Sh SEE ALSO 120.Xr connect 2 , 121.Xr listen 2 , 122.Xr socket 2 , 123.Xr getsockname 2 124.Sh HISTORY 125The 126.Fn bind 127function call appeared in 128.Bx 4.2 . 129