Skip to content

Commit 024e279

Browse files
Make IsCanonicalExternalIp independent of system endianness (#2113)
IsCanonicalExternalIp does not work on big endian systems like s390x. This change makes it so the check is always done in network endianness, effectively making it independent of the system. Change is only needed on IPv4 checks because IPv6 uses 64 bit integers filled with 1s, so endianness is irrelevant in that case. Co-authored-by: Jouko Virtanen <jvirtane@redhat.com>
1 parent dad1f4f commit 024e279

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

collector/lib/NetworkConnection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class Address {
139139
static bool IsCanonicalExternalIp(const Address& addr) {
140140
switch (addr.family_) {
141141
case Family::IPV4:
142-
return addr.data_[0] == 0xffffffffULL;
142+
return (addr.data_[0] & htonll(0xffffffff00000000ULL)) == htonll(0xffffffff00000000ULL);
143143
case Family::IPV6:
144144
return addr.data_[0] == 0xffffffffffffffffULL && addr.data_[1] == 0xffffffffffffffffULL;
145145
default:

collector/test/NetworkConnectionTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ TEST(TestIPNet, TestIsCanonicalExternalIp) {
172172
};
173173

174174
for (const auto& [address, expected] : tests) {
175-
EXPECT_EQ(Address::IsCanonicalExternalIp(address), expected);
175+
EXPECT_EQ(Address::IsCanonicalExternalIp(address), expected) << "Address under test: " << address;
176176
}
177177
}
178178

0 commit comments

Comments
 (0)