summaryrefslogtreecommitdiffhomepage
path: root/libs/luci-lib-ip
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2023-11-07 22:59:08 +0100
committerJo-Philipp Wich <jo@mein.io>2023-11-07 22:59:08 +0100
commitac7b37ef0133ab8349c8516d5a63a57a44dddafd (patch)
tree43227b5169d35c1aea1cc257d0a90cc37089426e /libs/luci-lib-ip
parent3508984fd7f0f4e4ddabf2b27532aae15589a761 (diff)
luci-lib-ip: fix creating address instances from integers
Ensure that the proper byte order is used when creating IPv4/IPv6/MAC instances from integer values on big endian systems. Fixes: #6678 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'libs/luci-lib-ip')
-rw-r--r--libs/luci-lib-ip/src/ip.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/libs/luci-lib-ip/src/ip.c b/libs/luci-lib-ip/src/ip.c
index 9b157da265..a624f3f83f 100644
--- a/libs/luci-lib-ip/src/ip.c
+++ b/libs/luci-lib-ip/src/ip.c
@@ -406,28 +406,28 @@ static int _cidr_new(lua_State *L, int index, int family, bool mask)
if (lua_type(L, index) == LUA_TNUMBER)
{
- n = htonl(lua_tointeger(L, index));
+ n = lua_tointeger(L, index);
if (family == AF_INET6)
{
cidr.family = AF_INET6;
- cidr.addr.v6.s6_addr[12] = n;
- cidr.addr.v6.s6_addr[13] = (n >> 8);
- cidr.addr.v6.s6_addr[14] = (n >> 16);
- cidr.addr.v6.s6_addr[15] = (n >> 24);
+ cidr.addr.v6.s6_addr[12] = n / 0x1000000;
+ cidr.addr.v6.s6_addr[13] = n % 0x1000000 / 0x10000;
+ cidr.addr.v6.s6_addr[14] = n % 0x10000 / 0x100;
+ cidr.addr.v6.s6_addr[15] = n % 0x100;
}
else if (family == AF_INET)
{
cidr.family = AF_INET;
- cidr.addr.v4.s_addr = n;
+ cidr.addr.v4.s_addr = htonl(n);
}
else
{
cidr.family = AF_PACKET;
- cidr.addr.mac.ether_addr_octet[2] = n;
- cidr.addr.mac.ether_addr_octet[3] = (n >> 8);
- cidr.addr.mac.ether_addr_octet[4] = (n >> 16);
- cidr.addr.mac.ether_addr_octet[5] = (n >> 24);
+ cidr.addr.mac.ether_addr_octet[2] = n / 0x1000000;
+ cidr.addr.mac.ether_addr_octet[3] = n % 0x1000000 / 0x10000;
+ cidr.addr.mac.ether_addr_octet[4] = n % 0x10000 / 0x100;
+ cidr.addr.mac.ether_addr_octet[5] = n % 0x100;
}
cidr.bits = AF_BITS(cidr.family);