:htype_(HTYPE_ETHER) {
}
-HWAddr::HWAddr(const uint8_t* hwaddr, size_t len, uint8_t htype)
+HWAddr::HWAddr(const uint8_t* hwaddr, size_t len, uint16_t htype)
:hwaddr_(hwaddr, hwaddr + len), htype_(htype) {
if (len > MAX_HWADDR_LEN) {
isc_throw(InvalidParameter, "hwaddr length exceeds MAX_HWADDR_LEN");
}
}
-HWAddr::HWAddr(const std::vector<uint8_t>& hwaddr, uint8_t htype)
+HWAddr::HWAddr(const std::vector<uint8_t>& hwaddr, uint16_t htype)
:hwaddr_(hwaddr), htype_(htype) {
if (hwaddr.size() > MAX_HWADDR_LEN) {
isc_throw(InvalidParameter,
std::string HWAddr::toText(bool include_htype) const {
std::stringstream tmp;
if (include_htype) {
- tmp << "hwtype=" << static_cast<int>(htype_) << " ";
+ tmp << "hwtype=" << static_cast<unsigned int>(htype_) << " ";
}
tmp << std::hex;
bool delim = false;
}
HWAddr
-HWAddr::fromText(const std::string& text, const uint8_t htype) {
+HWAddr::fromText(const std::string& text, const uint16_t htype) {
/// @todo optimize stream operations here.
std::vector<std::string> split_text;
boost::split(split_text, text, boost::is_any_of(":"),
/// @param hwaddr pointer to hardware address
/// @param len length of the address pointed by hwaddr
/// @param htype hardware type
- HWAddr(const uint8_t* hwaddr, size_t len, uint8_t htype);
+ HWAddr(const uint8_t* hwaddr, size_t len, uint16_t htype);
/// @brief constructor, based on C++ vector<uint8_t>
/// @param hwaddr const reference to hardware address
/// @param htype hardware type
- HWAddr(const std::vector<uint8_t>& hwaddr, uint8_t htype);
+ HWAddr(const std::vector<uint8_t>& hwaddr, uint16_t htype);
// Vector that keeps the actual hardware address
std::vector<uint8_t> hwaddr_;
- // Hardware type
- uint8_t htype_;
+ /// Hardware type
+ ///
+ /// @note It used to be uint8_t as used in DHCPv4. However, since we're
+ /// expanding MAC addresses support to DHCPv6 that uses hw_type as
+ /// 16 bits, we need to be able to store that wider format.
+ uint16_t htype_;
/// @brief Returns textual representation of a hardware address
/// (e.g. 00:01:02:03:04:05)
///
/// @return Instance of the HW address created from text.
static HWAddr fromText(const std::string& text,
- const uint8_t htype = HTYPE_ETHER);
+ const uint16_t htype = HTYPE_ETHER);
/// @brief Compares two hardware addresses for equality
bool operator==(const HWAddr& other) const;
}
+// Checks that 16 bits values can be stored in HWaddr
+TEST(HWAddrTest, 16bits) {
+
+ uint8_t data[] = {0, 1, 2, 3, 4, 5};
+ uint16_t htype = 257;
+ HWAddrPtr hw(new HWAddr(data, sizeof(data), htype));
+
+ EXPECT_EQ("hwtype=257 00:01:02:03:04:05", hw->toText());
+
+
+}
+
} // end of anonymous namespace