16 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
23 memset(data_, 0, kSize);
27 memcpy(data_, data, kSize);
31 boost::system::error_code *errorp) {
32 if (str ==
"zero_esi")
37 size_t num_colons = count(str.begin(), str.end(),
':');
38 if (num_colons != 1 && num_colons != 9) {
40 *errorp = make_error_code(boost::system::errc::invalid_argument);
45 memset(data, 0, kSize);
48 if (num_colons == 1) {
49 size_t pos = str.find(
':');
50 assert(pos != string::npos);
51 string asn_or_ip(str.substr(0, pos));
53 size_t num_dots = count(asn_or_ip.begin(), asn_or_ip.end(),
'.');
54 if (num_dots != 0 && num_dots != 3) {
56 *errorp = make_error_code(boost::system::errc::invalid_argument);
66 *errorp = make_error_code(boost::system::errc::invalid_argument);
77 boost::system::error_code ec;
78 Ip4Address addr = Ip4Address::from_string(asn_or_ip, ec);
79 if (ec.value() != 0) {
81 *errorp = make_error_code(boost::system::errc::invalid_argument);
87 const Ip4Address::bytes_type &bytes = addr.to_bytes();
88 copy(bytes.begin(), bytes.begin() + 4, &data[1]);
92 string disc_str(str, pos + 1);
97 *errorp = make_error_code(boost::system::errc::invalid_argument);
105 if (num_colons == 9) {
107 int ret = sscanf(str.c_str(),
108 "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx%c",
109 &data[0], &data[1], &data[2], &data[3], &data[4],
110 &data[5], &data[6], &data[7], &data[8], &data[9], &extra);
111 if (ret != kSize || strchr(str.c_str(),
'x') || strchr(str.c_str(),
'X')) {
113 *errorp = make_error_code(boost::system::errc::invalid_argument);
130 uint32_t value =
get_value(data_ + 5, 4);
136 uint32_t value =
get_value(data_ + 5, 4);
146 snprintf(temp,
sizeof(temp),
147 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
148 data_[0], data_[1], data_[2], data_[3], data_[4],
149 data_[5], data_[6], data_[7], data_[8], data_[9]);
158 return memcmp(data_, rhs.
data_, kSize);
boost::asio::ip::address_v4 Ip4Address
static int CompareTo(const AuthenticationKey &lhs, const AuthenticationKey &rhs)
std::string ToString() const
int CompareTo(const EthernetSegmentId &rhs) const
static const EthernetSegmentId kZeroEsi
static EthernetSegmentId FromString(const std::string &str, boost::system::error_code *errorp=NULL)
static const EthernetSegmentId kMaxEsi
static const uint8_t max_esi_bytes[]
static void put_value(uint8_t *data, int size, uint64_t value)
static uint64_t get_value(const uint8_t *data, int size)
bool stringToInteger(const std::string &str, NumberType &num)
static const std::string integerToString(const NumberType &num)