Onenet

Dependents:   K64F_eCompass_OneNET_JW

Committer:
robert_jw
Date:
Mon Jun 20 01:40:20 2016 +0000
Revision:
0:b2805b6888dc
ADS

Who changed what in which revision?

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