Fix. getaddrinfo returns garbage as address on Windows.
Add. test_getaddrinfo.luamaster
parent
fbe184f28a
commit
56dbda39ed
21
src/inet.c
21
src/inet.c
|
@ -176,9 +176,24 @@ static int inet_global_getaddrinfo(lua_State *L)
|
|||
}
|
||||
lua_newtable(L);
|
||||
for (iterator = resolved; iterator; iterator = iterator->ai_next) {
|
||||
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
||||
getnameinfo(iterator->ai_addr, (socklen_t) iterator->ai_addrlen, hbuf,
|
||||
(socklen_t) sizeof(hbuf), sbuf, 0, NI_NUMERICHOST);
|
||||
char hbuf[NI_MAXHOST]
|
||||
#ifndef _WINDOWS
|
||||
,sbuf[NI_MAXSERV]
|
||||
#endif
|
||||
;
|
||||
ret = getnameinfo(iterator->ai_addr, (socklen_t) iterator->ai_addrlen, hbuf,
|
||||
(socklen_t) sizeof(hbuf),
|
||||
#ifdef _WINDOWS
|
||||
NULL, 0,
|
||||
#else
|
||||
sbuf, 0,
|
||||
#endif
|
||||
NI_NUMERICHOST);
|
||||
if(ret){
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, socket_gaistrerror(ret));
|
||||
return 2;
|
||||
}
|
||||
lua_pushnumber(L, i);
|
||||
lua_newtable(L);
|
||||
switch (iterator->ai_family) {
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
local socket = require "socket"
|
||||
local addresses = assert(socket.dns.getaddrinfo("localhost"))
|
||||
assert(type(addresses) == 'table')
|
||||
|
||||
local ipv4mask = "^%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?$"
|
||||
|
||||
for i, alt in ipairs(addresses) do
|
||||
if alt.family == 'inet' then
|
||||
assert(type(alt.addr) == 'string')
|
||||
assert(alt.addr:find(ipv4mask))
|
||||
assert(alt.addr == '127.0.0.1')
|
||||
end
|
||||
end
|
||||
|
||||
print("done!")
|
Loading…
Reference in New Issue