1bind(3XNET)      X/Open Networking Services Library Functions      bind(3XNET)
2
3
4

NAME

6       bind - bind a name to a socket
7

SYNOPSIS

9       cc [ flag ... ] file ... -lxnet [ library ... ]
10       #include <sys/socket.h>
11
12       int bind(int socket, const struct sockaddr *address,
13            socklen_t address_len);
14
15

DESCRIPTION

17       The  bind()  function assigns an address to an unnamed socket.  Sockets
18       created with socket(3XNET) function are  initially  unnamed.  They  are
19       identified only by their address family.
20
21
22       The function takes the following arguments:
23
24       socket         Specifies the file descriptor of the socket to be bound.
25
26
27       address        Points to a sockaddr structure containing the address to
28                      be bound to the socket.  The length and  format  of  the
29                      address depend on the address family of the socket.
30
31
32       address_len    Specifies  the  length of the sockaddr structure pointed
33                      to by the address argument.
34
35
36
37       The socket in use may require the process to  have  appropriate  privi‐
38       leges to use the bind() function.
39

USAGE

41       An  application  program can retrieve the assigned socket name with the
42       getsockname(3XNET) function.
43

RETURN VALUES

45       Upon  successful  completion,  bind()  returns  0.   Otherwise,  −1  is
46       returned and errno is set to indicate the error.
47

ERRORS

49       The bind() function will fail if:
50
51       EADDRINUSE       The specified address is already in use.
52
53
54       EADDRNOTAVAIL    The  specified address is not available from the local
55                        machine.
56
57
58       EAFNOSUPPORT     The specified address is not a valid address  for  the
59                        address family of the specified socket.
60
61
62       EBADF            The socket argument is not a valid file descriptor.
63
64
65       EFAULT           The  address argument can not be accessed.
66
67
68       EINVAL           The  socket  is  already  bound to an address, and the
69                        protocol does not support binding to a new address; or
70                        the socket has been shut down.
71
72
73       ENOTSOCK         The socket argument does not refer to a socket.
74
75
76       EOPNOTSUPP       The  socket type of the specified socket does not sup‐
77                        port binding to an address.
78
79
80
81       If the address family of the socket is AF_UNIX, then bind()  will  fail
82       if:
83
84       EACCES          A  component  of  the path prefix denies search permis‐
85                       sion, or the  requested  name  requires  writing  in  a
86                       directory with a mode that denies write permission.
87
88
89       EDESTADDRREQ    The address argument is a null pointer.
90       EISDIR
91
92       EIO             An I/O error occurred.
93
94
95       ELOOP           Too many symbolic links were encountered in translating
96                       the pathname in address.
97
98
99       ENAMETOOLONG    A component of a pathname exceeded NAME_MAX characters,
100                       or an entire pathname exceeded PATH_MAX characters.
101
102
103       ENOENT          A  component  of the pathname does not name an existing
104                       file or the pathname is an empty string.
105
106
107       ENOTDIR         A component of the  path  prefix  of  the  pathname  in
108                       address is not a directory.
109
110
111       EROFS           The name would reside on a read-only filesystem.
112
113
114
115       The bind() function may fail if:
116
117       EACCES          The  specified address is protected, and {PRIV_NET_PRI‐
118                       VADOR} is not asserted in the effective set of the cur‐
119                       rent process.
120
121
122       EINVAL          The  address_len argument is not a valid length for the
123                       address family.
124
125
126       EISCONN         The socket is already connected.
127
128
129       ENAMETOOLONG    Pathname resolution of  a  symbolic  link  produced  an
130                       intermediate result whose length exceeds PATH_MAX.
131
132
133       ENOBUFS         Insufficient  resources  were available to complete the
134                       call.
135
136
137       ENOSR           There were insufficient STREAMS resources for the oper‐
138                       ation to complete.
139
140

ATTRIBUTES

142       See attributes(5) for descriptions of the following attributes:
143
144
145
146
147       ┌─────────────────────────────┬─────────────────────────────┐
148       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
149       ├─────────────────────────────┼─────────────────────────────┤
150       │Interface Stability          │Standard                     │
151       ├─────────────────────────────┼─────────────────────────────┤
152       │MT-Level                     │MT-Safe                      │
153       └─────────────────────────────┴─────────────────────────────┘
154

SEE ALSO

156       connect(3XNET),   getsockname(3XNET),   listen(3XNET),   socket(3XNET),
157       attributes(5), privileges(5), standards(5)
158
159
160
161SunOS 5.11                        20 Feb 2003                      bind(3XNET)
Impressum