OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
address_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 #ifndef BASE_ADDRESS_UTIL_H__
5 #define BASE_ADDRESS_UTIL_H__
6 
7 #include <string>
8 #include <vector>
9 
10 #include <base/address.h>
11 #include <boost/asio/io_service.hpp>
12 
13 /*
14  * Returns true if the given IPv4 address is member of the IPv4 subnet
15  * indicated by IPv4 address and prefix length. Otherwise returns false.
16  */
17 bool IsIp4SubnetMember(const Ip4Address &ip, const Ip4Address &prefix_ip,
18  uint16_t plen);
19 /*
20  * Returns true if the given IPv6 address is member of the IPv6 subnet
21  * indicated by IPv6 address and prefix length. Otherwise returns false.
22  */
23 bool IsIp6SubnetMember(const Ip6Address &ip, const Ip6Address &subnet,
24  uint8_t plen);
25 /*
26  * Returns canonical hostname
27  */
28 
29 std::string ResolveCanonicalName();
30 
31 /*
32  * Returns canonical hostname by IPv4
33  */
34 
35 std::string ResolveCanonicalName(const std::string& ipv4);
36 
37 /*
38  * Returns canonical hostname by IPv6
39  */
40 
41 std::string ResolveCanonicalNameIPv6(const std::string& ipv6);
42 
43 /*
44  * Returns boost::asio::ip::address if given string is either valid
45  * IPv4, IPv6 or a resolvable FQDN
46 */
47 
48 boost::asio::ip::address AddressFromString(
49  const std::string &ip_address_str,
50  boost::system::error_code *ec);
51 
53  uint16_t plen);
54 
55 bool ValidateIPAddressString(std::string ip_address_str,
56  std::string *error_msg);
57 
58 IpAddress PrefixToIpNetmask(uint32_t prefix_len);
59 uint32_t NetmaskToPrefix(uint32_t netmask);
60 
61 IpAddress PrefixToIp6Netmask(uint32_t plen);
62 
63 void IpToU64(const IpAddress &sip, const IpAddress &dip,
64  uint64_t *sip_u, uint64_t *sip_l,
65  uint64_t *dip_u, uint64_t *dip_l);
66 void U64ToIpv6(uint64_t upper, uint64_t lower, IpAddress *ip);
67 void U64ToIp(uint64_t sip_u, uint64_t sip_l, uint64_t dip_u, uint64_t dip_l,
68  int family, IpAddress *sip, IpAddress *dip);
69 void Ip6AddressToU64Array(const Ip6Address &addr, uint64_t *arr, int size);
70 
71 bool ValidateServerEndpoints(std::vector<std::string> list,
72  std::string *error_msg);
73 
74 std::string VectorIpv6ToString(const std::vector<signed char> &ipv6);
75 
76 /*
77  * Return IP address string for a host if it is resolvable, empty string
78  * otherwise.
79  */
80 std::string GetHostIp(boost::asio::io_context *io_service,
81  const std::string &hostname);
82 
83 /*
84  * Get VN name from routing instance
85  */
86 std::string GetVNFromRoutingInstance(const std::string &vn);
87 
88 #endif // BASE_ADDRESS_UTIL_H__
Ip4Address GetIp4SubnetBroadcastAddress(const Ip4Address &ip_prefix, uint16_t plen)
bool IsIp4SubnetMember(const Ip4Address &ip, const Ip4Address &prefix_ip, uint16_t plen)
Definition: address_util.cc:19
void IpToU64(const IpAddress &sip, const IpAddress &dip, uint64_t *sip_u, uint64_t *sip_l, uint64_t *dip_u, uint64_t *dip_l)
boost::asio::ip::address IpAddress
Definition: address.h:13
std::string GetVNFromRoutingInstance(const std::string &vn)
void U64ToIpv6(uint64_t upper, uint64_t lower, IpAddress *ip)
bool ValidateServerEndpoints(std::vector< std::string > list, std::string *error_msg)
std::string ResolveCanonicalNameIPv6(const std::string &ipv6)
Definition: address_util.cc:89
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:15
std::string VectorIpv6ToString(const std::vector< signed char > &ipv6)
void Ip6AddressToU64Array(const Ip6Address &addr, uint64_t *arr, int size)
IpAddress PrefixToIp6Netmask(uint32_t plen)
std::string ResolveCanonicalName()
Definition: address_util.cc:40
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
IpAddress AddressFromString(const std::string &ip_address_str, boost::system::error_code *ec)
bool ValidateIPAddressString(std::string ip_address_str, std::string *error_msg)
std::string GetHostIp(boost::asio::io_context *io_service, const std::string &hostname)
void U64ToIp(uint64_t sip_u, uint64_t sip_l, uint64_t dip_u, uint64_t dip_l, int family, IpAddress *sip, IpAddress *dip)
uint32_t NetmaskToPrefix(uint32_t netmask)
IpAddress PrefixToIpNetmask(uint32_t prefix_len)
bool IsIp6SubnetMember(const Ip6Address &ip, const Ip6Address &subnet, uint8_t plen)
Definition: address_util.cc:29