mlibc.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. mlibc.h
  9. Abstract:
  10. This header contains definitions for implementation-specific functions
  11. provided by the Minoca C library.
  12. Author:
  13. Evan Green 19-Nov-2013
  14. --*/
  15. //
  16. // ------------------------------------------------------------------- Includes
  17. //
  18. #include <libcbase.h>
  19. #include <sys/socket.h>
  20. //
  21. // ---------------------------------------------------------------- Definitions
  22. //
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. //
  27. // Define the current version number of the network conversion interface.
  28. //
  29. #define CL_NETWORK_CONVERSION_INTERFACE_VERSION 1
  30. //
  31. // ------------------------------------------------------ Data Type Definitions
  32. //
  33. typedef enum _CL_CONVERSION_TYPE {
  34. ClConversionInvalid,
  35. ClConversionNetworkAddress
  36. } CL_CONVERSION_TYPE, *PCL_CONVERSION_TYPE;
  37. typedef
  38. KSTATUS
  39. (*PCL_CONVERT_TO_NETWORK_ADDRESS) (
  40. const struct sockaddr *Address,
  41. socklen_t AddressLength,
  42. PNETWORK_ADDRESS NetworkAddress
  43. );
  44. /*++
  45. Routine Description:
  46. This routine converts a sockaddr address structure into a network address
  47. structure.
  48. Arguments:
  49. Address - Supplies a pointer to the address structure.
  50. AddressLength - Supplies the length of the address structure in bytes.
  51. NetworkAddress - Supplies a pointer where the corresponding network address
  52. will be returned.
  53. Return Value:
  54. STATUS_SUCCESS on success.
  55. STATUS_INVALID_ADDRESS on failure.
  56. --*/
  57. typedef
  58. KSTATUS
  59. (*PCL_CONVERT_FROM_NETWORK_ADDRESS) (
  60. PNETWORK_ADDRESS NetworkAddress,
  61. struct sockaddr *Address,
  62. socklen_t *AddressLength
  63. );
  64. /*++
  65. Routine Description:
  66. This routine converts a network address structure into a sockaddr structure.
  67. Arguments:
  68. NetworkAddress - Supplies a pointer to the network address to convert.
  69. Address - Supplies a pointer where the address structure will be returned.
  70. AddressLength - Supplies a pointer that on input contains the length of the
  71. specified Address structure, and on output returns the length of the
  72. returned address. If the supplied buffer is not big enough to hold the
  73. address, the address is truncated, and the larger needed buffer size
  74. will be returned here.
  75. Return Value:
  76. STATUS_SUCCESS on success.
  77. STATUS_BUFFER_TOO_SMALL if the address buffer is not big enough.
  78. STATUS_INVALID_ADDRESS on failure.
  79. --*/
  80. /*++
  81. Structure Description:
  82. This structure defines the network conversion interface between C library
  83. types and Minoca types.
  84. Members:
  85. Version - Stores the version number of this structure. Set to
  86. CL_NETWORK_CONVERSION_INTERFACE_VERSION.
  87. AddressFamily - Supplies the C library address family for the conversion
  88. interface.
  89. AddressDomain - Supplies the Minoca address domain for the conversion
  90. interface.
  91. ToNetworkAddress - Supplies a pointer to a function that converts a
  92. sockaddr address structure to a network address structure.
  93. FromNetworkAddress - Supplies a pointer to a function that converts a
  94. network address structure to a sockaddr address structure.
  95. --*/
  96. typedef struct _CL_NETWORK_CONVERSION_INTERFACE {
  97. ULONG Version;
  98. sa_family_t AddressFamily;
  99. NET_DOMAIN_TYPE AddressDomain;
  100. PCL_CONVERT_TO_NETWORK_ADDRESS ToNetworkAddress;
  101. PCL_CONVERT_FROM_NETWORK_ADDRESS FromNetworkAddress;
  102. } CL_NETWORK_CONVERSION_INTERFACE, *PCL_NETWORK_CONVERSION_INTERFACE;
  103. //
  104. // -------------------------------------------------------------------- Globals
  105. //
  106. //
  107. // -------------------------------------------------------- Function Prototypes
  108. //
  109. LIBC_API
  110. INT
  111. ClConvertKstatusToErrorNumber (
  112. KSTATUS Status
  113. );
  114. /*++
  115. Routine Description:
  116. This routine converts a status code to a C library error number.
  117. Arguments:
  118. Status - Supplies the status code.
  119. Return Value:
  120. Returns the appropriate error number for the given status code.
  121. --*/
  122. LIBC_API
  123. KSTATUS
  124. ClConvertToNetworkAddress (
  125. const struct sockaddr *Address,
  126. socklen_t AddressLength,
  127. PNETWORK_ADDRESS NetworkAddress,
  128. PSTR *Path,
  129. PUINTN PathSize
  130. );
  131. /*++
  132. Routine Description:
  133. This routine converts a sockaddr address structure into a network address
  134. structure.
  135. Arguments:
  136. Address - Supplies a pointer to the address structure.
  137. AddressLength - Supplies the length of the address structure in bytes.
  138. NetworkAddress - Supplies a pointer where the corresponding network address
  139. will be returned.
  140. Path - Supplies an optional pointer where a pointer to the path will be
  141. returned if this is a Unix address.
  142. PathSize - Supplies an optional pointer where the path size will be
  143. returned if this is a Unix address.
  144. Return Value:
  145. STATUS_SUCCESS on success.
  146. STATUS_INVALID_ADDRESS on failure.
  147. --*/
  148. LIBC_API
  149. KSTATUS
  150. ClConvertFromNetworkAddress (
  151. PNETWORK_ADDRESS NetworkAddress,
  152. struct sockaddr *Address,
  153. socklen_t *AddressLength,
  154. PSTR Path,
  155. UINTN PathSize
  156. );
  157. /*++
  158. Routine Description:
  159. This routine converts a network address structure into a sockaddr structure.
  160. Arguments:
  161. NetworkAddress - Supplies a pointer to the network address to convert.
  162. Address - Supplies a pointer where the address structure will be returned.
  163. AddressLength - Supplies a pointer that on input contains the length of the
  164. specified Address structure, and on output returns the length of the
  165. returned address. If the supplied buffer is not big enough to hold the
  166. address, the address is truncated, and the larger needed buffer size
  167. will be returned here.
  168. Path - Supplies the path, if this is a local Unix address.
  169. PathSize - Supplies the size of the path, if this is a local Unix address.
  170. Return Value:
  171. STATUS_SUCCESS on success.
  172. STATUS_BUFFER_TOO_SMALL if the address buffer is not big enough.
  173. STATUS_INVALID_ADDRESS on failure.
  174. --*/
  175. LIBC_API
  176. KSTATUS
  177. ClRegisterTypeConversionInterface (
  178. CL_CONVERSION_TYPE Type,
  179. PVOID Interface,
  180. BOOL Register
  181. );
  182. /*++
  183. Routine Description:
  184. This routine registers or de-registers a C library type conversion
  185. interface.
  186. Arguments:
  187. Type - Supplies the type of the conversion interface being registered.
  188. Interface - Supplies a pointer to the conversion interface. This memory
  189. will not be referenced after the function returns, so this may be a
  190. stack allocated structure.
  191. Register - Supplies a boolean indicating whether or not the given interface
  192. should be registered or de-registered.
  193. Return Value:
  194. Status code.
  195. --*/
  196. #ifdef __cplusplus
  197. }
  198. #endif