1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Fix Address::isLocalhost algorithm

This commit is contained in:
Loic Blot 2019-02-09 19:52:38 +01:00
parent 7796a3118d
commit ff5d4ffe1c
No known key found for this signature in database
GPG key ID: EFAA458E8C153987
3 changed files with 74 additions and 4 deletions

View file

@ -277,13 +277,13 @@ bool Address::isLocalhost() const {
static const unsigned char localhost_bytes[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
static const unsigned char mapped_ipv4_localhost[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0x7f, 0, 0, 1};
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0x7f, 0, 0, 0};
auto addr = m_address.ipv6.sin6_addr.s6_addr;
return memcmp(addr, localhost_bytes, 16) == 0 ||
memcmp(addr, mapped_ipv4_localhost, 16) == 0;
} else {
return m_address.ipv4.sin_addr.s_addr == 0x0100007F;
memcmp(addr, mapped_ipv4_localhost, 13) == 0;
}
return (m_address.ipv4.sin_addr.s_addr & 0xFF) == 0x7f;
}