33 os << m_minAddress <<
" <-> " << m_maxAddress;
39 using boost::asio::ip::address_v4;
40 static Network range =
Network(address_v4(0), address_v4(0xFFFFFFFF));
47 using boost::asio::ip::address_v6;
48 static address_v6::bytes_type maxV6 = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
49 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
69 std::string networkStr;
72 size_t position = networkStr.find(
'/');
73 if (position == std::string::npos)
75 network.m_minAddress = ip::address::from_string(networkStr);
76 network.m_maxAddress = ip::address::from_string(networkStr);
80 ip::address address = ip::address::from_string(networkStr.substr(0, position));
81 size_t mask = boost::lexical_cast<
size_t>(networkStr.substr(position+1));
85 ip::address_v4::bytes_type maskBytes = boost::initialized_value;
86 for (
size_t i = 0; i < mask; i++)
88 size_t byteId = i / 8;
89 size_t bitIndex = 7 - i % 8;
90 maskBytes[byteId] |= (1 << bitIndex);
93 ip::address_v4::bytes_type addressBytes = address.to_v4().to_bytes();
94 ip::address_v4::bytes_type min;
95 ip::address_v4::bytes_type max;
97 for (
size_t i = 0; i < addressBytes.size(); i++)
99 min[i] = addressBytes[i] & maskBytes[i];
100 max[i] = addressBytes[i] | ~(maskBytes[i]);
103 network.m_minAddress = ip::address_v4(min);
104 network.m_maxAddress = ip::address_v4(max);
108 ip::address_v6::bytes_type maskBytes = boost::initialized_value;
109 for (
size_t i = 0; i < mask; i++)
111 size_t byteId = i / 8;
112 size_t bitIndex = 7 - i % 8;
113 maskBytes[byteId] |= (1 << bitIndex);
116 ip::address_v6::bytes_type addressBytes = address.to_v6().to_bytes();
117 ip::address_v6::bytes_type min;
118 ip::address_v6::bytes_type max;
120 for (
size_t i = 0; i < addressBytes.size(); i++)
122 min[i] = addressBytes[i] & maskBytes[i];
123 max[i] = addressBytes[i] | ~(maskBytes[i]);
126 network.m_minAddress = ip::address_v6(min);
127 network.m_maxAddress = ip::address_v6(max);
static const Network & getMaxRangeV4()
Copyright (c) 2011-2015 Regents of the University of California.
static const Network & getMaxRangeV6()
void print(std::ostream &os) const
friend std::istream & operator>>(std::istream &is, Network &network)
friend std::ostream & operator<<(std::ostream &os, const Network &network)