64 snprintf(temp,
sizeof(temp),
"%u:%u", asn, value);
69 snprintf(temp,
sizeof(temp),
":%u", value);
70 return ip.to_string() + temp;
74 snprintf(temp,
sizeof(temp),
"%u:%u", asn, value);
77 snprintf(temp,
sizeof(temp),
"%u:%02x:%02x:%02x:%02x:%02x:%02x",
85 const string &str, boost::system::error_code *errorp) {
87 size_t pos = str.rfind(
':');
88 if (pos == string::npos) {
90 *errorp = make_error_code(boost::system::errc::invalid_argument);
95 boost::system::error_code ec;
96 string first(str.substr(0, pos));
97 Ip4Address addr = Ip4Address::from_string(first, ec);
101 if (ec.value() != 0) {
103 asn = strtol(first.c_str(), &endptr, 10);
104 if (asn >= 65535 || *endptr !=
'\0') {
105 if (errorp != NULL) {
107 make_error_code(boost::system::errc::invalid_argument);
121 string second(str, pos + 1);
122 uint64_t value = strtol(second.c_str(), &endptr, 10);
123 if (*endptr !=
'\0') {
124 if (errorp != NULL) {
125 *errorp = make_error_code(boost::system::errc::invalid_argument);
131 if (asn == 0 && value != 0) {
132 if (errorp != NULL) {
133 *errorp = make_error_code(boost::system::errc::invalid_argument);
139 if (offset == 4 && value > 0xFFFFFFFF) {
140 if (errorp != NULL) {
141 *errorp = make_error_code(boost::system::errc::invalid_argument);
147 if (offset == 6 && value > 0xFFFF) {
148 if (errorp != NULL) {
149 *errorp = make_error_code(boost::system::errc::invalid_argument);
boost::asio::ip::address_v4 Ip4Address
int CompareTo(const RouteDistinguisher &rhs) const
uint16_t GetVrfId() const
uint32_t GetAddress() const
static RouteDistinguisher FromString(const std::string &str, boost::system::error_code *error=NULL)
static const size_t kSize
static RouteDistinguisher kZeroRd
std::string ToString() const
static void put_value(uint8_t *data, int size, uint64_t value)
static uint64_t get_value(const uint8_t *data, int size)