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