diff options
-rw-r--r-- | src/inet.c | 21 | ||||
-rw-r--r-- | test/test_getaddrinfo.lua | 15 |
2 files changed, 33 insertions, 3 deletions
@@ -176,9 +176,24 @@ static int inet_global_getaddrinfo(lua_State *L) | |||
176 | } | 176 | } |
177 | lua_newtable(L); | 177 | lua_newtable(L); |
178 | for (iterator = resolved; iterator; iterator = iterator->ai_next) { | 178 | for (iterator = resolved; iterator; iterator = iterator->ai_next) { |
179 | char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; | 179 | char hbuf[NI_MAXHOST] |
180 | getnameinfo(iterator->ai_addr, (socklen_t) iterator->ai_addrlen, hbuf, | 180 | #ifndef _WINDOWS |
181 | (socklen_t) sizeof(hbuf), sbuf, 0, NI_NUMERICHOST); | 181 | ,sbuf[NI_MAXSERV] |
182 | #endif | ||
183 | ; | ||
184 | ret = getnameinfo(iterator->ai_addr, (socklen_t) iterator->ai_addrlen, hbuf, | ||
185 | (socklen_t) sizeof(hbuf), | ||
186 | #ifdef _WINDOWS | ||
187 | NULL, 0, | ||
188 | #else | ||
189 | sbuf, 0, | ||
190 | #endif | ||
191 | NI_NUMERICHOST); | ||
192 | if(ret){ | ||
193 | lua_pushnil(L); | ||
194 | lua_pushstring(L, socket_gaistrerror(ret)); | ||
195 | return 2; | ||
196 | } | ||
182 | lua_pushnumber(L, i); | 197 | lua_pushnumber(L, i); |
183 | lua_newtable(L); | 198 | lua_newtable(L); |
184 | switch (iterator->ai_family) { | 199 | switch (iterator->ai_family) { |
diff --git a/test/test_getaddrinfo.lua b/test/test_getaddrinfo.lua new file mode 100644 index 0000000..4b52ff9 --- /dev/null +++ b/test/test_getaddrinfo.lua | |||
@@ -0,0 +1,15 @@ | |||
1 | local socket = require "socket" | ||
2 | local addresses = assert(socket.dns.getaddrinfo("localhost")) | ||
3 | assert(type(addresses) == 'table') | ||
4 | |||
5 | local ipv4mask = "^%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?$" | ||
6 | |||
7 | for i, alt in ipairs(addresses) do | ||
8 | if alt.family == 'inet' then | ||
9 | assert(type(alt.addr) == 'string') | ||
10 | assert(alt.addr:find(ipv4mask)) | ||
11 | assert(alt.addr == '127.0.0.1') | ||
12 | end | ||
13 | end | ||
14 | |||
15 | print("done!") | ||