diff --git a/slsSupportLib/src/network_utils.cpp b/slsSupportLib/src/network_utils.cpp index 6147cfb19..6c3e25caa 100755 --- a/slsSupportLib/src/network_utils.cpp +++ b/slsSupportLib/src/network_utils.cpp @@ -20,9 +20,7 @@ IpAddr::IpAddr(const std::string &address) { inet_pton(AF_INET, address.c_str(), &addr_); } -IpAddr::IpAddr(const char *address) { - inet_pton(AF_INET, address, &addr_); -} +IpAddr::IpAddr(const char *address) { inet_pton(AF_INET, address, &addr_); } std::string IpAddr::str() const { char ipstring[INET_ADDRSTRLEN]{}; @@ -31,9 +29,9 @@ std::string IpAddr::str() const { } std::string IpAddr::hex() const { std::ostringstream ss; + ss << std::hex << std::setfill('0'); for (int i = 0; i != 4; ++i) { - ss << std::hex << std::setfill('0') << std::setw(2) - << ((addr_ >> i * 8) & 0xFF); + ss << std::setw(2) << ((addr_ >> i * 8) & 0xFF); } return ss.str(); } @@ -56,18 +54,14 @@ std::string MacAddr::to_hex(const char delimiter) const { for (int i = 32; i >= 0; i -= 8) { if (delimiter) ss << delimiter; - ss << ((addr_ >> i) & 0xFF); + ss << std::setw(2) << ((addr_ >> i) & 0xFF); } return ss.str(); } -std::string MacAddr::str() const { - return to_hex(':'); -} +std::string MacAddr::str() const { return to_hex(':'); } -std::string MacAddr::hex() const { - return to_hex(); -} +std::string MacAddr::hex() const { return to_hex(); } std::ostream &operator<<(std::ostream &out, const IpAddr &addr) { return out << addr.str(); diff --git a/slsSupportLib/tests/test-network_utils.cpp b/slsSupportLib/tests/test-network_utils.cpp index a9d68ae19..43a08795a 100755 --- a/slsSupportLib/tests/test-network_utils.cpp +++ b/slsSupportLib/tests/test-network_utils.cpp @@ -11,9 +11,9 @@ using namespace sls; TEST_CASE("Convert mac address using classes", "[support]") { - std::vector vec_addr{346856806822, 346856806852, 262027939863028}; + std::vector vec_addr{346856806822, 346856806852, 262027939863028,0, 281474976710655}; std::vector vec_ans{"00:50:c2:46:d9:a6", "00:50:c2:46:d9:c4", - "ee:50:22:46:d9:f4"}; + "ee:50:22:46:d9:f4", "00:00:00:00:00:00", "ff:ff:ff:ff:ff:ff"}; for (size_t i = 0; i != vec_addr.size(); ++i) { auto mac0 = MacAddr(vec_addr[i]); auto mac1 = MacAddr(vec_ans[i]);