From 56dbda39ed07faf2c14427797fe104213f734e00 Mon Sep 17 00:00:00 2001 From: moteus Date: Mon, 27 May 2013 11:20:52 +0400 Subject: Fix. getaddrinfo returns garbage as address on Windows. Add. test_getaddrinfo.lua --- src/inet.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/inet.c b/src/inet.c index 5bc6364..b28852b 100644 --- a/src/inet.c +++ b/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) { -- cgit v1.2.3-55-g6feb