]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/blob - src/include/lwip/sockets.h
inet_ntoa and inet_aton from Marc
[pes-rpp/rpp-lwip.git] / src / include / lwip / sockets.h
1 /*
2  * Copyright (c) 2001-2003 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 #include "lwip/ip_addr.h"
37
38 struct sockaddr_in {
39   u8_t sin_len;
40   u8_t sin_family;
41   u16_t sin_port;
42   struct in_addr sin_addr;
43   char sin_zero[8];
44 };
45
46 struct sockaddr {
47   u8_t sa_len;
48   u8_t sa_family;
49   char sa_data[14];
50 };
51
52 #ifndef socklen_t
53 #  define socklen_t int
54 #endif
55
56
57 #define SOCK_STREAM     1
58 #define SOCK_DGRAM      2
59 #define SOCK_RAW        3
60
61 /*
62  * Option flags per-socket.
63  */
64 #define SO_DEBUG        0x0001          /* turn on debugging info recording */
65 #define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
66 #define SO_REUSEADDR    0x0004          /* allow local address reuse */
67 #define SO_KEEPALIVE    0x0008          /* keep connections alive */
68 #define SO_DONTROUTE    0x0010          /* just use interface addresses */
69 #define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
70 #define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
71 #define SO_LINGER       0x0080          /* linger on close if data present */
72 #define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
73
74 #define SO_DONTLINGER   (int)(~SO_LINGER)
75
76 /*
77  * Additional options, not kept in so_options.
78  */
79 #define SO_SNDBUF       0x1001          /* send buffer size */
80 #define SO_RCVBUF       0x1002          /* receive buffer size */
81 #define SO_SNDLOWAT     0x1003          /* send low-water mark */
82 #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
83 #define SO_SNDTIMEO     0x1005          /* send timeout */
84 #define SO_RCVTIMEO     0x1006          /* receive timeout */
85 #define SO_ERROR        0x1007          /* get error status and clear */
86 #define SO_TYPE         0x1008          /* get socket type */
87
88
89
90 /*
91  * Structure used for manipulating linger option.
92  */
93 struct linger {
94        int l_onoff;                /* option on/off */
95        int l_linger;               /* linger time */
96 };
97
98 /*
99  * Level number for (get/set)sockopt() to apply to socket itself.
100  */
101 #define SOL_SOCKET      0xfff           /* options for socket level */
102
103
104 #define AF_UNSPEC       0
105 #define AF_INET         2
106 #define PF_INET         AF_INET
107 #define PF_UNSPEC       AF_UNSPEC
108
109 #define IPPROTO_IP      0
110 #define IPPROTO_TCP     6
111 #define IPPROTO_UDP     17
112
113 #define INADDR_ANY      0
114 #define INADDR_BROADCAST 0xffffffff
115
116 /* Flags we can use with send and recv. */
117 #define MSG_DONTWAIT    0x40            /* Nonblocking i/o for this operation only */
118
119
120 /*
121  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
122  *
123  *
124  * Ioctl's have the command encoded in the lower word,
125  * and the size of any in or out parameters in the upper
126  * word.  The high 2 bits of the upper word are used
127  * to encode the in/out status of the parameter; for now
128  * we restrict parameters to at most 128 bytes.
129  */
130 #if !defined(FIONREAD) || !defined(FIONBIO)
131 #define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
132 #define IOC_VOID        0x20000000      /* no parameters */
133 #define IOC_OUT         0x40000000      /* copy out parameters */
134 #define IOC_IN          0x80000000      /* copy in parameters */
135 #define IOC_INOUT       (IOC_IN|IOC_OUT)
136                                         /* 0x20000000 distinguishes new &
137                                            old ioctl's */
138 #define _IO(x,y)        (IOC_VOID|((x)<<8)|(y))
139
140 #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
141
142 #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
143 #endif
144
145 #ifndef FIONREAD
146 #define FIONREAD    _IOR('f', 127, unsigned long) /* get # bytes to read */
147 #endif
148 #ifndef FIONBIO
149 #define FIONBIO     _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
150 #endif
151
152 /* Socket I/O Controls */
153 #ifndef SIOCSHIWAT
154 #define SIOCSHIWAT  _IOW('s',  0, unsigned long)  /* set high watermark */
155 #define SIOCGHIWAT  _IOR('s',  1, unsigned long)  /* get high watermark */
156 #define SIOCSLOWAT  _IOW('s',  2, unsigned long)  /* set low watermark */
157 #define SIOCGLOWAT  _IOR('s',  3, unsigned long)  /* get low watermark */
158 #define SIOCATMARK  _IOR('s',  7, unsigned long)  /* at oob mark? */
159 #endif
160
161 #ifndef O_NONBLOCK
162 #define O_NONBLOCK    04000U
163 #endif
164
165 #ifndef FD_SET
166   #undef  FD_SETSIZE
167   #define FD_SETSIZE    16
168   #define FD_SET(n, p)  ((p)->fd_bits[(n)/8] |=  (1 << ((n) & 7)))
169   #define FD_CLR(n, p)  ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
170   #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] &   (1 << ((n) & 7)))
171   #define FD_ZERO(p)    memset((void*)(p),0,sizeof(*(p)))
172
173   typedef struct fd_set {
174           unsigned char fd_bits [(FD_SETSIZE+7)/8];
175         } fd_set;
176
177   struct timeval {
178           long    tv_sec;         /* seconds */
179           long    tv_usec;        /* and microseconds */
180   };
181
182 #endif
183
184 int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
185 int lwip_bind(int s, struct sockaddr *name, socklen_t namelen);
186 int lwip_shutdown(int s, int how);
187 int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen);
188 int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen);
189 int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
190 int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
191 int lwip_close(int s);
192 int lwip_connect(int s, struct sockaddr *name, socklen_t namelen);
193 int lwip_listen(int s, int backlog);
194 int lwip_recv(int s, void *mem, int len, unsigned int flags);
195 int lwip_read(int s, void *mem, int len);
196 int lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
197                   struct sockaddr *from, socklen_t *fromlen);
198 int lwip_send(int s, void *dataptr, int size, unsigned int flags);
199 int lwip_sendto(int s, void *dataptr, int size, unsigned int flags,
200                 struct sockaddr *to, socklen_t tolen);
201 int lwip_socket(int domain, int type, int protocol);
202 int lwip_write(int s, void *dataptr, int size);
203 int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
204                 struct timeval *timeout);
205 int lwip_ioctl(int s, long cmd, void *argp);
206
207 #if LWIP_COMPAT_SOCKETS
208 #define accept(a,b,c)         lwip_accept(a,b,c)
209 #define bind(a,b,c)           lwip_bind(a,b,c)
210 #define shutdown(a,b)         lwip_shutdown(a,b)
211 #define close(s)              lwip_close(s)
212 #define connect(a,b,c)        lwip_connect(a,b,c)
213 #define getsockname(a,b,c)    lwip_getsockname(a,b,c)
214 #define getpeername(a,b,c)    lwip_getpeername(a,b,c)
215 #define setsockopt(a,b,c,d,e) lwip_setsockopt(a,b,c,d,e)
216 #define getsockopt(a,b,c,d,e) lwip_getsockopt(a,b,c,d,e)
217 #define listen(a,b)           lwip_listen(a,b)
218 #define recv(a,b,c,d)         lwip_recv(a,b,c,d)
219 #define read(a,b,c)           lwip_read(a,b,c)
220 #define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f)
221 #define send(a,b,c,d)         lwip_send(a,b,c,d)
222 #define sendto(a,b,c,d,e,f)   lwip_sendto(a,b,c,d,e,f)
223 #define socket(a,b,c)         lwip_socket(a,b,c)
224 #define write(a,b,c)          lwip_write(a,b,c)
225 #define select(a,b,c,d,e)     lwip_select(a,b,c,d,e)
226 #define ioctlsocket(a,b,c)    lwip_ioctl(a,b,c)
227 #endif /* LWIP_COMPAT_SOCKETS */
228
229 #endif /* __LWIP_SOCKETS_H__ */
230