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