PageRenderTime 72ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/firmware/at91sam7/openbeacon-ethernet/network/src/include/lwip/sockets.h

https://github.com/meriac/openbeacon
C Header | 346 lines | 216 code | 50 blank | 80 comment | 2 complexity | b8713639cf977516c86be7217b673f9e MD5 | raw file
  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. #ifndef __LWIP_SOCKETS_H__
  33. #define __LWIP_SOCKETS_H__
  34. #include "lwip/opt.h"
  35. #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
  36. #include "lwip/ip_addr.h"
  37. #include "lwip/inet.h"
  38. #ifdef __cplusplus
  39. extern "C"
  40. {
  41. #endif
  42. /* members are in network byte order */
  43. struct sockaddr_in
  44. {
  45. u8_t sin_len;
  46. u8_t sin_family;
  47. u16_t sin_port;
  48. struct in_addr sin_addr;
  49. char sin_zero[8];
  50. };
  51. struct sockaddr
  52. {
  53. u8_t sa_len;
  54. u8_t sa_family;
  55. char sa_data[14];
  56. };
  57. #ifndef socklen_t
  58. # define socklen_t u32_t
  59. #endif
  60. /* Socket protocol types (TCP/UDP/RAW) */
  61. #define SOCK_STREAM 1
  62. #define SOCK_DGRAM 2
  63. #define SOCK_RAW 3
  64. /*
  65. * Option flags per-socket. These must match the SOF_ flags in ip.h!
  66. */
  67. #define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */
  68. #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
  69. #define SO_REUSEADDR 0x0004 /* Unimplemented: allow local address reuse */
  70. #define SO_KEEPALIVE 0x0008 /* keep connections alive */
  71. #define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */
  72. #define SO_BROADCAST 0x0020 /* Unimplemented: permit sending of broadcast msgs */
  73. #define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
  74. #define SO_LINGER 0x0080 /* linger on close if data present */
  75. #define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */
  76. #define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */
  77. #define SO_DONTLINGER ((int)(~SO_LINGER))
  78. /*
  79. * Additional options, not kept in so_options.
  80. */
  81. #define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */
  82. #define SO_RCVBUF 0x1002 /* receive buffer size */
  83. #define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */
  84. #define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */
  85. #define SO_SNDTIMEO 0x1005 /* Unimplemented: send timeout */
  86. #define SO_RCVTIMEO 0x1006 /* receive timeout */
  87. #define SO_ERROR 0x1007 /* get error status and clear */
  88. #define SO_TYPE 0x1008 /* get socket type */
  89. #define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */
  90. #define SO_NO_CHECK 0x100a /* don't create UDP checksum */
  91. /*
  92. * Structure used for manipulating linger option.
  93. */
  94. struct linger
  95. {
  96. int l_onoff; /* option on/off */
  97. int l_linger; /* linger time */
  98. };
  99. /*
  100. * Level number for (get/set)sockopt() to apply to socket itself.
  101. */
  102. #define SOL_SOCKET 0xfff /* options for socket level */
  103. #define AF_UNSPEC 0
  104. #define AF_INET 2
  105. #define PF_INET AF_INET
  106. #define PF_UNSPEC AF_UNSPEC
  107. #define IPPROTO_IP 0
  108. #define IPPROTO_TCP 6
  109. #define IPPROTO_UDP 17
  110. #define IPPROTO_UDPLITE 136
  111. #define INADDR_ANY 0
  112. #define INADDR_BROADCAST 0xffffffff
  113. /* Flags we can use with send and recv. */
  114. #define MSG_PEEK 0x01 /* Peeks at an incoming message */
  115. #define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
  116. #define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
  117. #define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */
  118. #define MSG_MORE 0x10 /* Sender will send more */
  119. /*
  120. * Options for level IPPROTO_IP
  121. */
  122. #define IP_TOS 1
  123. #define IP_TTL 2
  124. #if LWIP_TCP
  125. /*
  126. * Options for level IPPROTO_TCP
  127. */
  128. #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
  129. #define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
  130. #define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
  131. #define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */
  132. #define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */
  133. #endif /* LWIP_TCP */
  134. #if LWIP_UDP && LWIP_UDPLITE
  135. /*
  136. * Options for level IPPROTO_UDPLITE
  137. */
  138. #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
  139. #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
  140. #endif /* LWIP_UDP && LWIP_UDPLITE */
  141. #if LWIP_IGMP
  142. /*
  143. * Options and types for UDP multicast traffic handling
  144. */
  145. #define IP_ADD_MEMBERSHIP 3
  146. #define IP_DROP_MEMBERSHIP 4
  147. #define IP_MULTICAST_TTL 5
  148. #define IP_MULTICAST_IF 6
  149. #define IP_MULTICAST_LOOP 7
  150. typedef struct ip_mreq
  151. {
  152. struct in_addr imr_multiaddr; /* IP multicast address of group */
  153. struct in_addr imr_interface; /* local IP address of interface */
  154. } ip_mreq;
  155. #endif /* LWIP_IGMP */
  156. /* Unimplemented for now... */
  157. #define IPTOS_TOS_MASK 0x1E
  158. #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
  159. #define IPTOS_LOWDELAY 0x10
  160. #define IPTOS_THROUGHPUT 0x08
  161. #define IPTOS_RELIABILITY 0x04
  162. #define IPTOS_LOWCOST 0x02
  163. #define IPTOS_MINCOST IPTOS_LOWCOST
  164. /*
  165. * Definitions for IP precedence (also in ip_tos) (Unimplemented)
  166. */
  167. #define IPTOS_PREC_MASK 0xe0
  168. #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
  169. #define IPTOS_PREC_NETCONTROL 0xe0
  170. #define IPTOS_PREC_INTERNETCONTROL 0xc0
  171. #define IPTOS_PREC_CRITIC_ECP 0xa0
  172. #define IPTOS_PREC_FLASHOVERRIDE 0x80
  173. #define IPTOS_PREC_FLASH 0x60
  174. #define IPTOS_PREC_IMMEDIATE 0x40
  175. #define IPTOS_PREC_PRIORITY 0x20
  176. #define IPTOS_PREC_ROUTINE 0x00
  177. /*
  178. * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
  179. * lwip_ioctl only supports FIONREAD and FIONBIO, for now
  180. *
  181. * Ioctl's have the command encoded in the lower word,
  182. * and the size of any in or out parameters in the upper
  183. * word. The high 2 bits of the upper word are used
  184. * to encode the in/out status of the parameter; for now
  185. * we restrict parameters to at most 128 bytes.
  186. */
  187. #if !defined(FIONREAD) || !defined(FIONBIO)
  188. #define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */
  189. #define IOC_VOID 0x20000000UL /* no parameters */
  190. #define IOC_OUT 0x40000000UL /* copy out parameters */
  191. #define IOC_IN 0x80000000UL /* copy in parameters */
  192. #define IOC_INOUT (IOC_IN|IOC_OUT)
  193. /* 0x20000000 distinguishes new &
  194. old ioctl's */
  195. #define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
  196. #define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  197. #define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  198. #endif /* !defined(FIONREAD) || !defined(FIONBIO) */
  199. #ifndef FIONREAD
  200. #define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */
  201. #endif
  202. #ifndef FIONBIO
  203. #define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
  204. #endif
  205. /* Socket I/O Controls: unimplemented */
  206. #ifndef SIOCSHIWAT
  207. #define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */
  208. #define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */
  209. #define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */
  210. #define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */
  211. #define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */
  212. #endif
  213. /* Socket flags: */
  214. #ifndef O_NONBLOCK
  215. #define O_NONBLOCK 04000U
  216. #endif
  217. /* FD_SET used for lwip_select */
  218. #ifndef FD_SET
  219. #undef FD_SETSIZE
  220. /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
  221. #define FD_SETSIZE MEMP_NUM_NETCONN
  222. #define FD_SET(n, p) ((p)->fd_bits[(n)/8] |= (1 << ((n) & 7)))
  223. #define FD_CLR(n, p) ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
  224. #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] & (1 << ((n) & 7)))
  225. #define FD_ZERO(p) memset((void*)(p),0,sizeof(*(p)))
  226. typedef struct fd_set
  227. {
  228. unsigned char fd_bits[(FD_SETSIZE + 7) / 8];
  229. } fd_set;
  230. #endif /* FD_SET */
  231. /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
  232. * by your system, set this to 0 and include <sys/time.h> in cc.h */
  233. #ifndef LWIP_TIMEVAL_PRIVATE
  234. #define LWIP_TIMEVAL_PRIVATE 1
  235. #endif
  236. #if LWIP_TIMEVAL_PRIVATE
  237. struct timeval
  238. {
  239. long tv_sec; /* seconds */
  240. long tv_usec; /* and microseconds */
  241. };
  242. #endif /* LWIP_TIMEVAL_PRIVATE */
  243. void lwip_socket_init (void);
  244. int lwip_accept (int s, struct sockaddr *addr, socklen_t * addrlen);
  245. int lwip_bind (int s, struct sockaddr *name, socklen_t namelen);
  246. int lwip_shutdown (int s, int how);
  247. int lwip_getpeername (int s, struct sockaddr *name, socklen_t * namelen);
  248. int lwip_getsockname (int s, struct sockaddr *name, socklen_t * namelen);
  249. int lwip_getsockopt (int s, int level, int optname, void *optval,
  250. socklen_t * optlen);
  251. int lwip_setsockopt (int s, int level, int optname, const void *optval,
  252. socklen_t optlen);
  253. int lwip_close (int s);
  254. int lwip_connect (int s, const struct sockaddr *name, socklen_t namelen);
  255. int lwip_listen (int s, int backlog);
  256. int lwip_recv (int s, void *mem, int len, unsigned int flags);
  257. int lwip_read (int s, void *mem, int len);
  258. int lwip_recvfrom (int s, void *mem, int len, unsigned int flags,
  259. struct sockaddr *from, socklen_t * fromlen);
  260. int lwip_send (int s, const void *dataptr, int size, unsigned int flags);
  261. int lwip_sendto (int s, const void *dataptr, int size, unsigned int flags,
  262. struct sockaddr *to, socklen_t tolen);
  263. int lwip_socket (int domain, int type, int protocol);
  264. int lwip_write (int s, const void *dataptr, int size);
  265. int lwip_select (int maxfdp1, fd_set * readset, fd_set * writeset,
  266. fd_set * exceptset, struct timeval *timeout);
  267. int lwip_ioctl (int s, long cmd, void *argp);
  268. #if LWIP_COMPAT_SOCKETS
  269. #define accept(a,b,c) lwip_accept(a,b,c)
  270. #define bind(a,b,c) lwip_bind(a,b,c)
  271. #define shutdown(a,b) lwip_shutdown(a,b)
  272. #define closesocket(s) lwip_close(s)
  273. #define connect(a,b,c) lwip_connect(a,b,c)
  274. #define getsockname(a,b,c) lwip_getsockname(a,b,c)
  275. #define getpeername(a,b,c) lwip_getpeername(a,b,c)
  276. #define setsockopt(a,b,c,d,e) lwip_setsockopt(a,b,c,d,e)
  277. #define getsockopt(a,b,c,d,e) lwip_getsockopt(a,b,c,d,e)
  278. #define listen(a,b) lwip_listen(a,b)
  279. #define recv(a,b,c,d) lwip_recv(a,b,c,d)
  280. #define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f)
  281. #define send(a,b,c,d) lwip_send(a,b,c,d)
  282. #define sendto(a,b,c,d,e,f) lwip_sendto(a,b,c,d,e,f)
  283. #define socket(a,b,c) lwip_socket(a,b,c)
  284. #define select(a,b,c,d,e) lwip_select(a,b,c,d,e)
  285. #define ioctlsocket(a,b,c) lwip_ioctl(a,b,c)
  286. #if LWIP_POSIX_SOCKETS_IO_NAMES
  287. #define read(a,b,c) lwip_read(a,b,c)
  288. #define write(a,b,c) lwip_write(a,b,c)
  289. #define close(s) lwip_close(s)
  290. #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
  291. #endif /* LWIP_COMPAT_SOCKETS */
  292. #ifdef __cplusplus
  293. }
  294. #endif
  295. #endif /* LWIP_SOCKET */
  296. #endif /* __LWIP_SOCKETS_H__ */