From: Vsevolod Stakhov Date: Mon, 18 Nov 2013 16:36:57 +0000 (+0000) Subject: Fix ipv6 addresses exporting. X-Git-Tag: 0.6.0~52 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c9d3abd34a3a0b9b5a429c48de017dee51daf81f;p=rspamd.git Fix ipv6 addresses exporting. --- diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c index 89bb91ed0..1297f0403 100644 --- a/src/lua/lua_ip.c +++ b/src/lua/lua_ip.c @@ -71,9 +71,8 @@ lua_ip_to_table (lua_State *L) } ptr = (guint8 *)&ip->data; for (i = 1; i <= max; i ++, ptr ++) { - lua_pushnumber (L, i); lua_pushnumber (L, *ptr); - lua_settable (L, -3); + lua_rawseti (L, -2, i); } } else { @@ -89,7 +88,7 @@ lua_ip_str_octets (lua_State *L) struct rspamd_lua_ip *ip = lua_check_ip (L, 1); int max, i; guint8 *ptr; - char numbuf[4]; + char numbuf[8]; if (ip != NULL) { lua_newtable (L); @@ -101,10 +100,19 @@ lua_ip_str_octets (lua_State *L) } ptr = (guint8 *)&ip->data; for (i = 1; i <= max; i ++, ptr ++) { - rspamd_snprintf (numbuf, sizeof (numbuf), "%d", *ptr); - lua_pushnumber (L, i); - lua_pushstring (L, numbuf); - lua_settable (L, -3); + if (ip->af == AF_INET) { + rspamd_snprintf (numbuf, sizeof (numbuf), "%d", *ptr); + lua_pushstring (L, numbuf); + lua_rawseti (L, -2, i); + } + else { + rspamd_snprintf (numbuf, sizeof (numbuf), "%xd", (*ptr & 0xf0) >> 4); + lua_pushstring (L, numbuf); + lua_rawseti (L, -2, i*2 - 1); + rspamd_snprintf (numbuf, sizeof (numbuf), "%xd", *ptr & 0x0f); + lua_pushstring (L, numbuf); + lua_rawseti (L, -2, i*2); + } } } else { @@ -133,10 +141,19 @@ lua_ip_inversed_str_octets (lua_State *L) ptr = (guint8 *)&ip->data; ptr += max - 1; for (i = 1; i <= max; i ++, ptr --) { - rspamd_snprintf (numbuf, sizeof (numbuf), "%d", *ptr); - lua_pushnumber (L, i); - lua_pushstring (L, numbuf); - lua_settable (L, -3); + if (ip->af == AF_INET) { + rspamd_snprintf (numbuf, sizeof (numbuf), "%d", *ptr); + lua_pushstring (L, numbuf); + lua_rawseti (L, -2, i); + } + else { + rspamd_snprintf (numbuf, sizeof (numbuf), "%xd", *ptr & 0x0f); + lua_pushstring (L, numbuf); + lua_rawseti (L, -2, i*2 - 1); + rspamd_snprintf (numbuf, sizeof (numbuf), "%xd", (*ptr & 0xf0) >> 4); + lua_pushstring (L, numbuf); + lua_rawseti (L, -2, i*2); + } } } else { @@ -265,7 +282,7 @@ luaopen_ip (lua_State * L) lua_rawset (L, -3); luaL_register (L, NULL, iplib_m); - luaL_register (L, "ip", iplib_f); + luaL_register (L, "rspamd_ip", iplib_f); lua_pop (L, 1); /* remove metatable from stack */