From 9315768159406661548a76d93cbc2dd6668d2638 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 16 May 2019 14:07:58 +0200 Subject: [PATCH] client bug fix: smaller ips convert to hex --- slsSupportLib/src/network_utils.cpp | 4 ++-- slsSupportLib/tests/test-network_utils.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/slsSupportLib/src/network_utils.cpp b/slsSupportLib/src/network_utils.cpp index a3dba74a8..6147cfb19 100755 --- a/slsSupportLib/src/network_utils.cpp +++ b/slsSupportLib/src/network_utils.cpp @@ -31,9 +31,9 @@ std::string IpAddr::str() const { } std::string IpAddr::hex() const { std::ostringstream ss; - ss << std::hex << std::setfill('0') << std::setw(2); for (int i = 0; i != 4; ++i) { - ss << ((addr_ >> i * 8) & 0xFF); + ss << std::hex << std::setfill('0') << std::setw(2) + << ((addr_ >> i * 8) & 0xFF); } return ss.str(); } diff --git a/slsSupportLib/tests/test-network_utils.cpp b/slsSupportLib/tests/test-network_utils.cpp index c9457da4f..a9d68ae19 100755 --- a/slsSupportLib/tests/test-network_utils.cpp +++ b/slsSupportLib/tests/test-network_utils.cpp @@ -42,9 +42,12 @@ TEST_CASE("Hex representation of MAC", "[support]") { } TEST_CASE("Convert IP using classes ", "[support]") { - std::vector vec_addr{4073554305, 2747957633, 2697625985}; + std::vector vec_addr{4073554305, 2747957633, 2697625985, 2566979594, 0}; std::vector vec_ans{"129.129.205.242", "129.129.202.163", - "129.129.202.160"}; + "129.129.202.160", "10.0.1.153", "0.0.0.0"}; + std::vector vec_hex{"8181cdf2", "8181caa3", + "8181caa0", "0a000199","00000000"}; + for (size_t i = 0; i != vec_addr.size(); ++i) { auto ip0 = IpAddr(vec_addr[i]); @@ -57,6 +60,8 @@ TEST_CASE("Convert IP using classes ", "[support]") { CHECK(ip1 == vec_ans[i]); CHECK(ip0.str() == vec_ans[i]); CHECK(ip1.str() == vec_ans[i]); + CHECK(ip0.hex() == vec_hex[i]); + CHECK(ip1.hex() == vec_hex[i]); } }