BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file |
||
3 | * Socket API (to be used from non-TCPIP threads) |
||
4 | */ |
||
5 | |||
6 | /* |
||
7 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. |
||
8 | * All rights reserved. |
||
9 | * |
||
10 | * Redistribution and use in source and binary forms, with or without modification, |
||
11 | * are permitted provided that the following conditions are met: |
||
12 | * |
||
13 | * 1. Redistributions of source code must retain the above copyright notice, |
||
14 | * this list of conditions and the following disclaimer. |
||
15 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
||
16 | * this list of conditions and the following disclaimer in the documentation |
||
17 | * and/or other materials provided with the distribution. |
||
18 | * 3. The name of the author may not be used to endorse or promote products |
||
19 | * derived from this software without specific prior written permission. |
||
20 | * |
||
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
||
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
||
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
||
24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
||
26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
||
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
||
30 | * OF SUCH DAMAGE. |
||
31 | * |
||
32 | * This file is part of the lwIP TCP/IP stack. |
||
33 | * |
||
34 | * Author: Adam Dunkels <adam@sics.se> |
||
35 | * |
||
36 | */ |
||
37 | |||
38 | |||
39 | #ifndef LWIP_HDR_SOCKETS_H |
||
40 | #define LWIP_HDR_SOCKETS_H |
||
41 | |||
42 | #include "lwip/opt.h" |
||
43 | |||
44 | #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ |
||
45 | |||
46 | #include "lwip/ip_addr.h" |
||
47 | #include "lwip/netif.h" |
||
48 | #include "lwip/err.h" |
||
49 | #include "lwip/inet.h" |
||
50 | #include "lwip/errno.h" |
||
51 | |||
52 | #ifdef __cplusplus |
||
53 | extern "C" { |
||
54 | #endif |
||
55 | |||
56 | /* If your port already typedef's sa_family_t, define SA_FAMILY_T_DEFINED |
||
57 | to prevent this code from redefining it. */ |
||
58 | #if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED) |
||
59 | typedef u8_t sa_family_t; |
||
60 | #endif |
||
61 | /* If your port already typedef's in_port_t, define IN_PORT_T_DEFINED |
||
62 | to prevent this code from redefining it. */ |
||
63 | #if !defined(in_port_t) && !defined(IN_PORT_T_DEFINED) |
||
64 | typedef u16_t in_port_t; |
||
65 | #endif |
||
66 | |||
67 | #if LWIP_IPV4 |
||
68 | /* members are in network byte order */ |
||
69 | struct sockaddr_in { |
||
70 | u8_t sin_len; |
||
71 | sa_family_t sin_family; |
||
72 | in_port_t sin_port; |
||
73 | struct in_addr sin_addr; |
||
74 | #define SIN_ZERO_LEN 8 |
||
75 | char sin_zero[SIN_ZERO_LEN]; |
||
76 | }; |
||
77 | #endif /* LWIP_IPV4 */ |
||
78 | |||
79 | #if LWIP_IPV6 |
||
80 | struct sockaddr_in6 { |
||
81 | u8_t sin6_len; /* length of this structure */ |
||
82 | sa_family_t sin6_family; /* AF_INET6 */ |
||
83 | in_port_t sin6_port; /* Transport layer port # */ |
||
84 | u32_t sin6_flowinfo; /* IPv6 flow information */ |
||
85 | struct in6_addr sin6_addr; /* IPv6 address */ |
||
86 | u32_t sin6_scope_id; /* Set of interfaces for scope */ |
||
87 | }; |
||
88 | #endif /* LWIP_IPV6 */ |
||
89 | |||
90 | struct sockaddr { |
||
91 | u8_t sa_len; |
||
92 | sa_family_t sa_family; |
||
93 | char sa_data[14]; |
||
94 | }; |
||
95 | |||
96 | struct sockaddr_storage { |
||
97 | u8_t s2_len; |
||
98 | sa_family_t ss_family; |
||
99 | char s2_data1[2]; |
||
100 | u32_t s2_data2[3]; |
||
101 | #if LWIP_IPV6 |
||
102 | u32_t s2_data3[3]; |
||
103 | #endif /* LWIP_IPV6 */ |
||
104 | }; |
||
105 | |||
106 | /* If your port already typedef's socklen_t, define SOCKLEN_T_DEFINED |
||
107 | to prevent this code from redefining it. */ |
||
108 | #if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED) |
||
109 | typedef u32_t socklen_t; |
||
110 | #endif |
||
111 | |||
112 | #if !defined IOV_MAX |
||
113 | #define IOV_MAX 0xFFFF |
||
114 | #elif IOV_MAX > 0xFFFF |
||
115 | #error "IOV_MAX larger than supported by LwIP" |
||
116 | #endif /* IOV_MAX */ |
||
117 | |||
118 | #if !defined(iovec) |
||
119 | struct iovec { |
||
120 | void *iov_base; |
||
121 | size_t iov_len; |
||
122 | }; |
||
123 | #endif |
||
124 | |||
125 | struct msghdr { |
||
126 | void *msg_name; |
||
127 | socklen_t msg_namelen; |
||
128 | struct iovec *msg_iov; |
||
129 | int msg_iovlen; |
||
130 | void *msg_control; |
||
131 | socklen_t msg_controllen; |
||
132 | int msg_flags; |
||
133 | }; |
||
134 | |||
135 | /* struct msghdr->msg_flags bit field values */ |
||
136 | #define MSG_TRUNC 0x04 |
||
137 | #define MSG_CTRUNC 0x08 |
||
138 | |||
139 | /* RFC 3542, Section 20: Ancillary Data */ |
||
140 | struct cmsghdr { |
||
141 | socklen_t cmsg_len; /* number of bytes, including header */ |
||
142 | int cmsg_level; /* originating protocol */ |
||
143 | int cmsg_type; /* protocol-specific type */ |
||
144 | }; |
||
145 | /* Data section follows header and possible padding, typically referred to as |
||
146 | unsigned char cmsg_data[]; */ |
||
147 | |||
148 | /* cmsg header/data alignment. NOTE: we align to native word size (double word |
||
149 | size on 16-bit arch) so structures are not placed at an unaligned address. |
||
150 | 16-bit arch needs double word to ensure 32-bit alignment because socklen_t |
||
151 | could be 32 bits. If we ever have cmsg data with a 64-bit variable, alignment |
||
152 | will need to increase long long */ |
||
153 | #define ALIGN_H(size) (((size) + sizeof(long) - 1U) & ~(sizeof(long)-1U)) |
||
154 | #define ALIGN_D(size) ALIGN_H(size) |
||
155 | |||
156 | #define CMSG_FIRSTHDR(mhdr) \ |
||
157 | ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ |
||
158 | (struct cmsghdr *)(mhdr)->msg_control : \ |
||
159 | (struct cmsghdr *)NULL) |
||
160 | |||
161 | #define CMSG_NXTHDR(mhdr, cmsg) \ |
||
162 | (((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \ |
||
163 | (((u8_t *)(cmsg) + ALIGN_H((cmsg)->cmsg_len) \ |
||
164 | + ALIGN_D(sizeof(struct cmsghdr)) > \ |
||
165 | (u8_t *)((mhdr)->msg_control) + (mhdr)->msg_controllen) ? \ |
||
166 | (struct cmsghdr *)NULL : \ |
||
167 | (struct cmsghdr *)((void*)((u8_t *)(cmsg) + \ |
||
168 | ALIGN_H((cmsg)->cmsg_len))))) |
||
169 | |||
170 | #define CMSG_DATA(cmsg) ((void*)((u8_t *)(cmsg) + \ |
||
171 | ALIGN_D(sizeof(struct cmsghdr)))) |
||
172 | |||
173 | #define CMSG_SPACE(length) (ALIGN_D(sizeof(struct cmsghdr)) + \ |
||
174 | ALIGN_H(length)) |
||
175 | |||
176 | #define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + \ |
||
177 | length) |
||
178 | |||
179 | /* Set socket options argument */ |
||
180 | #define IFNAMSIZ NETIF_NAMESIZE |
||
181 | struct ifreq { |
||
182 | char ifr_name[IFNAMSIZ]; /* Interface name */ |
||
183 | }; |
||
184 | |||
185 | /* Socket protocol types (TCP/UDP/RAW) */ |
||
186 | #define SOCK_STREAM 1 |
||
187 | #define SOCK_DGRAM 2 |
||
188 | #define SOCK_RAW 3 |
||
189 | |||
190 | /* |
||
191 | * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c) |
||
192 | */ |
||
193 | #define SO_REUSEADDR 0x0004 /* Allow local address reuse */ |
||
194 | #define SO_KEEPALIVE 0x0008 /* keep connections alive */ |
||
195 | #define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ |
||
196 | |||
197 | |||
198 | /* |
||
199 | * Additional options, not kept in so_options. |
||
200 | */ |
||
201 | #define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */ |
||
202 | #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ |
||
203 | #define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */ |
||
204 | #define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */ |
||
205 | #define SO_LINGER 0x0080 /* linger on close if data present */ |
||
206 | #define SO_DONTLINGER ((int)(~SO_LINGER)) |
||
207 | #define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */ |
||
208 | #define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */ |
||
209 | #define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */ |
||
210 | #define SO_RCVBUF 0x1002 /* receive buffer size */ |
||
211 | #define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */ |
||
212 | #define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */ |
||
213 | #define SO_SNDTIMEO 0x1005 /* send timeout */ |
||
214 | #define SO_RCVTIMEO 0x1006 /* receive timeout */ |
||
215 | #define SO_ERROR 0x1007 /* get error status and clear */ |
||
216 | #define SO_TYPE 0x1008 /* get socket type */ |
||
217 | #define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */ |
||
218 | #define SO_NO_CHECK 0x100a /* don't create UDP checksum */ |
||
219 | #define SO_BINDTODEVICE 0x100b /* bind to device */ |
||
220 | |||
221 | /* |
||
222 | * Structure used for manipulating linger option. |
||
223 | */ |
||
224 | struct linger { |
||
225 | int l_onoff; /* option on/off */ |
||
226 | int l_linger; /* linger time in seconds */ |
||
227 | }; |
||
228 | |||
229 | /* |
||
230 | * Level number for (get/set)sockopt() to apply to socket itself. |
||
231 | */ |
||
232 | #define SOL_SOCKET 0xfff /* options for socket level */ |
||
233 | |||
234 | |||
235 | #define AF_UNSPEC 0 |
||
236 | #define AF_INET 2 |
||
237 | #if LWIP_IPV6 |
||
238 | #define AF_INET6 10 |
||
239 | #else /* LWIP_IPV6 */ |
||
240 | #define AF_INET6 AF_UNSPEC |
||
241 | #endif /* LWIP_IPV6 */ |
||
242 | #define PF_INET AF_INET |
||
243 | #define PF_INET6 AF_INET6 |
||
244 | #define PF_UNSPEC AF_UNSPEC |
||
245 | |||
246 | #define IPPROTO_IP 0 |
||
247 | #define IPPROTO_ICMP 1 |
||
248 | #define IPPROTO_TCP 6 |
||
249 | #define IPPROTO_UDP 17 |
||
250 | #if LWIP_IPV6 |
||
251 | #define IPPROTO_IPV6 41 |
||
252 | #define IPPROTO_ICMPV6 58 |
||
253 | #endif /* LWIP_IPV6 */ |
||
254 | #define IPPROTO_UDPLITE 136 |
||
255 | #define IPPROTO_RAW 255 |
||
256 | |||
257 | /* Flags we can use with send and recv. */ |
||
258 | #define MSG_PEEK 0x01 /* Peeks at an incoming message */ |
||
259 | #define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */ |
||
260 | #define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */ |
||
261 | #define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */ |
||
262 | #define MSG_MORE 0x10 /* Sender will send more */ |
||
263 | #define MSG_NOSIGNAL 0x20 /* Uninmplemented: Requests not to send the SIGPIPE signal if an attempt to send is made on a stream-oriented socket that is no longer connected. */ |
||
264 | |||
265 | |||
266 | /* |
||
267 | * Options for level IPPROTO_IP |
||
268 | */ |
||
269 | #define IP_TOS 1 |
||
270 | #define IP_TTL 2 |
||
271 | #define IP_PKTINFO 8 |
||
272 | |||
273 | #if LWIP_TCP |
||
274 | /* |
||
275 | * Options for level IPPROTO_TCP |
||
276 | */ |
||
277 | #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ |
||
278 | #define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */ |
||
279 | #define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */ |
||
280 | #define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */ |
||
281 | #define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */ |
||
282 | #endif /* LWIP_TCP */ |
||
283 | |||
284 | #if LWIP_IPV6 |
||
285 | /* |
||
286 | * Options for level IPPROTO_IPV6 |
||
287 | */ |
||
288 | #define IPV6_CHECKSUM 7 /* RFC3542: calculate and insert the ICMPv6 checksum for raw sockets. */ |
||
289 | #define IPV6_V6ONLY 27 /* RFC3493: boolean control to restrict AF_INET6 sockets to IPv6 communications only. */ |
||
290 | #endif /* LWIP_IPV6 */ |
||
291 | |||
292 | #if LWIP_UDP && LWIP_UDPLITE |
||
293 | /* |
||
294 | * Options for level IPPROTO_UDPLITE |
||
295 | */ |
||
296 | #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */ |
||
297 | #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */ |
||
298 | #endif /* LWIP_UDP && LWIP_UDPLITE*/ |
||
299 | |||
300 | |||
301 | #if LWIP_MULTICAST_TX_OPTIONS |
||
302 | /* |
||
303 | * Options and types for UDP multicast traffic handling |
||
304 | */ |
||
305 | #define IP_MULTICAST_TTL 5 |
||
306 | #define IP_MULTICAST_IF 6 |
||
307 | #define IP_MULTICAST_LOOP 7 |
||
308 | #endif /* LWIP_MULTICAST_TX_OPTIONS */ |
||
309 | |||
310 | #if LWIP_IGMP |
||
311 | /* |
||
312 | * Options and types related to multicast membership |
||
313 | */ |
||
314 | #define IP_ADD_MEMBERSHIP 3 |
||
315 | #define IP_DROP_MEMBERSHIP 4 |
||
316 | |||
317 | typedef struct ip_mreq { |
||
318 | struct in_addr imr_multiaddr; /* IP multicast address of group */ |
||
319 | struct in_addr imr_interface; /* local IP address of interface */ |
||
320 | } ip_mreq; |
||
321 | #endif /* LWIP_IGMP */ |
||
322 | |||
323 | #if LWIP_IPV4 |
||
324 | struct in_pktinfo { |
||
325 | unsigned int ipi_ifindex; /* Interface index */ |
||
326 | struct in_addr ipi_addr; /* Destination (from header) address */ |
||
327 | }; |
||
328 | #endif /* LWIP_IPV4 */ |
||
329 | |||
330 | #if LWIP_IPV6_MLD |
||
331 | /* |
||
332 | * Options and types related to IPv6 multicast membership |
||
333 | */ |
||
334 | #define IPV6_JOIN_GROUP 12 |
||
335 | #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP |
||
336 | #define IPV6_LEAVE_GROUP 13 |
||
337 | #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP |
||
338 | |||
339 | typedef struct ipv6_mreq { |
||
340 | struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast addr */ |
||
341 | unsigned int ipv6mr_interface; /* interface index, or 0 */ |
||
342 | } ipv6_mreq; |
||
343 | #endif /* LWIP_IPV6_MLD */ |
||
344 | |||
345 | /* |
||
346 | * The Type of Service provides an indication of the abstract |
||
347 | * parameters of the quality of service desired. These parameters are |
||
348 | * to be used to guide the selection of the actual service parameters |
||
349 | * when transmitting a datagram through a particular network. Several |
||
350 | * networks offer service precedence, which somehow treats high |
||
351 | * precedence traffic as more important than other traffic (generally |
||
352 | * by accepting only traffic above a certain precedence at time of high |
||
353 | * load). The major choice is a three way tradeoff between low-delay, |
||
354 | * high-reliability, and high-throughput. |
||
355 | * The use of the Delay, Throughput, and Reliability indications may |
||
356 | * increase the cost (in some sense) of the service. In many networks |
||
357 | * better performance for one of these parameters is coupled with worse |
||
358 | * performance on another. Except for very unusual cases at most two |
||
359 | * of these three indications should be set. |
||
360 | */ |
||
361 | #define IPTOS_TOS_MASK 0x1E |
||
362 | #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) |
||
363 | #define IPTOS_LOWDELAY 0x10 |
||
364 | #define IPTOS_THROUGHPUT 0x08 |
||
365 | #define IPTOS_RELIABILITY 0x04 |
||
366 | #define IPTOS_LOWCOST 0x02 |
||
367 | #define IPTOS_MINCOST IPTOS_LOWCOST |
||
368 | |||
369 | /* |
||
370 | * The Network Control precedence designation is intended to be used |
||
371 | * within a network only. The actual use and control of that |
||
372 | * designation is up to each network. The Internetwork Control |
||
373 | * designation is intended for use by gateway control originators only. |
||
374 | * If the actual use of these precedence designations is of concern to |
||
375 | * a particular network, it is the responsibility of that network to |
||
376 | * control the access to, and use of, those precedence designations. |
||
377 | */ |
||
378 | #define IPTOS_PREC_MASK 0xe0 |
||
379 | #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) |
||
380 | #define IPTOS_PREC_NETCONTROL 0xe0 |
||
381 | #define IPTOS_PREC_INTERNETCONTROL 0xc0 |
||
382 | #define IPTOS_PREC_CRITIC_ECP 0xa0 |
||
383 | #define IPTOS_PREC_FLASHOVERRIDE 0x80 |
||
384 | #define IPTOS_PREC_FLASH 0x60 |
||
385 | #define IPTOS_PREC_IMMEDIATE 0x40 |
||
386 | #define IPTOS_PREC_PRIORITY 0x20 |
||
387 | #define IPTOS_PREC_ROUTINE 0x00 |
||
388 | |||
389 | |||
390 | /* |
||
391 | * Commands for ioctlsocket(), taken from the BSD file fcntl.h. |
||
392 | * lwip_ioctl only supports FIONREAD and FIONBIO, for now |
||
393 | * |
||
394 | * Ioctl's have the command encoded in the lower word, |
||
395 | * and the size of any in or out parameters in the upper |
||
396 | * word. The high 2 bits of the upper word are used |
||
397 | * to encode the in/out status of the parameter; for now |
||
398 | * we restrict parameters to at most 128 bytes. |
||
399 | */ |
||
400 | #if !defined(FIONREAD) || !defined(FIONBIO) |
||
401 | #define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */ |
||
402 | #define IOC_VOID 0x20000000UL /* no parameters */ |
||
403 | #define IOC_OUT 0x40000000UL /* copy out parameters */ |
||
404 | #define IOC_IN 0x80000000UL /* copy in parameters */ |
||
405 | #define IOC_INOUT (IOC_IN|IOC_OUT) |
||
406 | /* 0x20000000 distinguishes new & |
||
407 | old ioctl's */ |
||
408 | #define _IO(x,y) ((long)(IOC_VOID|((x)<<8)|(y))) |
||
409 | |||
410 | #define _IOR(x,y,t) ((long)(IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))) |
||
411 | |||
412 | #define _IOW(x,y,t) ((long)(IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))) |
||
413 | #endif /* !defined(FIONREAD) || !defined(FIONBIO) */ |
||
414 | |||
415 | #ifndef FIONREAD |
||
416 | #define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */ |
||
417 | #endif |
||
418 | #ifndef FIONBIO |
||
419 | #define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */ |
||
420 | #endif |
||
421 | |||
422 | /* Socket I/O Controls: unimplemented */ |
||
423 | #ifndef SIOCSHIWAT |
||
424 | #define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */ |
||
425 | #define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */ |
||
426 | #define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */ |
||
427 | #define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */ |
||
428 | #define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */ |
||
429 | #endif |
||
430 | |||
431 | /* commands for fnctl */ |
||
432 | #ifndef F_GETFL |
||
433 | #define F_GETFL 3 |
||
434 | #endif |
||
435 | #ifndef F_SETFL |
||
436 | #define F_SETFL 4 |
||
437 | #endif |
||
438 | |||
439 | /* File status flags and file access modes for fnctl, |
||
440 | these are bits in an int. */ |
||
441 | #ifndef O_NONBLOCK |
||
442 | #define O_NONBLOCK 1 /* nonblocking I/O */ |
||
443 | #endif |
||
444 | #ifndef O_NDELAY |
||
445 | #define O_NDELAY 1 /* same as O_NONBLOCK, for compatibility */ |
||
446 | #endif |
||
447 | #ifndef O_RDONLY |
||
448 | #define O_RDONLY 2 |
||
449 | #endif |
||
450 | #ifndef O_WRONLY |
||
451 | #define O_WRONLY 4 |
||
452 | #endif |
||
453 | #ifndef O_RDWR |
||
454 | #define O_RDWR (O_RDONLY|O_WRONLY) |
||
455 | #endif |
||
456 | |||
457 | #ifndef SHUT_RD |
||
458 | #define SHUT_RD 0 |
||
459 | #define SHUT_WR 1 |
||
460 | #define SHUT_RDWR 2 |
||
461 | #endif |
||
462 | |||
463 | /* FD_SET used for lwip_select */ |
||
464 | #ifndef FD_SET |
||
465 | #undef FD_SETSIZE |
||
466 | /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */ |
||
467 | #define FD_SETSIZE MEMP_NUM_NETCONN |
||
468 | #define FDSETSAFESET(n, code) do { \ |
||
469 | if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \ |
||
470 | code; }} while(0) |
||
471 | #define FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\ |
||
472 | (code) : 0) |
||
473 | #define FD_SET(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] = (u8_t)((p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] | (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))) |
||
474 | #define FD_CLR(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] = (u8_t)((p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))) |
||
475 | #define FD_ISSET(n,p) FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7))) |
||
476 | #define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) |
||
477 | |||
478 | typedef struct fd_set |
||
479 | { |
||
480 | unsigned char fd_bits [(FD_SETSIZE+7)/8]; |
||
481 | } fd_set; |
||
482 | |||
483 | #elif LWIP_SOCKET_OFFSET |
||
484 | #error LWIP_SOCKET_OFFSET does not work with external FD_SET! |
||
485 | #elif FD_SETSIZE < MEMP_NUM_NETCONN |
||
486 | #error "external FD_SETSIZE too small for number of sockets" |
||
487 | #endif /* FD_SET */ |
||
488 | |||
489 | /* poll-related defines and types */ |
||
490 | /* @todo: find a better way to guard the definition of these defines and types if already defined */ |
||
491 | #if !defined(POLLIN) && !defined(POLLOUT) |
||
492 | #define POLLIN 1 |
||
493 | #define POLLOUT 2 |
||
494 | #define POLLERR 4 |
||
495 | #define POLLNVAL 8 |
||
496 | /* No support for POLLPRI, POLLHUP, POLLMSG, POLLRDBAND, POLLWRBAND. */ |
||
497 | typedef int nfds_t; |
||
498 | struct pollfd |
||
499 | { |
||
500 | int fd; |
||
501 | short events; |
||
502 | short revents; |
||
503 | }; |
||
504 | #endif |
||
505 | |||
506 | /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided |
||
507 | * by your system, set this to 0 and include <sys/time.h> in cc.h */ |
||
508 | #ifndef LWIP_TIMEVAL_PRIVATE |
||
509 | #define LWIP_TIMEVAL_PRIVATE 1 |
||
510 | #endif |
||
511 | |||
512 | #if LWIP_TIMEVAL_PRIVATE |
||
513 | struct timeval { |
||
514 | long tv_sec; /* seconds */ |
||
515 | long tv_usec; /* and microseconds */ |
||
516 | }; |
||
517 | #endif /* LWIP_TIMEVAL_PRIVATE */ |
||
518 | |||
519 | #define lwip_socket_init() /* Compatibility define, no init needed. */ |
||
520 | void lwip_socket_thread_init(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: initialize thread-local semaphore */ |
||
521 | void lwip_socket_thread_cleanup(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: destroy thread-local semaphore */ |
||
522 | |||
523 | #if LWIP_COMPAT_SOCKETS == 2 |
||
524 | /* This helps code parsers/code completion by not having the COMPAT functions as defines */ |
||
525 | #define lwip_accept accept |
||
526 | #define lwip_bind bind |
||
527 | #define lwip_shutdown shutdown |
||
528 | #define lwip_getpeername getpeername |
||
529 | #define lwip_getsockname getsockname |
||
530 | #define lwip_setsockopt setsockopt |
||
531 | #define lwip_getsockopt getsockopt |
||
532 | #define lwip_close closesocket |
||
533 | #define lwip_connect connect |
||
534 | #define lwip_listen listen |
||
535 | #define lwip_recv recv |
||
536 | #define lwip_recvmsg recvmsg |
||
537 | #define lwip_recvfrom recvfrom |
||
538 | #define lwip_send send |
||
539 | #define lwip_sendmsg sendmsg |
||
540 | #define lwip_sendto sendto |
||
541 | #define lwip_socket socket |
||
542 | #if LWIP_SOCKET_SELECT |
||
543 | #define lwip_select select |
||
544 | #endif |
||
545 | #if LWIP_SOCKET_POLL |
||
546 | #define lwip_poll poll |
||
547 | #endif |
||
548 | #define lwip_ioctl ioctlsocket |
||
549 | #define lwip_inet_ntop inet_ntop |
||
550 | #define lwip_inet_pton inet_pton |
||
551 | |||
552 | #if LWIP_POSIX_SOCKETS_IO_NAMES |
||
553 | #define lwip_read read |
||
554 | #define lwip_readv readv |
||
555 | #define lwip_write write |
||
556 | #define lwip_writev writev |
||
557 | #undef lwip_close |
||
558 | #define lwip_close close |
||
559 | #define closesocket(s) close(s) |
||
560 | int fcntl(int s, int cmd, ...); |
||
561 | #undef lwip_ioctl |
||
562 | #define lwip_ioctl ioctl |
||
563 | #define ioctlsocket ioctl |
||
564 | #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ |
||
565 | #endif /* LWIP_COMPAT_SOCKETS == 2 */ |
||
566 | |||
567 | int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); |
||
568 | int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); |
||
569 | int lwip_shutdown(int s, int how); |
||
570 | int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen); |
||
571 | int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen); |
||
572 | int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen); |
||
573 | int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen); |
||
574 | int lwip_close(int s); |
||
575 | int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); |
||
576 | int lwip_listen(int s, int backlog); |
||
577 | ssize_t lwip_recv(int s, void *mem, size_t len, int flags); |
||
578 | ssize_t lwip_read(int s, void *mem, size_t len); |
||
579 | ssize_t lwip_readv(int s, const struct iovec *iov, int iovcnt); |
||
580 | ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags, |
||
581 | struct sockaddr *from, socklen_t *fromlen); |
||
582 | ssize_t lwip_recvmsg(int s, struct msghdr *message, int flags); |
||
583 | ssize_t lwip_send(int s, const void *dataptr, size_t size, int flags); |
||
584 | ssize_t lwip_sendmsg(int s, const struct msghdr *message, int flags); |
||
585 | ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, |
||
586 | const struct sockaddr *to, socklen_t tolen); |
||
587 | int lwip_socket(int domain, int type, int protocol); |
||
588 | ssize_t lwip_write(int s, const void *dataptr, size_t size); |
||
589 | ssize_t lwip_writev(int s, const struct iovec *iov, int iovcnt); |
||
590 | #if LWIP_SOCKET_SELECT |
||
591 | int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, |
||
592 | struct timeval *timeout); |
||
593 | #endif |
||
594 | #if LWIP_SOCKET_POLL |
||
595 | int lwip_poll(struct pollfd *fds, nfds_t nfds, int timeout); |
||
596 | #endif |
||
597 | int lwip_ioctl(int s, long cmd, void *argp); |
||
598 | int lwip_fcntl(int s, int cmd, int val); |
||
599 | const char *lwip_inet_ntop(int af, const void *src, char *dst, socklen_t size); |
||
600 | int lwip_inet_pton(int af, const char *src, void *dst); |
||
601 | |||
602 | #if LWIP_COMPAT_SOCKETS |
||
603 | #if LWIP_COMPAT_SOCKETS != 2 |
||
604 | /** @ingroup socket */ |
||
605 | #define accept(s,addr,addrlen) lwip_accept(s,addr,addrlen) |
||
606 | /** @ingroup socket */ |
||
607 | #define bind(s,name,namelen) lwip_bind(s,name,namelen) |
||
608 | /** @ingroup socket */ |
||
609 | #define shutdown(s,how) lwip_shutdown(s,how) |
||
610 | /** @ingroup socket */ |
||
611 | #define getpeername(s,name,namelen) lwip_getpeername(s,name,namelen) |
||
612 | /** @ingroup socket */ |
||
613 | #define getsockname(s,name,namelen) lwip_getsockname(s,name,namelen) |
||
614 | /** @ingroup socket */ |
||
615 | #define setsockopt(s,level,optname,opval,optlen) lwip_setsockopt(s,level,optname,opval,optlen) |
||
616 | /** @ingroup socket */ |
||
617 | #define getsockopt(s,level,optname,opval,optlen) lwip_getsockopt(s,level,optname,opval,optlen) |
||
618 | /** @ingroup socket */ |
||
619 | #define closesocket(s) lwip_close(s) |
||
620 | /** @ingroup socket */ |
||
621 | #define connect(s,name,namelen) lwip_connect(s,name,namelen) |
||
622 | /** @ingroup socket */ |
||
623 | #define listen(s,backlog) lwip_listen(s,backlog) |
||
624 | /** @ingroup socket */ |
||
625 | #define recv(s,mem,len,flags) lwip_recv(s,mem,len,flags) |
||
626 | /** @ingroup socket */ |
||
627 | #define recvmsg(s,message,flags) lwip_recvmsg(s,message,flags) |
||
628 | /** @ingroup socket */ |
||
629 | #define recvfrom(s,mem,len,flags,from,fromlen) lwip_recvfrom(s,mem,len,flags,from,fromlen) |
||
630 | /** @ingroup socket */ |
||
631 | #define send(s,dataptr,size,flags) lwip_send(s,dataptr,size,flags) |
||
632 | /** @ingroup socket */ |
||
633 | #define sendmsg(s,message,flags) lwip_sendmsg(s,message,flags) |
||
634 | /** @ingroup socket */ |
||
635 | #define sendto(s,dataptr,size,flags,to,tolen) lwip_sendto(s,dataptr,size,flags,to,tolen) |
||
636 | /** @ingroup socket */ |
||
637 | #define socket(domain,type,protocol) lwip_socket(domain,type,protocol) |
||
638 | #if LWIP_SOCKET_SELECT |
||
639 | /** @ingroup socket */ |
||
640 | #define select(maxfdp1,readset,writeset,exceptset,timeout) lwip_select(maxfdp1,readset,writeset,exceptset,timeout) |
||
641 | #endif |
||
642 | #if LWIP_SOCKET_POLL |
||
643 | /** @ingroup socket */ |
||
644 | #define poll(fds,nfds,timeout) lwip_poll(fds,nfds,timeout) |
||
645 | #endif |
||
646 | /** @ingroup socket */ |
||
647 | #define ioctlsocket(s,cmd,argp) lwip_ioctl(s,cmd,argp) |
||
648 | /** @ingroup socket */ |
||
649 | #define inet_ntop(af,src,dst,size) lwip_inet_ntop(af,src,dst,size) |
||
650 | /** @ingroup socket */ |
||
651 | #define inet_pton(af,src,dst) lwip_inet_pton(af,src,dst) |
||
652 | |||
653 | #if LWIP_POSIX_SOCKETS_IO_NAMES |
||
654 | /** @ingroup socket */ |
||
655 | #define read(s,mem,len) lwip_read(s,mem,len) |
||
656 | /** @ingroup socket */ |
||
657 | #define readv(s,iov,iovcnt) lwip_readv(s,iov,iovcnt) |
||
658 | /** @ingroup socket */ |
||
659 | #define write(s,dataptr,len) lwip_write(s,dataptr,len) |
||
660 | /** @ingroup socket */ |
||
661 | #define writev(s,iov,iovcnt) lwip_writev(s,iov,iovcnt) |
||
662 | /** @ingroup socket */ |
||
663 | #define close(s) lwip_close(s) |
||
664 | /** @ingroup socket */ |
||
665 | #define fcntl(s,cmd,val) lwip_fcntl(s,cmd,val) |
||
666 | /** @ingroup socket */ |
||
667 | #define ioctl(s,cmd,argp) lwip_ioctl(s,cmd,argp) |
||
668 | #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ |
||
669 | #endif /* LWIP_COMPAT_SOCKETS != 2 */ |
||
670 | |||
671 | #endif /* LWIP_COMPAT_SOCKETS */ |
||
672 | |||
673 | #ifdef __cplusplus |
||
674 | } |
||
675 | #endif |
||
676 | |||
677 | #endif /* LWIP_SOCKET */ |
||
678 | |||
679 | #endif /* LWIP_HDR_SOCKETS_H */ |