Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sherckuith 0:479ce5546098 1 /*
sherckuith 0:479ce5546098 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
sherckuith 0:479ce5546098 3 * All rights reserved.
sherckuith 0:479ce5546098 4 *
sherckuith 0:479ce5546098 5 * Redistribution and use in source and binary forms, with or without modification,
sherckuith 0:479ce5546098 6 * are permitted provided that the following conditions are met:
sherckuith 0:479ce5546098 7 *
sherckuith 0:479ce5546098 8 * 1. Redistributions of source code must retain the above copyright notice,
sherckuith 0:479ce5546098 9 * this list of conditions and the following disclaimer.
sherckuith 0:479ce5546098 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
sherckuith 0:479ce5546098 11 * this list of conditions and the following disclaimer in the documentation
sherckuith 0:479ce5546098 12 * and/or other materials provided with the distribution.
sherckuith 0:479ce5546098 13 * 3. The name of the author may not be used to endorse or promote products
sherckuith 0:479ce5546098 14 * derived from this software without specific prior written permission.
sherckuith 0:479ce5546098 15 *
sherckuith 0:479ce5546098 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
sherckuith 0:479ce5546098 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
sherckuith 0:479ce5546098 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
sherckuith 0:479ce5546098 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
sherckuith 0:479ce5546098 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
sherckuith 0:479ce5546098 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
sherckuith 0:479ce5546098 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
sherckuith 0:479ce5546098 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
sherckuith 0:479ce5546098 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
sherckuith 0:479ce5546098 25 * OF SUCH DAMAGE.
sherckuith 0:479ce5546098 26 *
sherckuith 0:479ce5546098 27 * This file is part of the lwIP TCP/IP stack.
sherckuith 0:479ce5546098 28 *
sherckuith 0:479ce5546098 29 * Author: Adam Dunkels <adam@sics.se>
sherckuith 0:479ce5546098 30 *
sherckuith 0:479ce5546098 31 */
sherckuith 0:479ce5546098 32
sherckuith 0:479ce5546098 33
sherckuith 0:479ce5546098 34 #ifndef __LWIP_SOCKETS_H__
sherckuith 0:479ce5546098 35 #define __LWIP_SOCKETS_H__
sherckuith 0:479ce5546098 36
sherckuith 0:479ce5546098 37 #include "lwip/opt.h"
sherckuith 0:479ce5546098 38
sherckuith 0:479ce5546098 39 #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
sherckuith 0:479ce5546098 40
sherckuith 0:479ce5546098 41 #include <stddef.h> /* for size_t */
sherckuith 0:479ce5546098 42
sherckuith 0:479ce5546098 43 #include "lwip/ip_addr.h"
sherckuith 0:479ce5546098 44 #include "lwip/inet.h"
sherckuith 0:479ce5546098 45
sherckuith 0:479ce5546098 46 #ifdef __cplusplus
sherckuith 0:479ce5546098 47 extern "C" {
sherckuith 0:479ce5546098 48 #endif
sherckuith 0:479ce5546098 49
sherckuith 0:479ce5546098 50 /* members are in network byte order */
sherckuith 0:479ce5546098 51 struct sockaddr_in {
sherckuith 0:479ce5546098 52 u8_t sin_len;
sherckuith 0:479ce5546098 53 u8_t sin_family;
sherckuith 0:479ce5546098 54 u16_t sin_port;
sherckuith 0:479ce5546098 55 struct in_addr sin_addr;
sherckuith 0:479ce5546098 56 char sin_zero[8];
sherckuith 0:479ce5546098 57 };
sherckuith 0:479ce5546098 58
sherckuith 0:479ce5546098 59 struct sockaddr {
sherckuith 0:479ce5546098 60 u8_t sa_len;
sherckuith 0:479ce5546098 61 u8_t sa_family;
sherckuith 0:479ce5546098 62 u16_t sa_data[14];
sherckuith 0:479ce5546098 63 };
sherckuith 0:479ce5546098 64
sherckuith 0:479ce5546098 65 #ifndef socklen_t
sherckuith 0:479ce5546098 66 # define socklen_t u32_t
sherckuith 0:479ce5546098 67 #endif
sherckuith 0:479ce5546098 68
sherckuith 0:479ce5546098 69 /* Socket protocol types (TCP/UDP/RAW) */
sherckuith 0:479ce5546098 70 #define SOCK_STREAM 1
sherckuith 0:479ce5546098 71 #define SOCK_DGRAM 2
sherckuith 0:479ce5546098 72 #define SOCK_RAW 3
sherckuith 0:479ce5546098 73
sherckuith 0:479ce5546098 74 /*
sherckuith 0:479ce5546098 75 * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c)
sherckuith 0:479ce5546098 76 */
sherckuith 0:479ce5546098 77 #define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */
sherckuith 0:479ce5546098 78 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
sherckuith 0:479ce5546098 79 #define SO_REUSEADDR 0x0004 /* Allow local address reuse */
sherckuith 0:479ce5546098 80 #define SO_KEEPALIVE 0x0008 /* keep connections alive */
sherckuith 0:479ce5546098 81 #define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */
sherckuith 0:479ce5546098 82 #define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
sherckuith 0:479ce5546098 83 #define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
sherckuith 0:479ce5546098 84 #define SO_LINGER 0x0080 /* linger on close if data present */
sherckuith 0:479ce5546098 85 #define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */
sherckuith 0:479ce5546098 86 #define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */
sherckuith 0:479ce5546098 87
sherckuith 0:479ce5546098 88 #define SO_DONTLINGER ((int)(~SO_LINGER))
sherckuith 0:479ce5546098 89
sherckuith 0:479ce5546098 90 /*
sherckuith 0:479ce5546098 91 * Additional options, not kept in so_options.
sherckuith 0:479ce5546098 92 */
sherckuith 0:479ce5546098 93 #define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */
sherckuith 0:479ce5546098 94 #define SO_RCVBUF 0x1002 /* receive buffer size */
sherckuith 0:479ce5546098 95 #define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */
sherckuith 0:479ce5546098 96 #define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */
sherckuith 0:479ce5546098 97 #define SO_SNDTIMEO 0x1005 /* Unimplemented: send timeout */
sherckuith 0:479ce5546098 98 #define SO_RCVTIMEO 0x1006 /* receive timeout */
sherckuith 0:479ce5546098 99 #define SO_ERROR 0x1007 /* get error status and clear */
sherckuith 0:479ce5546098 100 #define SO_TYPE 0x1008 /* get socket type */
sherckuith 0:479ce5546098 101 #define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */
sherckuith 0:479ce5546098 102 #define SO_NO_CHECK 0x100a /* don't create UDP checksum */
sherckuith 0:479ce5546098 103
sherckuith 0:479ce5546098 104
sherckuith 0:479ce5546098 105 /*
sherckuith 0:479ce5546098 106 * Structure used for manipulating linger option.
sherckuith 0:479ce5546098 107 */
sherckuith 0:479ce5546098 108 struct linger {
sherckuith 0:479ce5546098 109 int l_onoff; /* option on/off */
sherckuith 0:479ce5546098 110 int l_linger; /* linger time */
sherckuith 0:479ce5546098 111 };
sherckuith 0:479ce5546098 112
sherckuith 0:479ce5546098 113 /*
sherckuith 0:479ce5546098 114 * Level number for (get/set)sockopt() to apply to socket itself.
sherckuith 0:479ce5546098 115 */
sherckuith 0:479ce5546098 116 #define SOL_SOCKET 0xfff /* options for socket level */
sherckuith 0:479ce5546098 117
sherckuith 0:479ce5546098 118
sherckuith 0:479ce5546098 119 #define AF_UNSPEC 0
sherckuith 0:479ce5546098 120 #define AF_INET 2
sherckuith 0:479ce5546098 121 #define PF_INET AF_INET
sherckuith 0:479ce5546098 122 #define PF_UNSPEC AF_UNSPEC
sherckuith 0:479ce5546098 123
sherckuith 0:479ce5546098 124 #define IPPROTO_IP 0
sherckuith 0:479ce5546098 125 #define IPPROTO_TCP 6
sherckuith 0:479ce5546098 126 #define IPPROTO_UDP 17
sherckuith 0:479ce5546098 127 #define IPPROTO_UDPLITE 136
sherckuith 0:479ce5546098 128
sherckuith 0:479ce5546098 129 /* Flags we can use with send and recv. */
sherckuith 0:479ce5546098 130 #define MSG_PEEK 0x01 /* Peeks at an incoming message */
sherckuith 0:479ce5546098 131 #define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
sherckuith 0:479ce5546098 132 #define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
sherckuith 0:479ce5546098 133 #define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */
sherckuith 0:479ce5546098 134 #define MSG_MORE 0x10 /* Sender will send more */
sherckuith 0:479ce5546098 135
sherckuith 0:479ce5546098 136
sherckuith 0:479ce5546098 137 /*
sherckuith 0:479ce5546098 138 * Options for level IPPROTO_IP
sherckuith 0:479ce5546098 139 */
sherckuith 0:479ce5546098 140 #define IP_TOS 1
sherckuith 0:479ce5546098 141 #define IP_TTL 2
sherckuith 0:479ce5546098 142
sherckuith 0:479ce5546098 143 #if LWIP_TCP
sherckuith 0:479ce5546098 144 /*
sherckuith 0:479ce5546098 145 * Options for level IPPROTO_TCP
sherckuith 0:479ce5546098 146 */
sherckuith 0:479ce5546098 147 #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
sherckuith 0:479ce5546098 148 #define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
sherckuith 0:479ce5546098 149 #define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
sherckuith 0:479ce5546098 150 #define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */
sherckuith 0:479ce5546098 151 #define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */
sherckuith 0:479ce5546098 152 #endif /* LWIP_TCP */
sherckuith 0:479ce5546098 153
sherckuith 0:479ce5546098 154 #if LWIP_UDP && LWIP_UDPLITE
sherckuith 0:479ce5546098 155 /*
sherckuith 0:479ce5546098 156 * Options for level IPPROTO_UDPLITE
sherckuith 0:479ce5546098 157 */
sherckuith 0:479ce5546098 158 #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
sherckuith 0:479ce5546098 159 #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
sherckuith 0:479ce5546098 160 #endif /* LWIP_UDP && LWIP_UDPLITE*/
sherckuith 0:479ce5546098 161
sherckuith 0:479ce5546098 162
sherckuith 0:479ce5546098 163 #if LWIP_IGMP
sherckuith 0:479ce5546098 164 /*
sherckuith 0:479ce5546098 165 * Options and types for UDP multicast traffic handling
sherckuith 0:479ce5546098 166 */
sherckuith 0:479ce5546098 167 #define IP_ADD_MEMBERSHIP 3
sherckuith 0:479ce5546098 168 #define IP_DROP_MEMBERSHIP 4
sherckuith 0:479ce5546098 169 #define IP_MULTICAST_TTL 5
sherckuith 0:479ce5546098 170 #define IP_MULTICAST_IF 6
sherckuith 0:479ce5546098 171 #define IP_MULTICAST_LOOP 7
sherckuith 0:479ce5546098 172
sherckuith 0:479ce5546098 173 typedef struct ip_mreq {
sherckuith 0:479ce5546098 174 struct in_addr imr_multiaddr; /* IP multicast address of group */
sherckuith 0:479ce5546098 175 struct in_addr imr_interface; /* local IP address of interface */
sherckuith 0:479ce5546098 176 } ip_mreq;
sherckuith 0:479ce5546098 177 #endif /* LWIP_IGMP */
sherckuith 0:479ce5546098 178
sherckuith 0:479ce5546098 179 /*
sherckuith 0:479ce5546098 180 * The Type of Service provides an indication of the abstract
sherckuith 0:479ce5546098 181 * parameters of the quality of service desired. These parameters are
sherckuith 0:479ce5546098 182 * to be used to guide the selection of the actual service parameters
sherckuith 0:479ce5546098 183 * when transmitting a datagram through a particular network. Several
sherckuith 0:479ce5546098 184 * networks offer service precedence, which somehow treats high
sherckuith 0:479ce5546098 185 * precedence traffic as more important than other traffic (generally
sherckuith 0:479ce5546098 186 * by accepting only traffic above a certain precedence at time of high
sherckuith 0:479ce5546098 187 * load). The major choice is a three way tradeoff between low-delay,
sherckuith 0:479ce5546098 188 * high-reliability, and high-throughput.
sherckuith 0:479ce5546098 189 * The use of the Delay, Throughput, and Reliability indications may
sherckuith 0:479ce5546098 190 * increase the cost (in some sense) of the service. In many networks
sherckuith 0:479ce5546098 191 * better performance for one of these parameters is coupled with worse
sherckuith 0:479ce5546098 192 * performance on another. Except for very unusual cases at most two
sherckuith 0:479ce5546098 193 * of these three indications should be set.
sherckuith 0:479ce5546098 194 */
sherckuith 0:479ce5546098 195 #define IPTOS_TOS_MASK 0x1E
sherckuith 0:479ce5546098 196 #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
sherckuith 0:479ce5546098 197 #define IPTOS_LOWDELAY 0x10
sherckuith 0:479ce5546098 198 #define IPTOS_THROUGHPUT 0x08
sherckuith 0:479ce5546098 199 #define IPTOS_RELIABILITY 0x04
sherckuith 0:479ce5546098 200 #define IPTOS_LOWCOST 0x02
sherckuith 0:479ce5546098 201 #define IPTOS_MINCOST IPTOS_LOWCOST
sherckuith 0:479ce5546098 202
sherckuith 0:479ce5546098 203 /*
sherckuith 0:479ce5546098 204 * The Network Control precedence designation is intended to be used
sherckuith 0:479ce5546098 205 * within a network only. The actual use and control of that
sherckuith 0:479ce5546098 206 * designation is up to each network. The Internetwork Control
sherckuith 0:479ce5546098 207 * designation is intended for use by gateway control originators only.
sherckuith 0:479ce5546098 208 * If the actual use of these precedence designations is of concern to
sherckuith 0:479ce5546098 209 * a particular network, it is the responsibility of that network to
sherckuith 0:479ce5546098 210 * control the access to, and use of, those precedence designations.
sherckuith 0:479ce5546098 211 */
sherckuith 0:479ce5546098 212 #define IPTOS_PREC_MASK 0xe0
sherckuith 0:479ce5546098 213 #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
sherckuith 0:479ce5546098 214 #define IPTOS_PREC_NETCONTROL 0xe0
sherckuith 0:479ce5546098 215 #define IPTOS_PREC_INTERNETCONTROL 0xc0
sherckuith 0:479ce5546098 216 #define IPTOS_PREC_CRITIC_ECP 0xa0
sherckuith 0:479ce5546098 217 #define IPTOS_PREC_FLASHOVERRIDE 0x80
sherckuith 0:479ce5546098 218 #define IPTOS_PREC_FLASH 0x60
sherckuith 0:479ce5546098 219 #define IPTOS_PREC_IMMEDIATE 0x40
sherckuith 0:479ce5546098 220 #define IPTOS_PREC_PRIORITY 0x20
sherckuith 0:479ce5546098 221 #define IPTOS_PREC_ROUTINE 0x00
sherckuith 0:479ce5546098 222
sherckuith 0:479ce5546098 223
sherckuith 0:479ce5546098 224 /*
sherckuith 0:479ce5546098 225 * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
sherckuith 0:479ce5546098 226 * lwip_ioctl only supports FIONREAD and FIONBIO, for now
sherckuith 0:479ce5546098 227 *
sherckuith 0:479ce5546098 228 * Ioctl's have the command encoded in the lower word,
sherckuith 0:479ce5546098 229 * and the size of any in or out parameters in the upper
sherckuith 0:479ce5546098 230 * word. The high 2 bits of the upper word are used
sherckuith 0:479ce5546098 231 * to encode the in/out status of the parameter; for now
sherckuith 0:479ce5546098 232 * we restrict parameters to at most 128 bytes.
sherckuith 0:479ce5546098 233 */
sherckuith 0:479ce5546098 234 #if !defined(FIONREAD) || !defined(FIONBIO)
sherckuith 0:479ce5546098 235 #define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */
sherckuith 0:479ce5546098 236 #define IOC_VOID 0x20000000UL /* no parameters */
sherckuith 0:479ce5546098 237 #define IOC_OUT 0x40000000UL /* copy out parameters */
sherckuith 0:479ce5546098 238 #define IOC_IN 0x80000000UL /* copy in parameters */
sherckuith 0:479ce5546098 239 #define IOC_INOUT (IOC_IN|IOC_OUT)
sherckuith 0:479ce5546098 240 /* 0x20000000 distinguishes new &
sherckuith 0:479ce5546098 241 old ioctl's */
sherckuith 0:479ce5546098 242 #define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
sherckuith 0:479ce5546098 243
sherckuith 0:479ce5546098 244 #define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
sherckuith 0:479ce5546098 245
sherckuith 0:479ce5546098 246 #define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
sherckuith 0:479ce5546098 247 #endif /* !defined(FIONREAD) || !defined(FIONBIO) */
sherckuith 0:479ce5546098 248
sherckuith 0:479ce5546098 249 #ifndef FIONREAD
sherckuith 0:479ce5546098 250 #define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */
sherckuith 0:479ce5546098 251 #endif
sherckuith 0:479ce5546098 252 #ifndef FIONBIO
sherckuith 0:479ce5546098 253 #define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
sherckuith 0:479ce5546098 254 #endif
sherckuith 0:479ce5546098 255
sherckuith 0:479ce5546098 256 /* Socket I/O Controls: unimplemented */
sherckuith 0:479ce5546098 257 #ifndef SIOCSHIWAT
sherckuith 0:479ce5546098 258 #define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */
sherckuith 0:479ce5546098 259 #define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */
sherckuith 0:479ce5546098 260 #define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */
sherckuith 0:479ce5546098 261 #define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */
sherckuith 0:479ce5546098 262 #define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */
sherckuith 0:479ce5546098 263 #endif
sherckuith 0:479ce5546098 264
sherckuith 0:479ce5546098 265 /* commands for fnctl */
sherckuith 0:479ce5546098 266 #ifndef F_GETFL
sherckuith 0:479ce5546098 267 #define F_GETFL 3
sherckuith 0:479ce5546098 268 #endif
sherckuith 0:479ce5546098 269 #ifndef F_SETFL
sherckuith 0:479ce5546098 270 #define F_SETFL 4
sherckuith 0:479ce5546098 271 #endif
sherckuith 0:479ce5546098 272
sherckuith 0:479ce5546098 273 /* File status flags and file access modes for fnctl,
sherckuith 0:479ce5546098 274 these are bits in an int. */
sherckuith 0:479ce5546098 275 #ifndef O_NONBLOCK
sherckuith 0:479ce5546098 276 #define O_NONBLOCK 1 /* nonblocking I/O */
sherckuith 0:479ce5546098 277 #endif
sherckuith 0:479ce5546098 278 #ifndef O_NDELAY
sherckuith 0:479ce5546098 279 #define O_NDELAY 1 /* same as O_NONBLOCK, for compatibility */
sherckuith 0:479ce5546098 280 #endif
sherckuith 0:479ce5546098 281
sherckuith 0:479ce5546098 282 #ifndef SHUT_RD
sherckuith 0:479ce5546098 283 #define SHUT_RD 1
sherckuith 0:479ce5546098 284 #define SHUT_WR 2
sherckuith 0:479ce5546098 285 #define SHUT_RDWR 3
sherckuith 0:479ce5546098 286 #endif
sherckuith 0:479ce5546098 287
sherckuith 0:479ce5546098 288 /* FD_SET used for lwip_select */
sherckuith 0:479ce5546098 289 #ifndef FD_SET
sherckuith 0:479ce5546098 290 #undef FD_SETSIZE
sherckuith 0:479ce5546098 291 /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
sherckuith 0:479ce5546098 292 #define FD_SETSIZE MEMP_NUM_NETCONN
sherckuith 0:479ce5546098 293 #define FD_SET(n, p) ((p)->fd_bits[(n)/8] |= (1 << ((n) & 7)))
sherckuith 0:479ce5546098 294 #define FD_CLR(n, p) ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
sherckuith 0:479ce5546098 295 #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] & (1 << ((n) & 7)))
sherckuith 0:479ce5546098 296 #define FD_ZERO(p) memset((void*)(p),0,sizeof(*(p)))
sherckuith 0:479ce5546098 297
sherckuith 0:479ce5546098 298 typedef struct fd_set {
sherckuith 0:479ce5546098 299 unsigned char fd_bits [(FD_SETSIZE+7)/8];
sherckuith 0:479ce5546098 300 } fd_set;
sherckuith 0:479ce5546098 301
sherckuith 0:479ce5546098 302 #endif /* FD_SET */
sherckuith 0:479ce5546098 303
sherckuith 0:479ce5546098 304 /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
sherckuith 0:479ce5546098 305 * by your system, set this to 0 and include <sys/time.h> in cc.h */
sherckuith 0:479ce5546098 306 #ifndef LWIP_TIMEVAL_PRIVATE
sherckuith 0:479ce5546098 307 #define LWIP_TIMEVAL_PRIVATE 1
sherckuith 0:479ce5546098 308 #endif
sherckuith 0:479ce5546098 309
sherckuith 0:479ce5546098 310 #if LWIP_TIMEVAL_PRIVATE
sherckuith 0:479ce5546098 311 struct timeval {
sherckuith 0:479ce5546098 312 long tv_sec; /* seconds */
sherckuith 0:479ce5546098 313 long tv_usec; /* and microseconds */
sherckuith 0:479ce5546098 314 };
sherckuith 0:479ce5546098 315 #endif /* LWIP_TIMEVAL_PRIVATE */
sherckuith 0:479ce5546098 316
sherckuith 0:479ce5546098 317 void lwip_socket_init(void);
sherckuith 0:479ce5546098 318
sherckuith 0:479ce5546098 319 int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
sherckuith 0:479ce5546098 320 int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen);
sherckuith 0:479ce5546098 321 int lwip_shutdown(int s, int how);
sherckuith 0:479ce5546098 322 int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen);
sherckuith 0:479ce5546098 323 int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen);
sherckuith 0:479ce5546098 324 int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
sherckuith 0:479ce5546098 325 int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
sherckuith 0:479ce5546098 326 int lwip_close(int s);
sherckuith 0:479ce5546098 327 int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen);
sherckuith 0:479ce5546098 328 int lwip_listen(int s, int backlog);
sherckuith 0:479ce5546098 329 int lwip_recv(int s, void *mem, size_t len, int flags);
sherckuith 0:479ce5546098 330 int lwip_read(int s, void *mem, size_t len);
sherckuith 0:479ce5546098 331 int lwip_recvfrom(int s, void *mem, size_t len, int flags,
sherckuith 0:479ce5546098 332 struct sockaddr *from, socklen_t *fromlen);
sherckuith 0:479ce5546098 333 int lwip_send(int s, const void *dataptr, size_t size, int flags);
sherckuith 0:479ce5546098 334 int lwip_sendto(int s, const void *dataptr, size_t size, int flags,
sherckuith 0:479ce5546098 335 const struct sockaddr *to, socklen_t tolen);
sherckuith 0:479ce5546098 336 int lwip_socket(int domain, int type, int protocol);
sherckuith 0:479ce5546098 337 int lwip_write(int s, const void *dataptr, size_t size);
sherckuith 0:479ce5546098 338 int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
sherckuith 0:479ce5546098 339 struct timeval *timeout);
sherckuith 0:479ce5546098 340 int lwip_ioctl(int s, long cmd, void *argp);
sherckuith 0:479ce5546098 341 int lwip_fcntl(int s, int cmd, int val);
sherckuith 0:479ce5546098 342
sherckuith 0:479ce5546098 343 #if LWIP_COMPAT_SOCKETS
sherckuith 0:479ce5546098 344 #define accept(a,b,c) lwip_accept(a,b,c)
sherckuith 0:479ce5546098 345 #define bind(a,b,c) lwip_bind(a,b,c)
sherckuith 0:479ce5546098 346 #define shutdown(a,b) lwip_shutdown(a,b)
sherckuith 0:479ce5546098 347 #define closesocket(s) lwip_close(s)
sherckuith 0:479ce5546098 348 #define connect(a,b,c) lwip_connect(a,b,c)
sherckuith 0:479ce5546098 349 #define getsockname(a,b,c) lwip_getsockname(a,b,c)
sherckuith 0:479ce5546098 350 #define getpeername(a,b,c) lwip_getpeername(a,b,c)
sherckuith 0:479ce5546098 351 #define setsockopt(a,b,c,d,e) lwip_setsockopt(a,b,c,d,e)
sherckuith 0:479ce5546098 352 #define getsockopt(a,b,c,d,e) lwip_getsockopt(a,b,c,d,e)
sherckuith 0:479ce5546098 353 #define listen(a,b) lwip_listen(a,b)
sherckuith 0:479ce5546098 354 #define recv(a,b,c,d) lwip_recv(a,b,c,d)
sherckuith 0:479ce5546098 355 #define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f)
sherckuith 0:479ce5546098 356 #define send(a,b,c,d) lwip_send(a,b,c,d)
sherckuith 0:479ce5546098 357 #define sendto(a,b,c,d,e,f) lwip_sendto(a,b,c,d,e,f)
sherckuith 0:479ce5546098 358 #define socket(a,b,c) lwip_socket(a,b,c)
sherckuith 0:479ce5546098 359 #define select(a,b,c,d,e) lwip_select(a,b,c,d,e)
sherckuith 0:479ce5546098 360 #define ioctlsocket(a,b,c) lwip_ioctl(a,b,c)
sherckuith 0:479ce5546098 361
sherckuith 0:479ce5546098 362 #if LWIP_POSIX_SOCKETS_IO_NAMES
sherckuith 0:479ce5546098 363 #define read(a,b,c) lwip_read(a,b,c)
sherckuith 0:479ce5546098 364 #define write(a,b,c) lwip_write(a,b,c)
sherckuith 0:479ce5546098 365 #define close(s) lwip_close(s)
sherckuith 0:479ce5546098 366 #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
sherckuith 0:479ce5546098 367
sherckuith 0:479ce5546098 368 #endif /* LWIP_COMPAT_SOCKETS */
sherckuith 0:479ce5546098 369
sherckuith 0:479ce5546098 370 #ifdef __cplusplus
sherckuith 0:479ce5546098 371 }
sherckuith 0:479ce5546098 372 #endif
sherckuith 0:479ce5546098 373
sherckuith 0:479ce5546098 374 #endif /* LWIP_SOCKET */
sherckuith 0:479ce5546098 375
sherckuith 0:479ce5546098 376 #endif /* __LWIP_SOCKETS_H__ */