Skip to content

Commit

Permalink
Fix some lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
peternewman committed Sep 20, 2023
1 parent 05da388 commit 3cc1292
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
20 changes: 12 additions & 8 deletions common/network/IPV6Address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,24 @@ namespace network {
using std::string;

IPV6Address::IPV6Address(const uint8_t *address) {
// TODO(Peter): Deal with network byte order?
// TODO(Peter): Deal with any network byte order conversion?
memcpy(&m_address.s6_addr[0], address, sizeof (struct in6_addr));
}

bool IPV6Address::operator<(const IPV6Address &other) const {
// TODO(Peter): Deal with network byte order?
// TODO(Peter): Deal with any network byte order conversion?
// Stored in network byte order, so convert to sort appropriately
return (memcmp(&m_address.s6_addr[0], &other.m_address.s6_addr[0], sizeof (struct in6_addr)) < 0);
return (memcmp(&m_address.s6_addr[0],
&other.m_address.s6_addr[0],
sizeof (struct in6_addr)) < 0);
}

bool IPV6Address::operator>(const IPV6Address &other) const {
// TODO(Peter): Deal with network byte order?
// TODO(Peter): Deal with any network byte order conversion?
// Stored in network byte order, so convert to sort appropriately
return (memcmp(&m_address.s6_addr[0], &other.m_address.s6_addr[0], sizeof (struct in6_addr)) > 0);
return (memcmp(&m_address.s6_addr[0],
&other.m_address.s6_addr[0],
sizeof (struct in6_addr)) > 0);
}

bool IPV6StringToAddress(const string &address, struct in6_addr *addr) {
Expand Down Expand Up @@ -154,14 +158,14 @@ IPV6Address IPV6Address::FromStringOrDie(const string &address) {

IPV6Address IPV6Address::WildCard() {
in6_addr wildCard = IN6ADDR_ANY_INIT;
// TODO(Peter): Deal with host to network conversion...
// TODO(Peter): Deal with any host to network conversion...
return IPV6Address(wildCard);
}

IPV6Address IPV6Address::Loopback() {
in6_addr loopback = IN6ADDR_LOOPBACK_INIT;
// TODO(Peter): Deal with host to network conversion...
//return IPV6Address(HostToNetwork(IN6ADDR_LOOPBACK_INIT));
// TODO(Peter): Deal with any host to network conversion...
// return IPV6Address(HostToNetwork(IN6ADDR_LOOPBACK_INIT));
return IPV6Address(loopback);
}
} // namespace network
Expand Down
33 changes: 22 additions & 11 deletions common/network/IPV6AddressTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,21 @@ void IPV6AddressTest::testIPV6Address() {
// OLA_ASSERT_EQ(HostToNetwork(0xc0a80101), static_cast<uint32_t>(ip_as_int));
OLA_ASSERT_EQ(string("::ffff:192.168.1.1"), address1.ToString());

IPV6Address address2 = IPV6Address::FromStringOrDie("2001:db8:1234:5678:90ab:cdef:feed:face");
IPV6Address address2 = IPV6Address::FromStringOrDie(
"2001:db8:1234:5678:90ab:cdef:feed:face");
// int ip_as_int = address2.AsInt();
OLA_ASSERT_NE(wildcard_address, address2);
// OLA_ASSERT_NE(HostToNetwork(0xc0a811), ip_as_int);
// OLA_ASSERT_EQ(HostToNetwork(0xc0a80101), static_cast<uint32_t>(ip_as_int));

const uint8_t big_endian_address_data[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 10, 0, 0, 1};
const uint8_t big_endian_address_data[] =
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 10, 0, 0, 1};
IPV6Address binary_address(big_endian_address_data);
OLA_ASSERT_EQ(string("::ffff:10.0.0.1"), binary_address.ToString());

// Test Get()
uint8_t address_data[] = {32, 1, 13, 184, 18, 52, 86, 120, 144, 171, 205, 239, 254, 237, 250, 206};
uint8_t address_data[] = {32, 1, 13, 184, 18, 52, 86, 120,
144, 171, 205, 239, 254, 237, 250, 206};
uint8_t addr[IPV6Address::LENGTH];
address2.Get(addr);
OLA_ASSERT_DATA_EQUALS(addr,
Expand All @@ -103,7 +106,8 @@ void IPV6AddressTest::testIPV6Address() {
OLA_ASSERT_EQ(string("::ffff:192.168.1.1"), str.str());

// test from string
auto_ptr<IPV6Address> string_address(IPV6Address::FromString("::ffff:10.0.0.1"));
auto_ptr<IPV6Address> string_address(
IPV6Address::FromString("::ffff:10.0.0.1"));
OLA_ASSERT_NOT_NULL(string_address.get());
OLA_ASSERT_EQ(string("::ffff:10.0.0.1"), string_address->ToString());

Expand All @@ -112,18 +116,23 @@ void IPV6AddressTest::testIPV6Address() {

// and the second form
IPV6Address string_address3;
OLA_ASSERT_TRUE(IPV6Address::FromString("::ffff:172.16.4.1", &string_address3));
OLA_ASSERT_TRUE(IPV6Address::FromString(
"::ffff:172.16.4.1", &string_address3));
OLA_ASSERT_EQ(string("::ffff:172.16.4.1"), string_address3.ToString());

IPV6Address string_address4;
// Add the leading zero to the second group
OLA_ASSERT_TRUE(IPV6Address::FromString("2001:0db8:1234:5678:90ab:cdef:feed:face", &string_address4));
OLA_ASSERT_TRUE(IPV6Address::FromString(
"2001:0db8:1234:5678:90ab:cdef:feed:face", &string_address4));
// Confirm it's not rendered when we convert to a string
OLA_ASSERT_EQ(string("2001:db8:1234:5678:90ab:cdef:feed:face"), string_address4.ToString());
OLA_ASSERT_EQ(string("2001:db8:1234:5678:90ab:cdef:feed:face"),
string_address4.ToString());

IPV6Address string_address5;
OLA_ASSERT_TRUE(IPV6Address::FromString("2001:db8:dead:beef:dead:beef:dead:beef", &string_address5));
OLA_ASSERT_EQ(string("2001:db8:dead:beef:dead:beef:dead:beef"), string_address5.ToString());
OLA_ASSERT_TRUE(IPV6Address::FromString(
"2001:db8:dead:beef:dead:beef:dead:beef", &string_address5));
OLA_ASSERT_EQ(string("2001:db8:dead:beef:dead:beef:dead:beef"),
string_address5.ToString());

IPV6Address string_address6;
OLA_ASSERT_FALSE(IPV6Address::FromString("", &string_address6));
Expand All @@ -141,8 +150,10 @@ void IPV6AddressTest::testIPV6Address() {
OLA_ASSERT_EQ(string("::ffff:10.0.0.1"), addresses[0].ToString());
OLA_ASSERT_EQ(string("::ffff:172.16.4.1"), addresses[1].ToString());
OLA_ASSERT_EQ(string("::ffff:192.168.1.1"), addresses[2].ToString());
OLA_ASSERT_EQ(string("2001:db8:1234:5678:90ab:cdef:feed:face"), addresses[3].ToString());
OLA_ASSERT_EQ(string("2001:db8:dead:beef:dead:beef:dead:beef"), addresses[4].ToString());
OLA_ASSERT_EQ(string("2001:db8:1234:5678:90ab:cdef:feed:face"),
addresses[3].ToString());
OLA_ASSERT_EQ(string("2001:db8:dead:beef:dead:beef:dead:beef"),
addresses[4].ToString());

/* uint8_t mask = 255; // UINT8_MAX;
OLA_ASSERT_TRUE(
Expand Down

0 comments on commit 3cc1292

Please sign in to comment.