/
address.h
62 lines (52 loc) · 1.94 KB
/
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
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef ctrlplane_address_h
#define ctrlplane_address_h
#include <boost/asio/ip/address.hpp>
//
// address types are POD types
//
typedef boost::asio::ip::address IpAddress;
typedef boost::asio::ip::address_v4 Ip4Address;
typedef boost::asio::ip::address_v6 Ip6Address;
class Address {
public:
static const uint8_t kMaxV4Bytes = 4;
static const uint8_t kMaxV4PrefixLen = 32;
static const uint8_t kMaxV6Bytes = 16;
static const uint8_t kMaxV6PrefixLen = 128;
enum Family {
UNSPEC = 0,
INET = 1,
INET6 = 2,
INETVPN = 3,
INET6VPN = 4,
RTARGET = 5,
EVPN = 6,
ERMVPN = 7,
NUM_FAMILIES
};
Address();
static Family FamilyFromString(const std::string &family);
static std::string FamilyToString(Family fmly);
static Family FamilyFromRoutingTableName(const std::string &name);
static std::string FamilyToTableString(Family family);
static Family VpnFamilyFromFamily(Family family);
static Ip4Address V4FromV4MappedV6(const Ip6Address &v6_address);
static Ip4Address GetIp4SubnetAddress(const Ip4Address &prefix,
uint16_t plen);
static Ip6Address GetIp6SubnetAddress(const Ip6Address &prefix,
uint16_t plen);
private:
IpAddress addr_;
};
boost::system::error_code Ip4PrefixParse(const std::string &str,
Ip4Address *addr, int *plen);
boost::system::error_code Ip4SubnetParse(const std::string &str,
Ip4Address *addr, int *plen);
boost::system::error_code Inet6PrefixParse(const std::string &str,
Ip6Address *addr, int *plen);
boost::system::error_code Inet6SubnetParse(const std::string &str,
Ip6Address *addr, int *plen);
#endif