/chromium/ppapi/c/ppb_net_address.h

https://gitlab.com/f3822/qtwebengine-chromium · C Header · 203 lines · 43 code · 13 blank · 147 comment · 0 complexity · 254b42a0501adc0baee2fe8815b57512 MD5 · raw file

  1. /* Copyright 2013 The Chromium Authors. All rights reserved.
  2. * Use of this source code is governed by a BSD-style license that can be
  3. * found in the LICENSE file.
  4. */
  5. /* From ppb_net_address.idl modified Sat Jun 22 10:14:31 2013. */
  6. #ifndef PPAPI_C_PPB_NET_ADDRESS_H_
  7. #define PPAPI_C_PPB_NET_ADDRESS_H_
  8. #include "ppapi/c/pp_bool.h"
  9. #include "ppapi/c/pp_instance.h"
  10. #include "ppapi/c/pp_macros.h"
  11. #include "ppapi/c/pp_resource.h"
  12. #include "ppapi/c/pp_stdint.h"
  13. #include "ppapi/c/pp_var.h"
  14. #define PPB_NETADDRESS_INTERFACE_1_0 "PPB_NetAddress;1.0"
  15. #define PPB_NETADDRESS_INTERFACE PPB_NETADDRESS_INTERFACE_1_0
  16. /**
  17. * @file
  18. * This file defines the <code>PPB_NetAddress</code> interface.
  19. */
  20. /**
  21. * @addtogroup Enums
  22. * @{
  23. */
  24. /**
  25. * Network address family types.
  26. */
  27. typedef enum {
  28. /**
  29. * The address family is unspecified.
  30. */
  31. PP_NETADDRESS_FAMILY_UNSPECIFIED = 0,
  32. /**
  33. * The Internet Protocol version 4 (IPv4) address family.
  34. */
  35. PP_NETADDRESS_FAMILY_IPV4 = 1,
  36. /**
  37. * The Internet Protocol version 6 (IPv6) address family.
  38. */
  39. PP_NETADDRESS_FAMILY_IPV6 = 2
  40. } PP_NetAddress_Family;
  41. PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_NetAddress_Family, 4);
  42. /**
  43. * @}
  44. */
  45. /**
  46. * @addtogroup Structs
  47. * @{
  48. */
  49. /**
  50. * All members are expressed in network byte order.
  51. */
  52. struct PP_NetAddress_IPv4 {
  53. /**
  54. * Port number.
  55. */
  56. uint16_t port;
  57. /**
  58. * IPv4 address.
  59. */
  60. uint8_t addr[4];
  61. };
  62. PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_NetAddress_IPv4, 6);
  63. /**
  64. * All members are expressed in network byte order.
  65. */
  66. struct PP_NetAddress_IPv6 {
  67. /**
  68. * Port number.
  69. */
  70. uint16_t port;
  71. /**
  72. * IPv6 address.
  73. */
  74. uint8_t addr[16];
  75. };
  76. PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_NetAddress_IPv6, 18);
  77. /**
  78. * @}
  79. */
  80. /**
  81. * @addtogroup Interfaces
  82. * @{
  83. */
  84. /**
  85. * The <code>PPB_NetAddress</code> interface provides operations on network
  86. * addresses.
  87. */
  88. struct PPB_NetAddress_1_0 {
  89. /**
  90. * Creates a <code>PPB_NetAddress</code> resource with the specified IPv4
  91. * address.
  92. *
  93. * @param[in] instance A <code>PP_Instance</code> identifying one instance of
  94. * a module.
  95. * @param[in] ipv4_addr An IPv4 address.
  96. *
  97. * @return A <code>PP_Resource</code> representing the same address as
  98. * <code>ipv4_addr</code> or 0 on failure.
  99. */
  100. PP_Resource (*CreateFromIPv4Address)(
  101. PP_Instance instance,
  102. const struct PP_NetAddress_IPv4* ipv4_addr);
  103. /**
  104. * Creates a <code>PPB_NetAddress</code> resource with the specified IPv6
  105. * address.
  106. *
  107. * @param[in] instance A <code>PP_Instance</code> identifying one instance of
  108. * a module.
  109. * @param[in] ipv6_addr An IPv6 address.
  110. *
  111. * @return A <code>PP_Resource</code> representing the same address as
  112. * <code>ipv6_addr</code> or 0 on failure.
  113. */
  114. PP_Resource (*CreateFromIPv6Address)(
  115. PP_Instance instance,
  116. const struct PP_NetAddress_IPv6* ipv6_addr);
  117. /**
  118. * Determines if a given resource is a network address.
  119. *
  120. * @param[in] resource A <code>PP_Resource</code> to check.
  121. *
  122. * @return <code>PP_TRUE</code> if the input is a <code>PPB_NetAddress</code>
  123. * resource; <code>PP_FALSE</code> otherwise.
  124. */
  125. PP_Bool (*IsNetAddress)(PP_Resource resource);
  126. /**
  127. * Gets the address family.
  128. *
  129. * @param[in] addr A <code>PP_Resource</code> corresponding to a network
  130. * address.
  131. *
  132. * @return The address family on success;
  133. * <code>PP_NETADDRESS_FAMILY_UNSPECIFIED</code> on failure.
  134. */
  135. PP_NetAddress_Family (*GetFamily)(PP_Resource addr);
  136. /**
  137. * Returns a human-readable description of the network address. The
  138. * description is in the form of host [ ":" port ] and conforms to
  139. * http://tools.ietf.org/html/rfc3986#section-3.2 for IPv4 and IPv6 addresses
  140. * (e.g., "192.168.0.1", "192.168.0.1:99", or "[::1]:80").
  141. *
  142. * @param[in] addr A <code>PP_Resource</code> corresponding to a network
  143. * address.
  144. * @param[in] include_port Whether to include the port number in the
  145. * description.
  146. *
  147. * @return A string <code>PP_Var</code> on success; an undefined
  148. * <code>PP_Var</code> on failure.
  149. */
  150. struct PP_Var (*DescribeAsString)(PP_Resource addr, PP_Bool include_port);
  151. /**
  152. * Fills a <code>PP_NetAddress_IPv4</code> structure if the network address is
  153. * of <code>PP_NETADDRESS_FAMILY_IPV4</code> address family.
  154. * Note that passing a network address of
  155. * <code>PP_NETADDRESS_FAMILY_IPV6</code> address family will fail even if the
  156. * address is an IPv4-mapped IPv6 address.
  157. *
  158. * @param[in] addr A <code>PP_Resource</code> corresponding to a network
  159. * address.
  160. * @param[out] ipv4_addr A <code>PP_NetAddress_IPv4</code> structure to store
  161. * the result.
  162. *
  163. * @return A <code>PP_Bool</code> value indicating whether the operation
  164. * succeeded.
  165. */
  166. PP_Bool (*DescribeAsIPv4Address)(PP_Resource addr,
  167. struct PP_NetAddress_IPv4* ipv4_addr);
  168. /**
  169. * Fills a <code>PP_NetAddress_IPv6</code> structure if the network address is
  170. * of <code>PP_NETADDRESS_FAMILY_IPV6</code> address family.
  171. * Note that passing a network address of
  172. * <code>PP_NETADDRESS_FAMILY_IPV4</code> address family will fail - this
  173. * method doesn't map it to an IPv6 address.
  174. *
  175. * @param[in] addr A <code>PP_Resource</code> corresponding to a network
  176. * address.
  177. * @param[out] ipv6_addr A <code>PP_NetAddress_IPv6</code> structure to store
  178. * the result.
  179. *
  180. * @return A <code>PP_Bool</code> value indicating whether the operation
  181. * succeeded.
  182. */
  183. PP_Bool (*DescribeAsIPv6Address)(PP_Resource addr,
  184. struct PP_NetAddress_IPv6* ipv6_addr);
  185. };
  186. typedef struct PPB_NetAddress_1_0 PPB_NetAddress;
  187. /**
  188. * @}
  189. */
  190. #endif /* PPAPI_C_PPB_NET_ADDRESS_H_ */