1 .\" 2 .\" The contents of this file are subject to the terms of the 3 .\" Common Development and Distribution License (the "License"). 4 .\" You may not use this file except in compliance with the License. 5 .\" 6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 7 .\" or http://www.opensolaris.org/os/licensing. 8 .\" See the License for the specific language governing permissions 9 .\" and limitations under the License. 10 .\" 11 .\" When distributing Covered Code, include this CDDL HEADER in each 12 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. 13 .\" If applicable, add the following below this CDDL HEADER, with the 14 .\" fields enclosed by brackets "[]" replaced with your own identifying 15 .\" information: Portions Copyright [yyyy] [name of copyright owner] 16 .\" 17 .\" 18 .\" Copyright 1989 AT&T 19 .\" Copyright (C) 2009, Sun Microsystems, Inc. All Rights Reserved 20 .\" Copyright 2018 Nexenta Systems, Inc. 21 .\" 22 .Dd August 2, 2018 23 .Dt BIND 3C 24 .Os 25 .Sh NAME 26 .Nm bind 27 .Nd bind a name to a socket 28 .Sh LIBRARY 29 .Lb libc 30 .Sh SYNOPSIS 31 .In sys/types.h 32 .In sys/socket.h 33 .Ft int 34 .Fo bind 35 .Fa "int s" 36 .Fa "const struct sockaddr *name" 37 .Fa "socklen_t namelen" 38 .Fc 39 .Sh DESCRIPTION 40 The 41 .Fn bind 42 function assigns a name to an unnamed socket. 43 When a socket is created with 44 .Xr socket 3C , 45 it exists in a name space (address family) but has no name assigned. 46 The 47 .Fn bind 48 function requests that the name pointed to by 49 .Fa name 50 be assigned to the socket. 51 .Sh RETURN VALUES 52 Upon successful completion 0 is returned. 53 Otherwise, -1 54 is returned and 55 .Va errno 56 is set to indicate the error. 57 .Sh ERRORS 58 The 59 .Fn bind 60 function will fail if: 61 .Bl -tag -width Er 62 .It Bq Er EACCES 63 The requested address is protected, and 64 .Bq Dv PRIV_NET_PRIVADDR 65 is not asserted in the effective set of the current process. 66 .It Bq Er EADDRINUSE 67 The specified address is already in use. 68 .It Bq Er EADDRNOTAVAIL 69 The specified address is not available on the local machine. 70 .It Bq Er EBADF 71 .Fa s 72 is not a valid descriptor. 73 .It Bq Er EINVAL 74 .Fa namelen 75 is not the size of a valid address for the specified address family. 76 .Pp 77 The socket is already bound to an address. 78 .Pp 79 Socket options are inconsistent with port attributes. 80 .It Bq Er ENOSR 81 There were insufficient STREAMS resources for the operation to complete. 82 .It Bq Er ENOTSOCK 83 .Fa s 84 is a descriptor for a file, not a socket. 85 .El 86 .Pp 87 The following errors are specific to binding names in the UNIX domain: 88 .Bl -tag -width Er 89 .It Bq Er EACCES 90 Search permission is denied for a component of the path prefix of the pathname 91 in 92 .Fa name . 93 .It Bq Er EIO 94 An I/O error occurred while making the directory entry or allocating the inode. 95 .It Bq Er EISDIR 96 A null pathname was specified. 97 .It Bq Er ELOOP 98 Too many symbolic links were encountered in translating the pathname in 99 .Fa name . 100 .It Bq Er ENOENT 101 A component of the path prefix of the pathname in 102 .Fa name 103 does not exist. 104 .It Bq Er ENOTDIR 105 A component of the path prefix of the pathname in 106 .Fa name 107 is not a directory. 108 .It Bq Er EROFS 109 The inode would reside on a read-only file system. 110 .El 111 .Sh MT-LEVEL 112 .Sy Safe 113 .Sh SEE ALSO 114 .Xr unlink 2 , 115 .Xr sockaddr 3C , 116 .Xr socket 3C , 117 .Xr socket.h 3HEAD , 118 .Xr attributes 5 , 119 .Xr privileges 5 120 .Sh NOTES 121 Binding a name in the UNIX domain creates a socket in the file system that must 122 be deleted by the caller when it is no longer needed by using 123 .Xr unlink 2 . 124 .Pp 125 The rules used in name binding vary between communication domains.