15 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
22 memset(data_, 0, kSize);
26 memcpy(data_, data, kSize);
30 boost::system::error_code *errorp) {
31 if (str ==
"zero_esi")
36 size_t num_colons = count(str.begin(), str.end(),
':');
37 if (num_colons != 1 && num_colons != 9) {
39 *errorp = make_error_code(boost::system::errc::invalid_argument);
44 memset(data, 0, kSize);
47 if (num_colons == 1) {
48 size_t pos = str.find(
':');
49 assert(pos != string::npos);
50 string asn_or_ip(str.substr(0, pos));
52 size_t num_dots = count(asn_or_ip.begin(), asn_or_ip.end(),
'.');
53 if (num_dots != 0 && num_dots != 3) {
55 *errorp = make_error_code(boost::system::errc::invalid_argument);
65 *errorp = make_error_code(boost::system::errc::invalid_argument);
76 boost::system::error_code ec;
77 Ip4Address addr = Ip4Address::from_string(asn_or_ip, ec);
78 if (ec.value() != 0) {
80 *errorp = make_error_code(boost::system::errc::invalid_argument);
86 const Ip4Address::bytes_type &bytes = addr.to_bytes();
87 copy(bytes.begin(), bytes.begin() + 4, &data[1]);
91 string disc_str(str, pos + 1);
96 *errorp = make_error_code(boost::system::errc::invalid_argument);
104 if (num_colons == 9) {
106 int ret = sscanf(str.c_str(),
107 "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx%c",
108 &data[0], &data[1], &data[2], &data[3], &data[4],
109 &data[5], &data[6], &data[7], &data[8], &data[9], &extra);
110 if (ret != kSize || strchr(str.c_str(),
'x') || strchr(str.c_str(),
'X')) {
112 *errorp = make_error_code(boost::system::errc::invalid_argument);
129 uint32_t value =
get_value(data_ + 5, 4);
135 uint32_t value =
get_value(data_ + 5, 4);
145 snprintf(temp,
sizeof(temp),
146 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
147 data_[0], data_[1], data_[2], data_[3], data_[4],
148 data_[5], data_[6], data_[7], data_[8], data_[9]);
157 return memcmp(data_, rhs.
data_, kSize);
bool stringToInteger(const std::string &str, NumberType &num)
static uint64_t get_value(const uint8_t *data, int size)
static EthernetSegmentId FromString(const std::string &str, boost::system::error_code *errorp=NULL)
static const uint8_t max_esi_bytes[]
static const std::string integerToString(const NumberType &num)
boost::asio::ip::address_v4 Ip4Address
static const EthernetSegmentId kZeroEsi
std::string ToString() const
int CompareTo(const EthernetSegmentId &rhs) const
static int CompareTo(const AuthenticationKey &lhs, const AuthenticationKey &rhs)
static const EthernetSegmentId kMaxEsi
static void put_value(uint8_t *data, int size, uint64_t value)