4 #include <boost/asio.hpp>
5 #include <boost/lexical_cast.hpp>
8 namespace fc {
namespace ip {
17 _ip = boost::asio::ip::address_v4::from_string(s.c_str()).to_ulong();
23 return uint32_t(a) == uint32_t(b);
26 return uint32_t(a) != uint32_t(b);
33 _ip = boost::asio::ip::address_v4::from_string(s.c_str()).to_ulong();
45 address::operator std::string()
const
49 return boost::asio::ip::address_v4(_ip).to_string().c_str();
53 address::operator uint32_t()
const {
65 return a._port == b._port && a._ip == b._ip;
68 return a._port != b._port || a._ip != b._ip;
75 uint32_t(a.
port()) < uint32_t(b.
port()));
86 auto pos = endpoint_string.find(
':');
87 ep._ip = boost::asio::ip::address_v4::from_string(endpoint_string.substr( 0, pos ) ).to_ulong();
88 ep._port = boost::lexical_cast<uint16_t>( endpoint_string.substr( pos+1, endpoint_string.size() ) );
94 endpoint::operator string()
const
98 return string(_ip) +
':' + std::string(boost::lexical_cast<std::string>(_port).c_str());
114 static address min10_ip(
"10.0.0.0");
115 static address max10_ip(
"10.255.255.255");
116 static address min172_ip(
"172.16.0.0");
117 static address max172_ip(
"172.31.255.255");
118 static address min192_ip(
"192.168.0.0");
119 static address max192_ip(
"192.168.255.255");
120 static address min169_ip(
"169.254.0.0");
121 static address max169_ip(
"169.254.255.255");
122 if( _ip >= min10_ip._ip && _ip <= max10_ip._ip )
return true;
123 if( _ip >= min172_ip._ip && _ip <= max172_ip._ip )
return true;
124 if( _ip >= min192_ip._ip && _ip <= max192_ip._ip )
return true;
125 if( _ip >= min169_ip._ip && _ip <= max169_ip._ip )
return true;
134 static address min_ip(
"224.0.0.0");
135 static address max_ip(
"239.255.255.255");
136 return _ip >= min_ip._ip && _ip <= max_ip._ip;
144 static address min_ip(
"127.0.0.0");
145 static address max_ip(
"127.255.255.255");
146 return _ip >= min_ip._ip && _ip <= max_ip._ip;
159 vo = std::string(var);
168 vo = std::string(var);