PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/ATF2/control-software/epics-3.14.8/base/src/libCom/osi/osiSock.h

http://atf2flightsim.googlecode.com/
C Header | 208 lines | 63 code | 23 blank | 122 comment | 0 complexity | 62154a71707eb19a00badf5d3d3d91a3 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
  1. /*************************************************************************\
  2. * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
  3. * National Laboratory.
  4. * Copyright (c) 2002 The Regents of the University of California, as
  5. * Operator of Los Alamos National Laboratory.
  6. * EPICS BASE is distributed subject to a Software License Agreement found
  7. * in file LICENSE that is included with this distribution.
  8. \*************************************************************************/
  9. /*
  10. * osiSock.h,v 1.20.2.6 2009/06/04 21:31:39 anj Exp
  11. *
  12. * socket support library API def
  13. *
  14. * 7-1-97 -joh-
  15. */
  16. #ifndef osiSockh
  17. #define osiSockh
  18. #include "shareLib.h"
  19. #include "osdSock.h"
  20. #include "ellLib.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. struct sockaddr;
  25. struct sockaddr_in;
  26. struct in_addr;
  27. epicsShareFunc SOCKET epicsShareAPI epicsSocketCreate (
  28. int domain, int type, int protocol );
  29. epicsShareFunc int epicsShareAPI epicsSocketAccept (
  30. int sock, struct sockaddr * pAddr, osiSocklen_t * addrlen );
  31. epicsShareFunc void epicsShareAPI epicsSocketDestroy (
  32. SOCKET );
  33. epicsShareFunc void epicsShareAPI
  34. epicsSocketEnableAddressReuseDuringTimeWaitState ( SOCKET s );
  35. epicsShareFunc void epicsShareAPI
  36. epicsSocketEnableAddressUseForDatagramFanout ( SOCKET s );
  37. /*
  38. * Fortunately, on most systems the combination of a shutdown of both
  39. * directions and or a signal is sufficent to interrupt a blocking send,
  40. * receive, or connect call. For odd ball systems this is stubbed out in the
  41. * osi area.
  42. */
  43. enum epicsSocketSystemCallInterruptMechanismQueryInfo {
  44. esscimqi_socketCloseRequired,
  45. esscimqi_socketBothShutdownRequired,
  46. esscimqi_socketSigAlarmRequired /* NO LONGER USED/SUPPORTED */
  47. };
  48. epicsShareFunc enum epicsSocketSystemCallInterruptMechanismQueryInfo
  49. epicsSocketSystemCallInterruptMechanismQuery ();
  50. /*
  51. * convert socket address to ASCII in this order
  52. * 1) look for matching host name and typically add trailing IP port
  53. * 2) failing that, convert to raw ascii address (typically this is a
  54. * dotted IP address with trailing port)
  55. * 3) failing that, writes "<Ukn Addr Type>" into pBuf
  56. *
  57. * returns the number of character elements stored in buffer not
  58. * including the null termination, but always writes at least a
  59. * null ternminater in the string (if bufSize >= 1)
  60. */
  61. epicsShareFunc unsigned epicsShareAPI sockAddrToA (
  62. const struct sockaddr * paddr, char * pBuf, unsigned bufSize );
  63. /*
  64. * convert IP address to ASCII in this order
  65. * 1) look for matching host name and add trailing port
  66. * 2) convert to raw dotted IP address with trailing port
  67. *
  68. * returns the number of character elements stored in buffer not
  69. * including the null termination, but always writes at least a
  70. * null ternminater in the string (if bufSize >= 1)
  71. */
  72. epicsShareFunc unsigned epicsShareAPI ipAddrToA (
  73. const struct sockaddr_in * pInetAddr, char * pBuf, unsigned bufSize );
  74. /*
  75. * sockAddrToDottedIP ()
  76. * typically convert to raw dotted IP address with trailing port
  77. *
  78. * returns the number of character elements stored in buffer not
  79. * including the null termination, but always writes at least a
  80. * null ternminater in the string (if bufSize >= 1)
  81. */
  82. epicsShareFunc unsigned epicsShareAPI sockAddrToDottedIP (
  83. const struct sockaddr * paddr, char * pBuf, unsigned bufSize );
  84. /*
  85. * ipAddrToDottedIP ()
  86. * convert to raw dotted IP address with trailing port
  87. *
  88. * returns the number of character elements stored in buffer not
  89. * including the null termination, but always writes at least a
  90. * null ternminater in the string (if bufSize >= 1)
  91. */
  92. epicsShareFunc unsigned epicsShareAPI ipAddrToDottedIP (
  93. const struct sockaddr_in * paddr, char * pBuf, unsigned bufSize );
  94. /*
  95. * convert inet address to a host name string
  96. *
  97. * returns the number of character elements stored in buffer not
  98. * including the null termination. This will be zero if a matching
  99. * host name cant be found.
  100. *
  101. * there are many OS specific implementation stubs for this routine
  102. */
  103. epicsShareFunc unsigned epicsShareAPI ipAddrToHostName (
  104. const struct in_addr * pAddr, char * pBuf, unsigned bufSize );
  105. /*
  106. * attempt to convert ASCII string to an IP address in this order
  107. * 1) look for traditional doted ip with optional port
  108. * 2) look for raw number form of ip address with optional port
  109. * 3) look for valid host name with optional port
  110. */
  111. epicsShareFunc int epicsShareAPI aToIPAddr
  112. ( const char * pAddrString, unsigned short defaultPort, struct sockaddr_in * pIP);
  113. /*
  114. * attempt to convert ASCII host name string with optional port to an IP address
  115. */
  116. epicsShareFunc int epicsShareAPI hostToIPAddr
  117. (const char *pHostName, struct in_addr *pIPA);
  118. /*
  119. * attach to BSD socket library
  120. */
  121. epicsShareFunc int epicsShareAPI osiSockAttach (void); /* returns T if success, else F */
  122. /*
  123. * release BSD socket library
  124. */
  125. epicsShareFunc void epicsShareAPI osiSockRelease (void);
  126. /*
  127. * convert socket error number to a string
  128. */
  129. epicsShareFunc void epicsSocketConvertErrnoToString (
  130. char * pBuf, unsigned bufSize );
  131. typedef union osiSockAddr {
  132. struct sockaddr_in ia;
  133. struct sockaddr sa;
  134. } osiSockAddr;
  135. typedef struct osiSockAddrNode {
  136. ELLNODE node;
  137. osiSockAddr addr;
  138. } osiSockAddrNode;
  139. /*
  140. * sockAddrAreIdentical()
  141. * (returns true if addresses are identical)
  142. */
  143. epicsShareFunc int epicsShareAPI sockAddrAreIdentical
  144. ( const osiSockAddr * plhs, const osiSockAddr * prhs );
  145. /*
  146. * osiSockDiscoverBroadcastAddresses ()
  147. * Returns the broadcast addresses of each network interface found.
  148. *
  149. * This routine is provided with the address of an ELLLIST, a socket,
  150. * a destination port number, and a match address. When the
  151. * routine returns there will be one additional entry
  152. * (an osiSockAddrNode) in the list for each network interface found that
  153. * is up and isnt a loop back interface (match addr is INADDR_ANY),
  154. * or only the interfaces that match the specified addresses (match addr
  155. * is other than INADDR_ANY). If the interface supports broadcasting
  156. * then add its broadcast address to the list. If the interface is a
  157. * point to point link then add the destination address of the point to
  158. * point link to the list.
  159. *
  160. * Any mutex locking required to protect pList is applied externally.
  161. *
  162. */
  163. epicsShareFunc void epicsShareAPI osiSockDiscoverBroadcastAddresses
  164. (ELLLIST *pList, SOCKET socket, const osiSockAddr *pMatchAddr);
  165. /*
  166. * osiLocalAddr ()
  167. * Returns the osiSockAddr of the first non-loopback interface found
  168. * that is operational (up flag is set). If no valid address can be
  169. * located then return an osiSockAddr with the address family set to
  170. * unspecified (AF_UNSPEC).
  171. *
  172. * Unfortunately in EPICS 3.13 beta 11 and before the CA
  173. * repeater would not always allow the loopback address
  174. * as a local client address so current clients alternate
  175. * between the address of the first non-loopback interface
  176. * found and the loopback addresss when subscribing with
  177. * the CA repeater until all CA repeaters have been updated
  178. * to current code. After all CA repeaters have been restarted
  179. * this osi interface can be eliminated.
  180. */
  181. epicsShareFunc osiSockAddr epicsShareAPI osiLocalAddr (SOCKET socket);
  182. #ifdef __cplusplus
  183. }
  184. #endif
  185. #endif /* ifndef osiSockh */