Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
sockets.h
00001 /** 00002 * @file 00003 * Socket API (to be used from non-TCPIP threads) 00004 */ 00005 00006 /* 00007 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without modification, 00011 * are permitted provided that the following conditions are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. The name of the author may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00024 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00026 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00029 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00030 * OF SUCH DAMAGE. 00031 * 00032 * This file is part of the lwIP TCP/IP stack. 00033 * 00034 * Author: Adam Dunkels <adam@sics.se> 00035 * 00036 */ 00037 00038 00039 #ifndef LWIP_HDR_SOCKETS_H 00040 #define LWIP_HDR_SOCKETS_H 00041 00042 #include "lwip/opt.h" 00043 00044 #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ 00045 00046 #include "lwip/ip_addr.h" 00047 #include "lwip/netif.h" 00048 #include "lwip/err.h" 00049 #include "lwip/inet.h" 00050 #include "lwip/errno.h" 00051 00052 #include <string.h> 00053 00054 #ifdef __cplusplus 00055 extern "C" { 00056 #endif 00057 00058 /* If your port already typedef's sa_family_t, define SA_FAMILY_T_DEFINED 00059 to prevent this code from redefining it. */ 00060 #if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED) 00061 typedef u8_t sa_family_t; 00062 #endif 00063 /* If your port already typedef's in_port_t, define IN_PORT_T_DEFINED 00064 to prevent this code from redefining it. */ 00065 #if !defined(in_port_t) && !defined(IN_PORT_T_DEFINED) 00066 typedef u16_t in_port_t; 00067 #endif 00068 00069 #if LWIP_IPV4 00070 /* members are in network byte order */ 00071 struct sockaddr_in { 00072 u8_t sin_len; 00073 sa_family_t sin_family; 00074 in_port_t sin_port; 00075 struct in_addr sin_addr; 00076 #define SIN_ZERO_LEN 8 00077 char sin_zero[SIN_ZERO_LEN]; 00078 }; 00079 #endif /* LWIP_IPV4 */ 00080 00081 #if LWIP_IPV6 00082 struct sockaddr_in6 { 00083 u8_t sin6_len; /* length of this structure */ 00084 sa_family_t sin6_family; /* AF_INET6 */ 00085 in_port_t sin6_port; /* Transport layer port # */ 00086 u32_t sin6_flowinfo; /* IPv6 flow information */ 00087 struct in6_addr sin6_addr; /* IPv6 address */ 00088 u32_t sin6_scope_id; /* Set of interfaces for scope */ 00089 }; 00090 #endif /* LWIP_IPV6 */ 00091 00092 struct sockaddr { 00093 u8_t sa_len; 00094 sa_family_t sa_family; 00095 char sa_data[14]; 00096 }; 00097 00098 struct sockaddr_storage { 00099 u8_t s2_len; 00100 sa_family_t ss_family; 00101 char s2_data1[2]; 00102 u32_t s2_data2[3]; 00103 #if LWIP_IPV6 00104 u32_t s2_data3[3]; 00105 #endif /* LWIP_IPV6 */ 00106 }; 00107 00108 /* If your port already typedef's socklen_t, define SOCKLEN_T_DEFINED 00109 to prevent this code from redefining it. */ 00110 #if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED) 00111 typedef u32_t socklen_t; 00112 #endif 00113 00114 #if !defined IOV_MAX 00115 #define IOV_MAX 0xFFFF 00116 #elif IOV_MAX > 0xFFFF 00117 #error "IOV_MAX larger than supported by LwIP" 00118 #endif /* IOV_MAX */ 00119 00120 #if !defined(iovec) 00121 struct iovec { 00122 void *iov_base; 00123 size_t iov_len; 00124 }; 00125 #endif 00126 00127 struct msghdr { 00128 void *msg_name; 00129 socklen_t msg_namelen; 00130 struct iovec *msg_iov; 00131 int msg_iovlen; 00132 void *msg_control; 00133 socklen_t msg_controllen; 00134 int msg_flags; 00135 }; 00136 00137 /* struct msghdr->msg_flags bit field values */ 00138 #define MSG_TRUNC 0x04 00139 #define MSG_CTRUNC 0x08 00140 00141 /* RFC 3542, Section 20: Ancillary Data */ 00142 struct cmsghdr { 00143 socklen_t cmsg_len; /* number of bytes, including header */ 00144 int cmsg_level; /* originating protocol */ 00145 int cmsg_type; /* protocol-specific type */ 00146 }; 00147 /* Data section follows header and possible padding, typically referred to as 00148 unsigned char cmsg_data[]; */ 00149 00150 /* cmsg header/data alignment. NOTE: we align to native word size (double word 00151 size on 16-bit arch) so structures are not placed at an unaligned address. 00152 16-bit arch needs double word to ensure 32-bit alignment because socklen_t 00153 could be 32 bits. If we ever have cmsg data with a 64-bit variable, alignment 00154 will need to increase long long */ 00155 #define ALIGN_H(size) (((size) + sizeof(long) - 1U) & ~(sizeof(long)-1U)) 00156 #define ALIGN_D(size) ALIGN_H(size) 00157 00158 #define CMSG_FIRSTHDR(mhdr) \ 00159 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ 00160 (struct cmsghdr *)(mhdr)->msg_control : \ 00161 (struct cmsghdr *)NULL) 00162 00163 #define CMSG_NXTHDR(mhdr, cmsg) \ 00164 (((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \ 00165 (((u8_t *)(cmsg) + ALIGN_H((cmsg)->cmsg_len) \ 00166 + ALIGN_D(sizeof(struct cmsghdr)) > \ 00167 (u8_t *)((mhdr)->msg_control) + (mhdr)->msg_controllen) ? \ 00168 (struct cmsghdr *)NULL : \ 00169 (struct cmsghdr *)((void*)((u8_t *)(cmsg) + \ 00170 ALIGN_H((cmsg)->cmsg_len))))) 00171 00172 #define CMSG_DATA(cmsg) ((void*)((u8_t *)(cmsg) + \ 00173 ALIGN_D(sizeof(struct cmsghdr)))) 00174 00175 #define CMSG_SPACE(length) (ALIGN_D(sizeof(struct cmsghdr)) + \ 00176 ALIGN_H(length)) 00177 00178 #define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + \ 00179 length) 00180 00181 /* Set socket options argument */ 00182 #define IFNAMSIZ NETIF_NAMESIZE 00183 struct ifreq { 00184 char ifr_name[IFNAMSIZ]; /* Interface name */ 00185 }; 00186 00187 /* Socket protocol types (TCP/UDP/RAW) */ 00188 #define SOCK_STREAM 1 00189 #define SOCK_DGRAM 2 00190 #define SOCK_RAW 3 00191 00192 /* 00193 * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c) 00194 */ 00195 #define SO_REUSEADDR 0x0004 /* Allow local address reuse */ 00196 #define SO_KEEPALIVE 0x0008 /* keep connections alive */ 00197 #define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ 00198 00199 00200 /* 00201 * Additional options, not kept in so_options. 00202 */ 00203 #define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */ 00204 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ 00205 #define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */ 00206 #define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */ 00207 #define SO_LINGER 0x0080 /* linger on close if data present */ 00208 #define SO_DONTLINGER ((int)(~SO_LINGER)) 00209 #define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */ 00210 #define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */ 00211 #define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */ 00212 #define SO_RCVBUF 0x1002 /* receive buffer size */ 00213 #define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */ 00214 #define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */ 00215 #define SO_SNDTIMEO 0x1005 /* send timeout */ 00216 #define SO_RCVTIMEO 0x1006 /* receive timeout */ 00217 #define SO_ERROR 0x1007 /* get error status and clear */ 00218 #define SO_TYPE 0x1008 /* get socket type */ 00219 #define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */ 00220 #define SO_NO_CHECK 0x100a /* don't create UDP checksum */ 00221 #define SO_BINDTODEVICE 0x100b /* bind to device */ 00222 00223 /* 00224 * Structure used for manipulating linger option. 00225 */ 00226 struct linger { 00227 int l_onoff; /* option on/off */ 00228 int l_linger; /* linger time in seconds */ 00229 }; 00230 00231 /* 00232 * Level number for (get/set)sockopt() to apply to socket itself. 00233 */ 00234 #define SOL_SOCKET 0xfff /* options for socket level */ 00235 00236 00237 #define AF_UNSPEC 0 00238 #define AF_INET 2 00239 #if LWIP_IPV6 00240 #define AF_INET6 10 00241 #else /* LWIP_IPV6 */ 00242 #define AF_INET6 AF_UNSPEC 00243 #endif /* LWIP_IPV6 */ 00244 #define PF_INET AF_INET 00245 #define PF_INET6 AF_INET6 00246 #define PF_UNSPEC AF_UNSPEC 00247 00248 #define IPPROTO_IP 0 00249 #define IPPROTO_ICMP 1 00250 #define IPPROTO_TCP 6 00251 #define IPPROTO_UDP 17 00252 #if LWIP_IPV6 00253 #define IPPROTO_IPV6 41 00254 #define IPPROTO_ICMPV6 58 00255 #endif /* LWIP_IPV6 */ 00256 #define IPPROTO_UDPLITE 136 00257 #define IPPROTO_RAW 255 00258 00259 /* Flags we can use with send and recv. */ 00260 #define MSG_PEEK 0x01 /* Peeks at an incoming message */ 00261 #define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */ 00262 #define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */ 00263 #define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */ 00264 #define MSG_MORE 0x10 /* Sender will send more */ 00265 #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. */ 00266 00267 00268 /* 00269 * Options for level IPPROTO_IP 00270 */ 00271 #define IP_TOS 1 00272 #define IP_TTL 2 00273 #define IP_PKTINFO 8 00274 00275 #if LWIP_TCP 00276 /* 00277 * Options for level IPPROTO_TCP 00278 */ 00279 #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ 00280 #define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */ 00281 #define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */ 00282 #define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */ 00283 #define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */ 00284 #endif /* LWIP_TCP */ 00285 00286 #if LWIP_IPV6 00287 /* 00288 * Options for level IPPROTO_IPV6 00289 */ 00290 #define IPV6_CHECKSUM 7 /* RFC3542: calculate and insert the ICMPv6 checksum for raw sockets. */ 00291 #define IPV6_V6ONLY 27 /* RFC3493: boolean control to restrict AF_INET6 sockets to IPv6 communications only. */ 00292 #endif /* LWIP_IPV6 */ 00293 00294 #if LWIP_UDP && LWIP_UDPLITE 00295 /* 00296 * Options for level IPPROTO_UDPLITE 00297 */ 00298 #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */ 00299 #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */ 00300 #endif /* LWIP_UDP && LWIP_UDPLITE*/ 00301 00302 00303 #if LWIP_MULTICAST_TX_OPTIONS 00304 /* 00305 * Options and types for UDP multicast traffic handling 00306 */ 00307 #define IP_MULTICAST_TTL 5 00308 #define IP_MULTICAST_IF 6 00309 #define IP_MULTICAST_LOOP 7 00310 #endif /* LWIP_MULTICAST_TX_OPTIONS */ 00311 00312 #if LWIP_IGMP 00313 /* 00314 * Options and types related to multicast membership 00315 */ 00316 #define IP_ADD_MEMBERSHIP 3 00317 #define IP_DROP_MEMBERSHIP 4 00318 00319 typedef struct ip_mreq { 00320 struct in_addr imr_multiaddr; /* IP multicast address of group */ 00321 struct in_addr imr_interface; /* local IP address of interface */ 00322 } ip_mreq; 00323 #endif /* LWIP_IGMP */ 00324 00325 #if LWIP_IPV4 00326 struct in_pktinfo { 00327 unsigned int ipi_ifindex; /* Interface index */ 00328 struct in_addr ipi_addr; /* Destination (from header) address */ 00329 }; 00330 #endif /* LWIP_IPV4 */ 00331 00332 #if LWIP_IPV6_MLD 00333 /* 00334 * Options and types related to IPv6 multicast membership 00335 */ 00336 #define IPV6_JOIN_GROUP 12 00337 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP 00338 #define IPV6_LEAVE_GROUP 13 00339 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP 00340 00341 typedef struct ipv6_mreq { 00342 struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast addr */ 00343 unsigned int ipv6mr_interface; /* interface index, or 0 */ 00344 } ipv6_mreq; 00345 #endif /* LWIP_IPV6_MLD */ 00346 00347 /* 00348 * The Type of Service provides an indication of the abstract 00349 * parameters of the quality of service desired. These parameters are 00350 * to be used to guide the selection of the actual service parameters 00351 * when transmitting a datagram through a particular network. Several 00352 * networks offer service precedence, which somehow treats high 00353 * precedence traffic as more important than other traffic (generally 00354 * by accepting only traffic above a certain precedence at time of high 00355 * load). The major choice is a three way tradeoff between low-delay, 00356 * high-reliability, and high-throughput. 00357 * The use of the Delay, Throughput, and Reliability indications may 00358 * increase the cost (in some sense) of the service. In many networks 00359 * better performance for one of these parameters is coupled with worse 00360 * performance on another. Except for very unusual cases at most two 00361 * of these three indications should be set. 00362 */ 00363 #define IPTOS_TOS_MASK 0x1E 00364 #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) 00365 #define IPTOS_LOWDELAY 0x10 00366 #define IPTOS_THROUGHPUT 0x08 00367 #define IPTOS_RELIABILITY 0x04 00368 #define IPTOS_LOWCOST 0x02 00369 #define IPTOS_MINCOST IPTOS_LOWCOST 00370 00371 /* 00372 * The Network Control precedence designation is intended to be used 00373 * within a network only. The actual use and control of that 00374 * designation is up to each network. The Internetwork Control 00375 * designation is intended for use by gateway control originators only. 00376 * If the actual use of these precedence designations is of concern to 00377 * a particular network, it is the responsibility of that network to 00378 * control the access to, and use of, those precedence designations. 00379 */ 00380 #define IPTOS_PREC_MASK 0xe0 00381 #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) 00382 #define IPTOS_PREC_NETCONTROL 0xe0 00383 #define IPTOS_PREC_INTERNETCONTROL 0xc0 00384 #define IPTOS_PREC_CRITIC_ECP 0xa0 00385 #define IPTOS_PREC_FLASHOVERRIDE 0x80 00386 #define IPTOS_PREC_FLASH 0x60 00387 #define IPTOS_PREC_IMMEDIATE 0x40 00388 #define IPTOS_PREC_PRIORITY 0x20 00389 #define IPTOS_PREC_ROUTINE 0x00 00390 00391 00392 /* 00393 * Commands for ioctlsocket(), taken from the BSD file fcntl.h. 00394 * lwip_ioctl only supports FIONREAD and FIONBIO, for now 00395 * 00396 * Ioctl's have the command encoded in the lower word, 00397 * and the size of any in or out parameters in the upper 00398 * word. The high 2 bits of the upper word are used 00399 * to encode the in/out status of the parameter; for now 00400 * we restrict parameters to at most 128 bytes. 00401 */ 00402 #if !defined(FIONREAD) || !defined(FIONBIO) 00403 #define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */ 00404 #define IOC_VOID 0x20000000UL /* no parameters */ 00405 #define IOC_OUT 0x40000000UL /* copy out parameters */ 00406 #define IOC_IN 0x80000000UL /* copy in parameters */ 00407 #define IOC_INOUT (IOC_IN|IOC_OUT) 00408 /* 0x20000000 distinguishes new & 00409 old ioctl's */ 00410 #define _IO(x,y) ((long)(IOC_VOID|((x)<<8)|(y))) 00411 00412 #define _IOR(x,y,t) ((long)(IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))) 00413 00414 #define _IOW(x,y,t) ((long)(IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))) 00415 #endif /* !defined(FIONREAD) || !defined(FIONBIO) */ 00416 00417 #ifndef FIONREAD 00418 #define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */ 00419 #endif 00420 #ifndef FIONBIO 00421 #define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */ 00422 #endif 00423 00424 /* Socket I/O Controls: unimplemented */ 00425 #ifndef SIOCSHIWAT 00426 #define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */ 00427 #define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */ 00428 #define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */ 00429 #define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */ 00430 #define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */ 00431 #endif 00432 00433 /* commands for fnctl */ 00434 #ifndef F_GETFL 00435 #define F_GETFL 3 00436 #endif 00437 #ifndef F_SETFL 00438 #define F_SETFL 4 00439 #endif 00440 00441 /* File status flags and file access modes for fnctl, 00442 these are bits in an int. */ 00443 #ifndef O_NONBLOCK 00444 #define O_NONBLOCK 1 /* nonblocking I/O */ 00445 #endif 00446 #ifndef O_NDELAY 00447 #define O_NDELAY O_NONBLOCK /* same as O_NONBLOCK, for compatibility */ 00448 #endif 00449 #ifndef O_RDONLY 00450 #define O_RDONLY 2 00451 #endif 00452 #ifndef O_WRONLY 00453 #define O_WRONLY 4 00454 #endif 00455 #ifndef O_RDWR 00456 #define O_RDWR (O_RDONLY|O_WRONLY) 00457 #endif 00458 00459 #ifndef SHUT_RD 00460 #define SHUT_RD 0 00461 #define SHUT_WR 1 00462 #define SHUT_RDWR 2 00463 #endif 00464 00465 /* FD_SET used for lwip_select */ 00466 #ifndef FD_SET 00467 #undef FD_SETSIZE 00468 /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */ 00469 #define FD_SETSIZE MEMP_NUM_NETCONN 00470 #define LWIP_SELECT_MAXNFDS (FD_SETSIZE + LWIP_SOCKET_OFFSET) 00471 #define FDSETSAFESET(n, code) do { \ 00472 if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \ 00473 code; }} while(0) 00474 #define FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\ 00475 (code) : 0) 00476 #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)))) 00477 #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)))) 00478 #define FD_ISSET(n,p) FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7))) 00479 #define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) 00480 00481 typedef struct fd_set 00482 { 00483 unsigned char fd_bits [(FD_SETSIZE+7)/8]; 00484 } fd_set; 00485 00486 #elif FD_SETSIZE < (LWIP_SOCKET_OFFSET + MEMP_NUM_NETCONN) 00487 #error "external FD_SETSIZE too small for number of sockets" 00488 #else 00489 #define LWIP_SELECT_MAXNFDS FD_SETSIZE 00490 #endif /* FD_SET */ 00491 00492 /* poll-related defines and types */ 00493 /* @todo: find a better way to guard the definition of these defines and types if already defined */ 00494 #if !defined(POLLIN) && !defined(POLLOUT) 00495 #define POLLIN 0x1 00496 #define POLLOUT 0x2 00497 #define POLLERR 0x4 00498 #define POLLNVAL 0x8 00499 /* Below values are unimplemented */ 00500 #define POLLRDNORM 0x10 00501 #define POLLRDBAND 0x20 00502 #define POLLPRI 0x40 00503 #define POLLWRNORM 0x80 00504 #define POLLWRBAND 0x100 00505 #define POLLHUP 0x200 00506 typedef unsigned int nfds_t; 00507 struct pollfd 00508 { 00509 int fd; 00510 short events; 00511 short revents; 00512 }; 00513 #endif 00514 00515 /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided 00516 * by your system, set this to 0 and include <sys/time.h> in cc.h */ 00517 #ifndef LWIP_TIMEVAL_PRIVATE 00518 #define LWIP_TIMEVAL_PRIVATE 1 00519 #endif 00520 00521 #if LWIP_TIMEVAL_PRIVATE 00522 struct timeval { 00523 long tv_sec; /* seconds */ 00524 long tv_usec; /* and microseconds */ 00525 }; 00526 #endif /* LWIP_TIMEVAL_PRIVATE */ 00527 00528 #define lwip_socket_init() /* Compatibility define, no init needed. */ 00529 void lwip_socket_thread_init(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: initialize thread-local semaphore */ 00530 void lwip_socket_thread_cleanup(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: destroy thread-local semaphore */ 00531 00532 #if LWIP_COMPAT_SOCKETS == 2 00533 /* This helps code parsers/code completion by not having the COMPAT functions as defines */ 00534 #define lwip_accept accept 00535 #define lwip_bind bind 00536 #define lwip_shutdown shutdown 00537 #define lwip_getpeername getpeername 00538 #define lwip_getsockname getsockname 00539 #define lwip_setsockopt setsockopt 00540 #define lwip_getsockopt getsockopt 00541 #define lwip_close closesocket 00542 #define lwip_connect connect 00543 #define lwip_listen listen 00544 #define lwip_recv recv 00545 #define lwip_recvmsg recvmsg 00546 #define lwip_recvfrom recvfrom 00547 #define lwip_send send 00548 #define lwip_sendmsg sendmsg 00549 #define lwip_sendto sendto 00550 #define lwip_socket socket 00551 #if LWIP_SOCKET_SELECT 00552 #define lwip_select select 00553 #endif 00554 #if LWIP_SOCKET_POLL 00555 #define lwip_poll poll 00556 #endif 00557 #define lwip_ioctl ioctlsocket 00558 #define lwip_inet_ntop inet_ntop 00559 #define lwip_inet_pton inet_pton 00560 00561 #if LWIP_POSIX_SOCKETS_IO_NAMES 00562 #define lwip_read read 00563 #define lwip_readv readv 00564 #define lwip_write write 00565 #define lwip_writev writev 00566 #undef lwip_close 00567 #define lwip_close close 00568 #define closesocket(s) close(s) 00569 int fcntl(int s, int cmd, ...); 00570 #undef lwip_ioctl 00571 #define lwip_ioctl ioctl 00572 #define ioctlsocket ioctl 00573 #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ 00574 #endif /* LWIP_COMPAT_SOCKETS == 2 */ 00575 00576 int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); 00577 int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); 00578 int lwip_shutdown(int s, int how); 00579 int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen); 00580 int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen); 00581 int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen); 00582 int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen); 00583 int lwip_close(int s); 00584 int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); 00585 int lwip_listen(int s, int backlog); 00586 ssize_t lwip_recv(int s, void *mem, size_t len, int flags); 00587 ssize_t lwip_read(int s, void *mem, size_t len); 00588 ssize_t lwip_readv(int s, const struct iovec *iov, int iovcnt); 00589 ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags, 00590 struct sockaddr *from, socklen_t *fromlen); 00591 ssize_t lwip_recvmsg(int s, struct msghdr *message, int flags); 00592 ssize_t lwip_send(int s, const void *dataptr, size_t size, int flags); 00593 ssize_t lwip_sendmsg(int s, const struct msghdr *message, int flags); 00594 ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, 00595 const struct sockaddr *to, socklen_t tolen); 00596 int lwip_socket(int domain, int type, int protocol); 00597 ssize_t lwip_write(int s, const void *dataptr, size_t size); 00598 ssize_t lwip_writev(int s, const struct iovec *iov, int iovcnt); 00599 #if LWIP_SOCKET_SELECT 00600 int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, 00601 struct timeval *timeout); 00602 #endif 00603 #if LWIP_SOCKET_POLL 00604 int lwip_poll(struct pollfd *fds, nfds_t nfds, int timeout); 00605 #endif 00606 int lwip_ioctl(int s, long cmd, void *argp); 00607 int lwip_fcntl(int s, int cmd, int val); 00608 const char *lwip_inet_ntop(int af, const void *src, char *dst, socklen_t size); 00609 int lwip_inet_pton(int af, const char *src, void *dst); 00610 00611 #if LWIP_COMPAT_SOCKETS 00612 #if LWIP_COMPAT_SOCKETS != 2 00613 /** @ingroup socket */ 00614 #define accept(s,addr,addrlen) lwip_accept(s,addr,addrlen) 00615 /** @ingroup socket */ 00616 #define bind(s,name,namelen) lwip_bind(s,name,namelen) 00617 /** @ingroup socket */ 00618 #define shutdown(s,how) lwip_shutdown(s,how) 00619 /** @ingroup socket */ 00620 #define getpeername(s,name,namelen) lwip_getpeername(s,name,namelen) 00621 /** @ingroup socket */ 00622 #define getsockname(s,name,namelen) lwip_getsockname(s,name,namelen) 00623 /** @ingroup socket */ 00624 #define setsockopt(s,level,optname,opval,optlen) lwip_setsockopt(s,level,optname,opval,optlen) 00625 /** @ingroup socket */ 00626 #define getsockopt(s,level,optname,opval,optlen) lwip_getsockopt(s,level,optname,opval,optlen) 00627 /** @ingroup socket */ 00628 #define closesocket(s) lwip_close(s) 00629 /** @ingroup socket */ 00630 #define connect(s,name,namelen) lwip_connect(s,name,namelen) 00631 /** @ingroup socket */ 00632 #define listen(s,backlog) lwip_listen(s,backlog) 00633 /** @ingroup socket */ 00634 #define recv(s,mem,len,flags) lwip_recv(s,mem,len,flags) 00635 /** @ingroup socket */ 00636 #define recvmsg(s,message,flags) lwip_recvmsg(s,message,flags) 00637 /** @ingroup socket */ 00638 #define recvfrom(s,mem,len,flags,from,fromlen) lwip_recvfrom(s,mem,len,flags,from,fromlen) 00639 /** @ingroup socket */ 00640 #define send(s,dataptr,size,flags) lwip_send(s,dataptr,size,flags) 00641 /** @ingroup socket */ 00642 #define sendmsg(s,message,flags) lwip_sendmsg(s,message,flags) 00643 /** @ingroup socket */ 00644 #define sendto(s,dataptr,size,flags,to,tolen) lwip_sendto(s,dataptr,size,flags,to,tolen) 00645 /** @ingroup socket */ 00646 #define socket(domain,type,protocol) lwip_socket(domain,type,protocol) 00647 #if LWIP_SOCKET_SELECT 00648 /** @ingroup socket */ 00649 #define select(maxfdp1,readset,writeset,exceptset,timeout) lwip_select(maxfdp1,readset,writeset,exceptset,timeout) 00650 #endif 00651 #if LWIP_SOCKET_POLL 00652 /** @ingroup socket */ 00653 #define poll(fds,nfds,timeout) lwip_poll(fds,nfds,timeout) 00654 #endif 00655 /** @ingroup socket */ 00656 #define ioctlsocket(s,cmd,argp) lwip_ioctl(s,cmd,argp) 00657 /** @ingroup socket */ 00658 #define inet_ntop(af,src,dst,size) lwip_inet_ntop(af,src,dst,size) 00659 /** @ingroup socket */ 00660 #define inet_pton(af,src,dst) lwip_inet_pton(af,src,dst) 00661 00662 #if LWIP_POSIX_SOCKETS_IO_NAMES 00663 /** @ingroup socket */ 00664 #define read(s,mem,len) lwip_read(s,mem,len) 00665 /** @ingroup socket */ 00666 #define readv(s,iov,iovcnt) lwip_readv(s,iov,iovcnt) 00667 /** @ingroup socket */ 00668 #define write(s,dataptr,len) lwip_write(s,dataptr,len) 00669 /** @ingroup socket */ 00670 #define writev(s,iov,iovcnt) lwip_writev(s,iov,iovcnt) 00671 /** @ingroup socket */ 00672 #define close(s) lwip_close(s) 00673 /** @ingroup socket */ 00674 #define fcntl(s,cmd,val) lwip_fcntl(s,cmd,val) 00675 /** @ingroup socket */ 00676 #define ioctl(s,cmd,argp) lwip_ioctl(s,cmd,argp) 00677 #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ 00678 #endif /* LWIP_COMPAT_SOCKETS != 2 */ 00679 00680 #endif /* LWIP_COMPAT_SOCKETS */ 00681 00682 #ifdef __cplusplus 00683 } 00684 #endif 00685 00686 #endif /* LWIP_SOCKET */ 00687 00688 #endif /* LWIP_HDR_SOCKETS_H */
Generated on Tue Jul 12 2022 13:54:51 by
