diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-11-18 16:36:57 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-11-18 16:36:57 +0000 |
commit | c9d3abd34a3a0b9b5a429c48de017dee51daf81f (patch) | |
tree | 7d035a5ff4ea5f6d16061cee6344c89a4a46e3dc /src/lua/lua_ip.c | |
parent | 6f0c375b601ba427261bec0d00c4d07f14b0d51b (diff) | |
download | rspamd-c9d3abd34a3a0b9b5a429c48de017dee51daf81f.tar.gz rspamd-c9d3abd34a3a0b9b5a429c48de017dee51daf81f.zip |
Fix ipv6 addresses exporting.
Diffstat (limited to 'src/lua/lua_ip.c')
-rw-r--r-- | src/lua/lua_ip.c | 41 |
1 files changed, 29 insertions, 12 deletions
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 */ |