]>
Commit | Line | Data |
---|---|---|
07a4742f | 1 | /* Declarations of socket constants, types, and functions. |
d4697bc9 | 2 | Copyright (C) 1991-2014 Free Software Foundation, Inc. |
54d79e99 UD |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
54d79e99 UD |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
54d79e99 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
0e3426bb RM |
18 | |
19 | #ifndef _SYS_SOCKET_H | |
0e3426bb | 20 | #define _SYS_SOCKET_H 1 |
5107cf1d | 21 | |
0e3426bb RM |
22 | #include <features.h> |
23 | ||
24 | __BEGIN_DECLS | |
25 | ||
6f0ea379 | 26 | #include <sys/uio.h> |
0e3426bb RM |
27 | #define __need_size_t |
28 | #include <stddef.h> | |
bdcebfc4 UD |
29 | #ifdef __USE_GNU |
30 | /* Get the __sigset_t definition. */ | |
31 | # include <bits/sigset.h> | |
32 | #endif | |
0e3426bb RM |
33 | |
34 | ||
07a4742f RM |
35 | /* This operating system-specific header file defines the SOCK_*, PF_*, |
36 | AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr', | |
37 | `struct msghdr', and `struct linger' types. */ | |
5107cf1d | 38 | #include <bits/socket.h> |
07a4742f | 39 | |
498afc54 | 40 | #ifdef __USE_MISC |
2064087b RM |
41 | /* This is the 4.3 BSD `struct sockaddr' format, which is used as wire |
42 | format in the grotty old 4.3 `talk' protocol. */ | |
43 | struct osockaddr | |
44 | { | |
45 | unsigned short int sa_family; | |
46 | unsigned char sa_data[14]; | |
47 | }; | |
48 | #endif | |
0e3426bb | 49 | |
3ee12f2b UD |
50 | /* The following constants should be used for the second parameter of |
51 | `shutdown'. */ | |
52 | enum | |
53 | { | |
54 | SHUT_RD = 0, /* No more receptions. */ | |
55 | #define SHUT_RD SHUT_RD | |
56 | SHUT_WR, /* No more transmissions. */ | |
57 | #define SHUT_WR SHUT_WR | |
58 | SHUT_RDWR /* No more receptions or transmissions. */ | |
59 | #define SHUT_RDWR SHUT_RDWR | |
60 | }; | |
61 | ||
0e3426bb RM |
62 | /* This is the type we use for generic socket address arguments. |
63 | ||
a3e59be8 UD |
64 | With GCC 2.7 and later, the funky union causes redeclarations or |
65 | uses with any of the listed types to be allowed without complaint. | |
66 | G++ 2.7 does not support transparent unions so there we want the | |
67 | old-style declaration, too. */ | |
6f0ea379 | 68 | #if defined __cplusplus || !__GNUC_PREREQ (2, 7) || !defined __USE_GNU |
98cbe360 | 69 | # define __SOCKADDR_ARG struct sockaddr *__restrict |
a784e502 | 70 | # define __CONST_SOCKADDR_ARG const struct sockaddr * |
0e3426bb RM |
71 | #else |
72 | /* Add more `struct sockaddr_AF' types here as necessary. | |
73 | These are all the ones I found on NetBSD and Linux. */ | |
55c14926 | 74 | # define __SOCKADDR_ALLTYPES \ |
0e3426bb RM |
75 | __SOCKADDR_ONETYPE (sockaddr) \ |
76 | __SOCKADDR_ONETYPE (sockaddr_at) \ | |
77 | __SOCKADDR_ONETYPE (sockaddr_ax25) \ | |
78 | __SOCKADDR_ONETYPE (sockaddr_dl) \ | |
79 | __SOCKADDR_ONETYPE (sockaddr_eon) \ | |
80 | __SOCKADDR_ONETYPE (sockaddr_in) \ | |
81 | __SOCKADDR_ONETYPE (sockaddr_in6) \ | |
82 | __SOCKADDR_ONETYPE (sockaddr_inarp) \ | |
83 | __SOCKADDR_ONETYPE (sockaddr_ipx) \ | |
84 | __SOCKADDR_ONETYPE (sockaddr_iso) \ | |
85 | __SOCKADDR_ONETYPE (sockaddr_ns) \ | |
86 | __SOCKADDR_ONETYPE (sockaddr_un) \ | |
87 | __SOCKADDR_ONETYPE (sockaddr_x25) | |
88 | ||
98cbe360 | 89 | # define __SOCKADDR_ONETYPE(type) struct type *__restrict __##type##__; |
0e3426bb RM |
90 | typedef union { __SOCKADDR_ALLTYPES |
91 | } __SOCKADDR_ARG __attribute__ ((__transparent_union__)); | |
55c14926 | 92 | # undef __SOCKADDR_ONETYPE |
a784e502 | 93 | # define __SOCKADDR_ONETYPE(type) const struct type *__restrict __##type##__; |
0e3426bb RM |
94 | typedef union { __SOCKADDR_ALLTYPES |
95 | } __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__)); | |
55c14926 | 96 | # undef __SOCKADDR_ONETYPE |
0e3426bb RM |
97 | #endif |
98 | ||
123be9de TS |
99 | #ifdef __USE_GNU |
100 | /* For `recvmmsg' and `sendmmsg'. */ | |
101 | struct mmsghdr | |
102 | { | |
103 | struct msghdr msg_hdr; /* Actual message header. */ | |
104 | unsigned int msg_len; /* Number of received or sent bytes for the | |
105 | entry. */ | |
106 | }; | |
107 | #endif | |
108 | ||
0e3426bb RM |
109 | |
110 | /* Create a new socket of type TYPE in domain DOMAIN, using | |
111 | protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically. | |
112 | Returns a file descriptor for the new socket, or -1 for errors. */ | |
ef5d6645 | 113 | extern int socket (int __domain, int __type, int __protocol) __THROW; |
0e3426bb RM |
114 | |
115 | /* Create two new sockets, of type TYPE in domain DOMAIN and using | |
116 | protocol PROTOCOL, which are connected to each other, and put file | |
117 | descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero, | |
118 | one will be chosen automatically. Returns 0 on success, -1 for errors. */ | |
ef5d6645 UD |
119 | extern int socketpair (int __domain, int __type, int __protocol, |
120 | int __fds[2]) __THROW; | |
0e3426bb RM |
121 | |
122 | /* Give the socket FD the local address ADDR (which is LEN bytes long). */ | |
ef5d6645 UD |
123 | extern int bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len) |
124 | __THROW; | |
0e3426bb RM |
125 | |
126 | /* Put the local address of FD into *ADDR and its length in *LEN. */ | |
98cbe360 UD |
127 | extern int getsockname (int __fd, __SOCKADDR_ARG __addr, |
128 | socklen_t *__restrict __len) __THROW; | |
0e3426bb RM |
129 | |
130 | /* Open a connection on socket FD to peer at ADDR (which LEN bytes long). | |
131 | For connectionless socket types, just set the default address to send to | |
132 | and the only address from which to accept transmissions. | |
2c008571 UD |
133 | Return 0 on success, -1 for errors. |
134 | ||
135 | This function is a cancellation point and therefore not marked with | |
136 | __THROW. */ | |
137 | extern int connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len); | |
0e3426bb RM |
138 | |
139 | /* Put the address of the peer connected to socket FD into *ADDR | |
140 | (which is *LEN bytes long), and its actual length into *LEN. */ | |
98cbe360 UD |
141 | extern int getpeername (int __fd, __SOCKADDR_ARG __addr, |
142 | socklen_t *__restrict __len) __THROW; | |
0e3426bb RM |
143 | |
144 | ||
2c008571 UD |
145 | /* Send N bytes of BUF to socket FD. Returns the number sent or -1. |
146 | ||
147 | This function is a cancellation point and therefore not marked with | |
148 | __THROW. */ | |
a784e502 | 149 | extern ssize_t send (int __fd, const void *__buf, size_t __n, int __flags); |
0e3426bb RM |
150 | |
151 | /* Read N bytes into BUF from socket FD. | |
2c008571 UD |
152 | Returns the number read or -1 for errors. |
153 | ||
154 | This function is a cancellation point and therefore not marked with | |
155 | __THROW. */ | |
156 | extern ssize_t recv (int __fd, void *__buf, size_t __n, int __flags); | |
0e3426bb RM |
157 | |
158 | /* Send N bytes of BUF on socket FD to peer at address ADDR (which is | |
2c008571 UD |
159 | ADDR_LEN bytes long). Returns the number sent, or -1 for errors. |
160 | ||
161 | This function is a cancellation point and therefore not marked with | |
162 | __THROW. */ | |
a784e502 | 163 | extern ssize_t sendto (int __fd, const void *__buf, size_t __n, |
c2063191 | 164 | int __flags, __CONST_SOCKADDR_ARG __addr, |
2c008571 | 165 | socklen_t __addr_len); |
0e3426bb RM |
166 | |
167 | /* Read N bytes into BUF through socket FD. | |
168 | If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of | |
169 | the sender, and store the actual size of the address in *ADDR_LEN. | |
2c008571 UD |
170 | Returns the number of bytes read or -1 for errors. |
171 | ||
172 | This function is a cancellation point and therefore not marked with | |
173 | __THROW. */ | |
174 | extern ssize_t recvfrom (int __fd, void *__restrict __buf, size_t __n, | |
175 | int __flags, __SOCKADDR_ARG __addr, | |
176 | socklen_t *__restrict __addr_len); | |
0e3426bb RM |
177 | |
178 | ||
179 | /* Send a message described MESSAGE on socket FD. | |
2c008571 UD |
180 | Returns the number of bytes sent, or -1 for errors. |
181 | ||
182 | This function is a cancellation point and therefore not marked with | |
183 | __THROW. */ | |
a784e502 | 184 | extern ssize_t sendmsg (int __fd, const struct msghdr *__message, |
2c008571 | 185 | int __flags); |
0e3426bb | 186 | |
123be9de TS |
187 | #ifdef __USE_GNU |
188 | /* Send a VLEN messages as described by VMESSAGES to socket FD. | |
189 | Returns the number of datagrams successfully written or -1 for errors. | |
190 | ||
191 | This function is a cancellation point and therefore not marked with | |
192 | __THROW. */ | |
193 | extern int sendmmsg (int __fd, struct mmsghdr *__vmessages, | |
194 | unsigned int __vlen, int __flags); | |
195 | #endif | |
196 | ||
0e3426bb | 197 | /* Receive a message as described by MESSAGE from socket FD. |
2c008571 UD |
198 | Returns the number of bytes read or -1 for errors. |
199 | ||
200 | This function is a cancellation point and therefore not marked with | |
201 | __THROW. */ | |
202 | extern ssize_t recvmsg (int __fd, struct msghdr *__message, int __flags); | |
0e3426bb | 203 | |
123be9de TS |
204 | #ifdef __USE_GNU |
205 | /* Receive up to VLEN messages as described by VMESSAGES from socket FD. | |
f7ed60c2 | 206 | Returns the number of messages received or -1 for errors. |
123be9de TS |
207 | |
208 | This function is a cancellation point and therefore not marked with | |
209 | __THROW. */ | |
210 | extern int recvmmsg (int __fd, struct mmsghdr *__vmessages, | |
211 | unsigned int __vlen, int __flags, | |
20e5a5f7 | 212 | struct timespec *__tmo); |
123be9de TS |
213 | #endif |
214 | ||
0e3426bb RM |
215 | |
216 | /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL | |
217 | into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's | |
218 | actual length. Returns 0 on success, -1 for errors. */ | |
ef5d6645 | 219 | extern int getsockopt (int __fd, int __level, int __optname, |
98cbe360 UD |
220 | void *__restrict __optval, |
221 | socklen_t *__restrict __optlen) __THROW; | |
0e3426bb RM |
222 | |
223 | /* Set socket FD's option OPTNAME at protocol level LEVEL | |
224 | to *OPTVAL (which is OPTLEN bytes long). | |
225 | Returns 0 on success, -1 for errors. */ | |
ef5d6645 | 226 | extern int setsockopt (int __fd, int __level, int __optname, |
a784e502 | 227 | const void *__optval, socklen_t __optlen) __THROW; |
0e3426bb RM |
228 | |
229 | ||
230 | /* Prepare to accept connections on socket FD. | |
231 | N connection requests will be queued before further requests are refused. | |
232 | Returns 0 on success, -1 for errors. */ | |
6f0ea379 | 233 | extern int listen (int __fd, int __n) __THROW; |
0e3426bb RM |
234 | |
235 | /* Await a connection on socket FD. | |
236 | When a connection arrives, open a new socket to communicate with it, | |
237 | set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting | |
238 | peer and *ADDR_LEN to the address's actual length, and return the | |
2c008571 UD |
239 | new socket's descriptor, or -1 for errors. |
240 | ||
241 | This function is a cancellation point and therefore not marked with | |
242 | __THROW. */ | |
98cbe360 | 243 | extern int accept (int __fd, __SOCKADDR_ARG __addr, |
2c008571 | 244 | socklen_t *__restrict __addr_len); |
0e3426bb | 245 | |
f93fc0b7 UD |
246 | #ifdef __USE_GNU |
247 | /* Similar to 'accept' but takes an additional parameter to specify flags. | |
248 | ||
249 | This function is a cancellation point and therefore not marked with | |
250 | __THROW. */ | |
251 | extern int accept4 (int __fd, __SOCKADDR_ARG __addr, | |
252 | socklen_t *__restrict __addr_len, int __flags); | |
253 | #endif | |
254 | ||
0e3426bb RM |
255 | /* Shut down all or part of the connection open on socket FD. |
256 | HOW determines what to shut down: | |
3ee12f2b UD |
257 | SHUT_RD = No more receptions; |
258 | SHUT_WR = No more transmissions; | |
259 | SHUT_RDWR = No more receptions or transmissions. | |
0e3426bb | 260 | Returns 0 on success, -1 for errors. */ |
ef5d6645 | 261 | extern int shutdown (int __fd, int __how) __THROW; |
0e3426bb RM |
262 | |
263 | ||
b5041719 UD |
264 | #ifdef __USE_XOPEN2K |
265 | /* Determine wheter socket is at a out-of-band mark. */ | |
266 | extern int sockatmark (int __fd) __THROW; | |
267 | #endif | |
268 | ||
269 | ||
6f0ea379 | 270 | #ifdef __USE_MISC |
07a4742f RM |
271 | /* FDTYPE is S_IFSOCK or another S_IF* macro defined in <sys/stat.h>; |
272 | returns 1 if FD is open on an object of the indicated type, 0 if not, | |
273 | or -1 for errors (setting errno). */ | |
ef5d6645 | 274 | extern int isfdtype (int __fd, int __fdtype) __THROW; |
6f0ea379 | 275 | #endif |
07a4742f | 276 | |
553cc5f9 UD |
277 | |
278 | /* Define some macros helping to catch buffer overflows. */ | |
5ac3ea17 | 279 | #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function |
553cc5f9 UD |
280 | # include <bits/socket2.h> |
281 | #endif | |
282 | ||
0e3426bb RM |
283 | __END_DECLS |
284 | ||
285 | #endif /* sys/socket.h */ |