1bind(3SOCKET) Sockets Library Functions bind(3SOCKET)
2
3
4
6 bind - bind a name to a socket
7
9 cc [ flag ... ] file ... -lsocket -lnsl [ library ... ]
10 #include <sys/types.h>
11 #include <sys/socket.h>
12
13
14
15 int bind(int s, const struct sockaddr *name, int namelen);
16
17
19 The bind() function assigns a name to an unnamed socket. When a socket
20 is created with socket(3SOCKET), it exists in a name space (address
21 family) but has no name assigned. The bind() function requests that the
22 name pointed to by name be assigned to the socket.
23
25 Upon successful completion 0 is returned. Otherwise, −1 is returned and
26 errno is set to indicate the error.
27
29 The bind() function will fail if:
30
31 EACCES The requested address is protected, and {PRIV_NET_PRI‐
32 VADDR} is not asserted in the effective set of the
33 current process.
34
35
36 EADDRINUSE The specified address is already in use.
37
38
39 EADDRNOTAVAIL The specified address is not available on the local
40 machine.
41
42
43 EBADF s is not a valid descriptor.
44
45
46 EINVAL namelen is not the size of a valid address for the
47 specified address family.
48
49 The socket is already bound to an address.
50
51 Socket options are inconsistent with port attributes.
52
53
54 ENOSR There were insufficient STREAMS resources for the
55 operation to complete.
56
57
58 ENOTSOCK s is a descriptor for a file, not a socket.
59
60
61
62 The following errors are specific to binding names in the UNIX domain:
63
64 EACCES Search permission is denied for a component of the path pre‐
65 fix of the pathname in name.
66
67
68 EIO An I/O error occurred while making the directory entry or
69 allocating the inode.
70
71
72 EISDIR A null pathname was specified.
73
74
75 ELOOP Too many symbolic links were encountered in translating the
76 pathname in name.
77
78
79 ENOENT A component of the path prefix of the pathname in name does
80 not exist.
81
82
83 ENOTDIR A component of the path prefix of the pathname in name is
84 not a directory.
85
86
87 EROFS The inode would reside on a read-only file system.
88
89
91 See attributes(5) for descriptions of the following attributes:
92
93
94
95
96 ┌─────────────────────────────┬─────────────────────────────┐
97 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
98 ├─────────────────────────────┼─────────────────────────────┤
99 │MT-Level │Safe │
100 └─────────────────────────────┴─────────────────────────────┘
101
103 unlink(2), socket(3SOCKET), attributes(5), privileges(5),
104 socket.h(3HEAD)
105
107 Binding a name in the UNIX domain creates a socket in the file system
108 that must be deleted by the caller when it is no longer needed by using
109 unlink(2).
110
111
112 The rules used in name binding vary between communication domains.
113
114
115
116SunOS 5.11 11 May 2009 bind(3SOCKET)