diff options
Diffstat (limited to 'libs')
-rw-r--r-- | libs/luci-lib-ip/src/ip.c | 20 | ||||
-rw-r--r-- | libs/luci-lib-jsonc/src/jsonc.c | 8 |
2 files changed, 15 insertions, 13 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); diff --git a/libs/luci-lib-jsonc/src/jsonc.c b/libs/luci-lib-jsonc/src/jsonc.c index 74839dd4f5..5abb738f5f 100644 --- a/libs/luci-lib-jsonc/src/jsonc.c +++ b/libs/luci-lib-jsonc/src/jsonc.c @@ -294,7 +294,7 @@ static bool visited(struct seen **sp, const void *ptr) { static struct json_object * _lua_to_json_rec(lua_State *L, int index, struct seen **seen) { - lua_Number nd, ni; + lua_Number nd; struct json_object *obj; const char *key; int i, max; @@ -364,10 +364,12 @@ static struct json_object * _lua_to_json_rec(lua_State *L, int index, return json_object_new_boolean(lua_toboolean(L, index)); case LUA_TNUMBER: + if (lua_isinteger(L, index)) + return json_object_new_int64(lua_tointeger(L, index)); + nd = lua_tonumber(L, index); - ni = lua_tointeger(L, index); - if (nd == ni) + if (isfinite(nd) && trunc(nd) == nd) return json_object_new_int64(nd); return json_object_new_double(nd); |