Skip to content
Snippets Groups Projects
Commit 161769f4 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

SockAddr: use host endianess for bitwise-shift operations

parent 9948079c
Branches
Tags
No related merge requests found
......@@ -94,7 +94,8 @@ SockAddr::isLoopback() const
{
switch (getFamily()) {
case AF_INET: {
uint8_t b1 = (uint8_t)(getIPv4().sin_addr.s_addr >> 24);
auto addr_host = ntohl(getIPv4().sin_addr.s_addr);
uint8_t b1 = (uint8_t)(addr_host >> 24);
return b1 == 127;
}
case AF_INET6:
......@@ -111,10 +112,11 @@ SockAddr::isPrivate() const
return true;
}
switch (getFamily()) {
case AF_INET:
case AF_INET: {
auto addr_host = ntohl(getIPv4().sin_addr.s_addr);
uint8_t b1, b2;
b1 = (uint8_t)(getIPv4().sin_addr.s_addr >> 24);
b2 = (uint8_t)((getIPv4().sin_addr.s_addr >> 16) & 0x0ff);
b1 = (uint8_t)(addr_host >> 24);
b2 = (uint8_t)((addr_host >> 16) & 0x0ff);
// 10.x.y.z
if (b1 == 10)
return true;
......@@ -125,6 +127,7 @@ SockAddr::isPrivate() const
if ((b1 == 192) && (b2 == 168))
return true;
return false;
}
case AF_INET6: {
const uint8_t* addr6 = reinterpret_cast<const uint8_t*>(&getIPv6().sin6_addr);
if (addr6[0] == 0xfc)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment