Roll src/third_party/WebKit ef7cfd7:80927b2 (svn 194570:194575)
[chromium-blink-merge.git] / ppapi / c / ppb_net_address.h
blob7f151832235d3bb74bc799c72deac4bb9915583f
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 */
6 /* From ppb_net_address.idl modified Sat Jun 22 10:14:31 2013. */
8 #ifndef PPAPI_C_PPB_NET_ADDRESS_H_
9 #define PPAPI_C_PPB_NET_ADDRESS_H_
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"
18 #define PPB_NETADDRESS_INTERFACE_1_0 "PPB_NetAddress;1.0"
19 #define PPB_NETADDRESS_INTERFACE PPB_NETADDRESS_INTERFACE_1_0
21 /**
22 * @file
23 * This file defines the <code>PPB_NetAddress</code> interface.
27 /**
28 * @addtogroup Enums
29 * @{
31 /**
32 * Network address family types.
34 typedef enum {
35 /**
36 * The address family is unspecified.
38 PP_NETADDRESS_FAMILY_UNSPECIFIED = 0,
39 /**
40 * The Internet Protocol version 4 (IPv4) address family.
42 PP_NETADDRESS_FAMILY_IPV4 = 1,
43 /**
44 * The Internet Protocol version 6 (IPv6) address family.
46 PP_NETADDRESS_FAMILY_IPV6 = 2
47 } PP_NetAddress_Family;
48 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_NetAddress_Family, 4);
49 /**
50 * @}
53 /**
54 * @addtogroup Structs
55 * @{
57 /**
58 * All members are expressed in network byte order.
60 struct PP_NetAddress_IPv4 {
61 /**
62 * Port number.
64 uint16_t port;
65 /**
66 * IPv4 address.
68 uint8_t addr[4];
70 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_NetAddress_IPv4, 6);
72 /**
73 * All members are expressed in network byte order.
75 struct PP_NetAddress_IPv6 {
76 /**
77 * Port number.
79 uint16_t port;
80 /**
81 * IPv6 address.
83 uint8_t addr[16];
85 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_NetAddress_IPv6, 18);
86 /**
87 * @}
90 /**
91 * @addtogroup Interfaces
92 * @{
94 /**
95 * The <code>PPB_NetAddress</code> interface provides operations on network
96 * addresses.
98 struct PPB_NetAddress_1_0 {
99 /**
100 * Creates a <code>PPB_NetAddress</code> resource with the specified IPv4
101 * address.
103 * @param[in] instance A <code>PP_Instance</code> identifying one instance of
104 * a module.
105 * @param[in] ipv4_addr An IPv4 address.
107 * @return A <code>PP_Resource</code> representing the same address as
108 * <code>ipv4_addr</code> or 0 on failure.
110 PP_Resource (*CreateFromIPv4Address)(
111 PP_Instance instance,
112 const struct PP_NetAddress_IPv4* ipv4_addr);
114 * Creates a <code>PPB_NetAddress</code> resource with the specified IPv6
115 * address.
117 * @param[in] instance A <code>PP_Instance</code> identifying one instance of
118 * a module.
119 * @param[in] ipv6_addr An IPv6 address.
121 * @return A <code>PP_Resource</code> representing the same address as
122 * <code>ipv6_addr</code> or 0 on failure.
124 PP_Resource (*CreateFromIPv6Address)(
125 PP_Instance instance,
126 const struct PP_NetAddress_IPv6* ipv6_addr);
128 * Determines if a given resource is a network address.
130 * @param[in] resource A <code>PP_Resource</code> to check.
132 * @return <code>PP_TRUE</code> if the input is a <code>PPB_NetAddress</code>
133 * resource; <code>PP_FALSE</code> otherwise.
135 PP_Bool (*IsNetAddress)(PP_Resource resource);
137 * Gets the address family.
139 * @param[in] addr A <code>PP_Resource</code> corresponding to a network
140 * address.
142 * @return The address family on success;
143 * <code>PP_NETADDRESS_FAMILY_UNSPECIFIED</code> on failure.
145 PP_NetAddress_Family (*GetFamily)(PP_Resource addr);
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").
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.
157 * @return A string <code>PP_Var</code> on success; an undefined
158 * <code>PP_Var</code> on failure.
160 struct PP_Var (*DescribeAsString)(PP_Resource addr, PP_Bool include_port);
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.
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.
173 * @return A <code>PP_Bool</code> value indicating whether the operation
174 * succeeded.
176 PP_Bool (*DescribeAsIPv4Address)(PP_Resource addr,
177 struct PP_NetAddress_IPv4* ipv4_addr);
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.
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.
190 * @return A <code>PP_Bool</code> value indicating whether the operation
191 * succeeded.
193 PP_Bool (*DescribeAsIPv6Address)(PP_Resource addr,
194 struct PP_NetAddress_IPv6* ipv6_addr);
197 typedef struct PPB_NetAddress_1_0 PPB_NetAddress;
199 * @}
202 #endif /* PPAPI_C_PPB_NET_ADDRESS_H_ */