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