PageRenderTime 96ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/MicroFrameworkPK_v4_1/DeviceCode/pal/rtip/rtpcore/rtpnet.h

https://bitbucket.org/pmfsampaio/netmf-lpc
C Header | 304 lines | 221 code | 33 blank | 50 comment | 0 complexity | e5cdc4b1aefb6264f11f7e79349b901c MD5 | raw file
  1. /*
  2. | RTPNET.H - Runtime Platform Services
  3. |
  4. | UNIVERSAL CODE - DO NOT CHANGE
  5. |
  6. | EBSnet - RT-Platform
  7. |
  8. | $Author: vmalaiya $
  9. | $Date: 2004/12/09 21:05:04 $
  10. | $Name: $
  11. | $Revision: 1.3 $
  12. |
  13. | Copyright EBSnet Inc. , 2003
  14. | All rights reserved.
  15. | This code may not be redistributed in source or linkable object form
  16. | without the consent of its author.
  17. |
  18. | Module description:
  19. | [tbd]
  20. */
  21. #ifndef __RTPNET_H__
  22. #define __RTPNET_H__
  23. #include "rtp.h"
  24. #include "rtip.h"
  25. typedef RTP_HANDLE RTP_SOCKET;
  26. /************************************************************************
  27. * Defines
  28. ************************************************************************/
  29. #define RTP_FD_SET_MAX 64
  30. #define RTP_NET_TYPE_IPV4 4
  31. #define RTP_NET_TYPE_IPV6 6
  32. #define RTP_NET_IP_ALEN 4
  33. #define RTP_NET_AF_INET AF_INET
  34. #define RTP_NET_SOCK_STREAM SOCK_STREAM
  35. #define RTP_NET_SOCK_DGRAM SOCK_DGRAM
  36. #define RTP_NET_SOCK_RAW SOCK_RAW
  37. #define RTP_NET_SOCK_RDM SOCK_RDM
  38. #define RTP_NET_SOCK_SEQPACKET SOCK_SEQPACKET
  39. #define RTP_NET_EADDRNOTAVAIL EADDRNOTAVAIL
  40. #define RTP_NET_EADDRINUSE EADDRINUSE
  41. #define RTP_NET_EAFNOSUPPORT EAFNOSUPPORT
  42. #define RTP_NET_EARPFULL EARPFULL
  43. #define RTP_NET_EBADBAUD EBADBAUD
  44. #define RTP_NET_EBADCOMMNUM EBADCOMMNUM
  45. #define RTP_NET_EBADDEVICE EBADDEVICE
  46. #define RTP_NET_EBADIFACE EBADIFACE
  47. #define RTP_NET_EBADMASK EBADMASK
  48. #define RTP_NET_EBADRESP EBADRESP
  49. #define RTP_NET_ECONNREFUSED ECONNREFUSED
  50. #define RTP_NET_EDESTADDREQ EDESTADDREQ
  51. #define RTP_NET_EDESTUNREACH EDESTUNREACH
  52. #define RTP_NET_EFAULT EFAULT
  53. #define RTP_NET_EIFACECLOSED EIFACECLOSED
  54. #define RTP_NET_EIFACEFULL EIFACEFULL
  55. #define RTP_NET_EIFACEOPENFAIL EIFACEOPENFAIL
  56. #define RTP_NET_EINPROGRESS EINPROGRESS
  57. #define RTP_NET_EINVAL EINVAL
  58. #define RTP_NET_EISCONN EISCONN
  59. #define RTP_NET_EMCASTFULL EMCASTFULL
  60. #define RTP_NET_EMCASTNOTFOUND EMCASTNOTFOUND
  61. #define RTP_NET_EMFILE EMFILE
  62. #define RTP_NET_ENETDOWN ENETDOWN
  63. #define RTP_NET_ENETUNREACH ENETUNREACH
  64. #define RTP_NET_ENOPKTS ENOPKTS
  65. #define RTP_NET_ENOPROTOOPT ENOPROTOOPT
  66. #define RTP_NET_ENOTCONN ENOTCONN
  67. #define RTP_NET_ENOTINITIALIZED ENOTINITIALIZED
  68. #define RTP_NET_ENOTSOCK ENOTSOCK
  69. #define RTP_NET_ENUMDEVICE ENUMDEVICE
  70. #define RTP_NET_EOPNOTSUPPORT EOPNOTSUPPORT
  71. #define RTP_NET_EOUTPUTFULL EOUTPUTFULL
  72. #define RTP_NET_EPROBEFAIL EPROBEFAIL
  73. #define RTP_NET_ERENTRANT ERENTRANT
  74. #define RTP_NET_ERTNOTFOUND ERTNOTFOUND
  75. #define RTP_NET_ERTFULL ERTFULL
  76. #define RTP_NET_ERSCINITFAIL ERSCINITFAIL
  77. #define RTP_NET_ESHUTDOWN ESHUTDOWN
  78. #define RTP_NET_ETIMEDOUT ETIMEDOUT
  79. #define RTP_NET_ETNOSUPPORT ETNOSUPPORT
  80. #define RTP_NET_EWOULDARP EWOULDARP
  81. #define RTP_NET_EWOULDBLOCK EWOULDBLOCK
  82. #define RTP_NET_EOUTAMEM EOUTAMEM
  83. #define RTP_NET_ETABLEFULL ETABLEFULL
  84. #define RTP_NET_EMSGSIZE EMSGSIZE
  85. #define RTP_NET_EDEVOPENFAIL EDEVOPENFAIL
  86. #define RTP_NET_EPFNOSUPPORT EPFNOSUPPORT
  87. #define RTP_NET_EPROTONOSUPPORT EPROTONOSUPPORT
  88. #define RTP_NET_EHTABLEFULL EHTABLEFULL
  89. #define RTP_NET_EENTRYNOTFOUND EENTRYNOTFOUND
  90. #define RTP_NET_ETOOMANYSERVERS ETOOMANYSERVERS
  91. #define RTP_NET_ENO_RECOVERY ENO_RECOVERY
  92. #define RTP_NET_ENAME_TOO_LONG ENAME_TOO_LONG
  93. #define RTP_NET_ETRYAGAIN ETRYAGAIN
  94. #define RTP_NET_ENODATA ENODATA
  95. #define RTP_NET_ENORESPONSE ENORESPONSE
  96. #define RTP_NET_ENOSERVERS ENOSERVERS
  97. #define RTP_NET_EDHCPSERVNORESP EDHCPSERVNORESP
  98. #define RTP_NET_EDHCPSERVBADRESP EDHCPSERVBADRESP
  99. #define RTP_NET_EDHCPSERVNOOFFER EDHCPSERVNOOFFER
  100. #define RTP_NET_EDHCPSERVNOACK EDHCPSERVNOACK
  101. #define RTP_NET_EDHCPSERVNOACKNAK EDHCPSERVNOACKNAK
  102. #define RTP_NET_EDHCPOPNOTFOUND EDHCPOPNOTFOUND
  103. #define RTP_NET_EDHCPOPOVERFLOW EDHCPOPOVERFLOW
  104. #define RTP_NET_EDHCPOPBADLEN EDHCPOPBADLEN
  105. #define RTP_NET_EDHCPBADPARAM EDHCPBADPARAM
  106. #define RTP_NET_EACCES EACCES
  107. /* IP options */
  108. #define RTP_NET_IP_OPTS_MULTICAST_IF IP_MULTICAST_IF
  109. #define RTP_NET_IP_OPTS_MULTICAST_TTL IP_MULTICAST_TTL
  110. #define RTP_NET_IP_OPTS_MULTICAST_LOOP IP_MULTICAST_LOOP
  111. #define RTP_NET_IP_OPTS_ADD_MEMBERSHIP IP_ADD_MEMBERSHIP
  112. #define RTP_NET_IP_OPTS_DROP_MEMBERSHIP IP_DROP_MEMBERSHIP
  113. #define RTP_NET_IP_OPTS_BROADCAST IP_BROADCAST
  114. #define RTP_NET_IP_OPTS_DONTFRAG IP_DONTFRAG
  115. /* Socket Options */
  116. #define RTP_NET_SO_NAGLE SO_NAGLE /* NAGLE algorithm enabled/disabled */
  117. #define RTP_NET_SO_TCP_STREAM SO_TCP_STREAM /* do not send unless can send MSS */
  118. #define RTP_NET_SO_REUSEADDR SO_REUSEADDR /* allow local address reuse */
  119. #define RTP_NET_SO_KEEPALIVE SO_KEEPALIVE /* keep connections alive */
  120. #define RTP_NET_SO_MAX_UDP_QUE SO_MAX_UDP_QUE /* max number of input UDP pkt to que */
  121. #define RTP_NET_SO_UDPCKSUM_IN SO_UDPCKSUM_IN /* check UDP checksum on input pkts */
  122. #define RTP_NET_SO_UDPCKSUM_OUT SO_UDPCKSUM_OUT /* generate UDP checksum output pkts */
  123. #define RTP_NET_SO_LINGER SO_LINGER /* linger on close if data present */
  124. #define RTP_NET_SO_TCP_NO_COPY SO_TCP_NO_COPY /* TCP is in packet mode vs window mode */
  125. #define RTP_NET_SO_REUSESOCK SO_REUSESOCK /* allow reuse of socket in TWAIT state */
  126. #define RTP_NET_SO_DELAYED_ACK SO_DELAYED_ACK /* delay sending ACK */
  127. #define RTP_NET_SO_IP_TTL SO_IP_TTL /* IP time-to-live */
  128. #define RTP_NET_SO_MCAST_LOOP SO_MCAST_LOOP /* send multicast to loopback if */
  129. #define RTP_NET_SO_SELECT_SIZE SO_SELECT_SIZE /* TCP write select: wake up when */
  130. /* specifed room in window */
  131. #define RTP_NET_SO_TYPE SO_TYPE /* type of socket */
  132. #define RTP_NET_SO_ACCEPTCON SO_ACCEPTCON /* can socket accept connection */
  133. #define RTP_NET_IO_BLOCK_OPT IO_BLOCK_OPT /* blocking mode: set by ioctlsocket() */
  134. /* listening to dest address (UDP only) */
  135. #if (INCLUDE_TCP_TIMESTAMP)
  136. #define RTP_NET_SO_TCP_TIMESTAMP SO_TCP_TIMESTAMP /* TCP timestamp option */
  137. #endif
  138. #if (INCLUDE_802_2)
  139. #define RTP_NET_SO_802_2 SO_802_2 /* 802.2 socket - passed to setsockopt() */
  140. #endif
  141. #define RTP_NET_SO_TOS SO_TOS /* TOS Byte value in IP Header */
  142. #define RTP_NET_SO_FREE_WITH_INPUT SO_FREE_WITH_INPUT /* Free TCP socket even if data in */
  143. #if (INCLUDE_SSL)
  144. #define RTP_SO_SECURE_SOCKET SO_SECURE_SOCKET /* Use secure socket to transmit data */
  145. #endif
  146. #define RTP_NET_SO_RCV_TIMEO SO_RCV_TIMEO /* Set receive timeout */
  147. #define RTP_NET_SO_SEND_TIMEO SO_SEND_TIMEO /* Set send timeout */
  148. #define RTP_NET_SO_ERROR SO_ERROR /* get and clear errno */
  149. #define RTP_NET_SO_RCVBUF SO_RCVBUF
  150. #define RTP_NET_SO_SNDBUF SO_SNDBUF
  151. #define RTP_NET_SO_RECEIVE_BUFFER SO_RECEIVE_BUFFER
  152. #define RTP_NET_SO_SEND_BUFFER SO_SEND_BUFFER
  153. #define RTP_NET_SO_IP_DONTFRAG IP_DONTFRAG
  154. /* IP option levels */
  155. #define RTP_NET_SOL_SOCKET SOL_SOCKET
  156. #define RTP_NET_IPROTO_TCP IPROTO_TCP
  157. #define RTP_NET_IPROTO_UDP IPROTO_UDP
  158. #define RTP_NET_IPROTO_IP IPROTO_IP
  159. #define RTP_NET_IPPROTO_TCP IPPROTO_TCP
  160. #define RTP_NET_IPPROTO_UDP IPPROTO_UDP
  161. #define RTP_NET_IPPROTO_IP IPPROTO_IP
  162. #define RTP_NET_MSG_OOB MSG_OOB /* process out-of-band data */
  163. #define RTP_NET_MSG_PEEK MSG_PEEK /* peek at incoming message */
  164. #define RTP_NET_MSG_DONTROUTE MSG_DONTROUTE /* send without using routing tables */
  165. #define RTP_NET_MSG_EOR MSG_EOR /* data completes record */
  166. #define RTP_NET_MSG_TRUNC MSG_TRUNC /* data discarded before delivery */
  167. #define RTP_NET_MSG_CTRUNC MSG_CTRUNC /* control data lost before delivery */
  168. #define RTP_NET_MSG_WAITALL MSG_WAITALL /* wait for full request or error */
  169. #define RTP_NET_MSG_QUEUE MSG_QUEUE /* just queue the buffer; dont send it */
  170. /************************************************************************
  171. * Typedefs
  172. ************************************************************************/
  173. /************************************************************************
  174. * RTP_FD_SET - socket handle list for rtp_net_select *
  175. ************************************************************************/
  176. typedef struct s_RTP_FD_SET
  177. {
  178. int fdCount;
  179. RTP_SOCKET fdArray[RTP_FD_SET_MAX];
  180. }
  181. RTP_FD_SET;
  182. /************************************************************************
  183. * RTP_NET_ADDR - network address structure *
  184. ************************************************************************/
  185. typedef struct s_RTP_NET_ADDR
  186. {
  187. unsigned char ipAddr[RTP_NET_IP_ALEN];
  188. int port;
  189. int type;
  190. }
  191. RTP_NET_ADDR;
  192. #ifdef __cplusplus
  193. extern "C" {
  194. #endif
  195. /************************************************************************
  196. * Initialize/Shutdown the API *
  197. ************************************************************************/
  198. int rtp_init_completions (void);
  199. int rtp_uninit_completions (void);
  200. int rtp_net_init (void);
  201. void rtp_net_exit (void);
  202. void rtp_net_restart (void);
  203. int rtp_net_set_ip (int ifaceNumber, RTP_PFUINT8 myIpAddress, RTP_PFUINT8 myBroadCastAddress);
  204. /************************************************************************
  205. * Sockets API *
  206. ************************************************************************/
  207. /* general sockets calls */
  208. int rtp_net_socket (RTP_SOCKET *sockHandle, int family, int type, int protocol);
  209. int rtp_net_bind (RTP_SOCKET sockHandle, unsigned char *ipAddr, int port, int type);
  210. int rtp_net_listen (RTP_SOCKET sockHandle, int queueSize);
  211. int rtp_net_getpeername (RTP_SOCKET sockHandle, unsigned char *ipAddr, int *port, int *type);
  212. int rtp_net_getsockname (RTP_SOCKET sockHandle, unsigned char *ipAddr, int *port, int *type);
  213. int rtp_net_gethostbyname (unsigned char *ipAddr, int *type, char *name);
  214. int rtp_net_accept (RTP_SOCKET *connectSock, RTP_SOCKET serverSock,
  215. unsigned char *ipAddr, int *port, int *type);
  216. int rtp_net_connect (RTP_SOCKET sockHandle, unsigned char *ipAddr, int port, int type);
  217. unsigned rtp_net_is_connected (RTP_SOCKET sockHandle);
  218. int rtp_net_write_select (RTP_SOCKET sockHandle, long msecTimeout);
  219. int rtp_net_read_select (RTP_SOCKET sockHandle, long msecTimeout);
  220. long rtp_net_send (RTP_SOCKET sockHandle, const unsigned char *buffer, long size, int flags);
  221. long rtp_net_recv (RTP_SOCKET sockHandle, unsigned char *buffer, long size, int flags);
  222. long rtp_net_sendto (RTP_SOCKET sockHandle, const unsigned char *buffer, long size,
  223. unsigned char *ipAddr, int port, int type, int flags);
  224. long rtp_net_recvfrom (RTP_SOCKET sockHandle, unsigned char *buffer, long size,
  225. unsigned char *ipAddr, int *port, int *type, int flags);
  226. int rtp_net_closesocket (RTP_SOCKET sockHandle);
  227. int rtp_net_shutdown (RTP_SOCKET sockHandle, int how);
  228. int rtp_net_getlasterror (void);
  229. /* socket options */
  230. int rtp_net_setsockoopt (RTP_HANDLE sockHandle, int level, int optionName,
  231. RTP_PFCCHAR optionVal, int length);
  232. int rtp_net_getsockopt (RTP_HANDLE sockHandle, int level, int optionName,
  233. RTP_PFCHAR opttionVal, int* optlen );
  234. int rtp_net_getntoread (RTP_SOCKET sockHandle, unsigned long * nToRead);
  235. int rtp_net_setblocking (RTP_SOCKET sockHandle, unsigned int onBool);
  236. int rtp_net_setnagle (RTP_SOCKET sockHandle, unsigned int onBool);
  237. int rtp_net_setlinger (RTP_SOCKET sockHandle, unsigned int onBool, long msecTimeout);
  238. int rtp_net_setreusesock (RTP_SOCKET sockHandle, unsigned int onBool);
  239. int rtp_net_setreuseaddr (RTP_SOCKET sockHandle, unsigned int onBool);
  240. int rtp_net_settcpnocopy (RTP_SOCKET sockHandle, unsigned int onBool);
  241. int rtp_net_setkeepalive (RTP_SOCKET sockHandle, unsigned int onBool);
  242. int rtp_net_setmembership (RTP_SOCKET sockHandle, unsigned char * ipAddr,
  243. int type, unsigned int onBool);
  244. int rtp_net_setmcastttl (RTP_SOCKET sockHandle, int ttl);
  245. int rtp_net_setbroadcast (RTP_SOCKET sockHandle, unsigned int onBool);
  246. /* utility functions */
  247. #if (!INCLUDE_RTIP)
  248. short rtp_net_htons (short i);
  249. short rtp_net_ntohs (short i);
  250. long rtp_net_htonl (long i);
  251. long rtp_net_ntohl (long i);
  252. #endif /* #if (!INCLUDE_RTIP) */
  253. int rtp_net_ip_to_str (char *str, unsigned char *ipAddr, int type);
  254. int rtp_net_str_to_ip (unsigned char *ipAddr, char *str, int *type);
  255. int rtp_net_getifaceaddr (unsigned char *localAddr, unsigned char *remoteAddr,
  256. int remotePort, int remoteType);
  257. /* FD_SET functions */
  258. void rtp_fd_zero (RTP_FD_SET *list);
  259. void rtp_fd_set (RTP_FD_SET *list, RTP_SOCKET fd);
  260. void rtp_fd_clr (RTP_FD_SET *list, RTP_SOCKET fd);
  261. int rtp_fd_isset (RTP_FD_SET *list, RTP_SOCKET fd);
  262. int rtp_net_select (RTP_FD_SET *readList, RTP_FD_SET *writeList, RTP_FD_SET *errorList, struct timeval * msecTimeout);
  263. void rtp_net_invoke_input (PIFACE pi, DCU msg, int length);
  264. void rtp_net_invoke_output (PIFACE pi, int xmit_complete_cnt);
  265. #ifdef __cplusplus
  266. }
  267. #endif
  268. #endif /* __RTPNET_H__ */
  269. /* ----------------------------------- */
  270. /* END OF FILE */
  271. /* ----------------------------------- */