1 BIND(3C) Standard C Library Functions BIND(3C) 2 3 NAME 4 bind - bind a name to a socket 5 6 LIBRARY 7 Standard C Library (libc, -lc) 8 9 SYNOPSIS 10 #include <sys/types.h> 11 #include <sys/socket.h> 12 13 int 14 bind(int s, const struct sockaddr *name, socklen_t namelen); 15 16 DESCRIPTION 17 The bind() function assigns a name to an unnamed socket. When a socket 18 is created with socket(3C), it exists in a name space (address family) 19 but has no name assigned. The bind() function requests that the name 20 pointed to by name be assigned to the socket. 21 22 RETURN VALUES 23 Upon successful completion 0 is returned. Otherwise, -1 is returned and 24 errno is set to indicate the error. 25 26 ERRORS 27 The bind() function will fail if: 28 29 [EACCES] The requested address is protected, and 30 [PRIV_NET_PRIVADDR] is not asserted in the effective 31 set of the current process. 32 33 [EADDRINUSE] The specified address is already in use. 34 35 [EADDRNOTAVAIL] The specified address is not available on the local 36 machine. 37 38 [EBADF] s is not a valid descriptor. 39 40 [EINVAL] namelen is not the size of a valid address for the 41 specified address family. 42 43 The socket is already bound to an address. 44 45 Socket options are inconsistent with port attributes. 46 47 [ENOSR] There were insufficient STREAMS resources for the 48 operation to complete. 49 50 [ENOTSOCK] s is a descriptor for a file, not a socket. 51 52 The following errors are specific to binding names in the UNIX domain: 53 54 [EACCES] Search permission is denied for a component of the 55 path prefix of the pathname in name. 56 57 [EIO] An I/O error occurred while making the directory entry 58 or allocating the inode. 59 60 [EISDIR] A null pathname was specified. 61 62 [ELOOP] Too many symbolic links were encountered in 63 translating the pathname in name. 64 65 [ENOENT] A component of the path prefix of the pathname in name 66 does not exist. 67 68 [ENOTDIR] A component of the path prefix of the pathname in name 69 is not a directory. 70 71 [EROFS] The inode would reside on a read-only file system. 72 73 MT-LEVEL 74 Safe 75 76 SEE ALSO 77 unlink(2), sockaddr(3C), socket(3C), socket.h(3HEAD), attributes(5), 78 privileges(5) 79 80 NOTES 81 Binding a name in the UNIX domain creates a socket in the file system 82 that must be deleted by the caller when it is no longer needed by using 83 unlink(2). 84 85 The rules used in name binding vary between communication domains. 86 87 illumos August 2, 2018 illumos