/* 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 PPB_NetAddress
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 PPB_NetAddress
interface provides operations on network
* addresses.
*/
struct PPB_NetAddress_1_0 {
/**
* Creates a PPB_NetAddress
resource with the specified IPv4
* address.
*
* @param[in] instance A PP_Instance
identifying one instance of
* a module.
* @param[in] ipv4_addr An IPv4 address.
*
* @return A PP_Resource
representing the same address as
* ipv4_addr
or 0 on failure.
*/
PP_Resource (*CreateFromIPv4Address)(
PP_Instance instance,
const struct PP_NetAddress_IPv4* ipv4_addr);
/**
* Creates a PPB_NetAddress
resource with the specified IPv6
* address.
*
* @param[in] instance A PP_Instance
identifying one instance of
* a module.
* @param[in] ipv6_addr An IPv6 address.
*
* @return A PP_Resource
representing the same address as
* ipv6_addr
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 PP_Resource
to check.
*
* @return PP_TRUE
if the input is a PPB_NetAddress
* resource; PP_FALSE
otherwise.
*/
PP_Bool (*IsNetAddress)(PP_Resource resource);
/**
* Gets the address family.
*
* @param[in] addr A PP_Resource
corresponding to a network
* address.
*
* @return The address family on success;
* PP_NETADDRESS_FAMILY_UNSPECIFIED
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 PP_Resource
corresponding to a network
* address.
* @param[in] include_port Whether to include the port number in the
* description.
*
* @return A string PP_Var
on success; an undefined
* PP_Var
on failure.
*/
struct PP_Var (*DescribeAsString)(PP_Resource addr, PP_Bool include_port);
/**
* Fills a PP_NetAddress_IPv4
structure if the network address is
* of PP_NETADDRESS_FAMILY_IPV4
address family.
* Note that passing a network address of
* PP_NETADDRESS_FAMILY_IPV6
address family will fail even if the
* address is an IPv4-mapped IPv6 address.
*
* @param[in] addr A PP_Resource
corresponding to a network
* address.
* @param[out] ipv4_addr A PP_NetAddress_IPv4
structure to store
* the result.
*
* @return A PP_Bool
value indicating whether the operation
* succeeded.
*/
PP_Bool (*DescribeAsIPv4Address)(PP_Resource addr,
struct PP_NetAddress_IPv4* ipv4_addr);
/**
* Fills a PP_NetAddress_IPv6
structure if the network address is
* of PP_NETADDRESS_FAMILY_IPV6
address family.
* Note that passing a network address of
* PP_NETADDRESS_FAMILY_IPV4
address family will fail - this
* method doesn't map it to an IPv6 address.
*
* @param[in] addr A PP_Resource
corresponding to a network
* address.
* @param[out] ipv6_addr A PP_NetAddress_IPv6
structure to store
* the result.
*
* @return A PP_Bool
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_ */