Commit 003c8279 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[3546] hw_type in HWAddr class is now 16 bits long.

parent dd1ecaaa
......@@ -31,14 +31,14 @@ HWAddr::HWAddr()
: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,
......@@ -49,7 +49,7 @@ HWAddr::HWAddr(const std::vector<uint8_t>& hwaddr, uint8_t htype)
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;
......@@ -65,7 +65,7 @@ std::string HWAddr::toText(bool include_htype) const {
}
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(":"),
......
......@@ -41,18 +41,22 @@ public:
/// @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)
......@@ -83,7 +87,7 @@ public:
///
/// @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;
......
......@@ -163,4 +163,16 @@ TEST(HWAddrTest, fromText) {
}
// 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment