From 5a58786a39bbef7ed4805821cc921f1d40f12068 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Sun, 7 Apr 2013 12:39:56 -0700 Subject: [PATCH 01/13] Added inet_pton/inet_ntop for MinGW on Windows; compiles with Lua52. --- build-mingw.sh | 9 +++++++++ src/inet.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/inet.h | 6 ++++++ 3 files changed, 65 insertions(+) create mode 100644 build-mingw.sh diff --git a/build-mingw.sh b/build-mingw.sh new file mode 100644 index 0000000..2387ae6 --- /dev/null +++ b/build-mingw.sh @@ -0,0 +1,9 @@ +LUA=../lua-5.2.1/src/ +BUILD_FLAGS="-Wl,-s -O2 -shared -D LUA_COMPAT_MODULE -D IPV6_V6ONLY=1 -D WINVER=0x0501 -s -I src -I $LUA -L $LUA" + +mkdir -p lib/mime lib/socket +gcc $BUILD_FLAGS -o "lib/mime/core.dll" src/mime.c -llua \ + || { echo "Error: failed to build LuaSocket/mime"; exit 1; } +gcc $BUILD_FLAGS -o "lib/socket/core.dll" \ + src/{luasocket.c,auxiliar.c,buffer.c,except.c,inet.c,io.c,options.c,select.c,tcp.c,timeout.c,udp.c,wsocket.c} -lwsock32 -lws2_32 -llua \ + || { echo "Error: failed to build LuaSocket/socket"; exit 1; } diff --git a/src/inet.c b/src/inet.c index 69d32e6..1017022 100644 --- a/src/inet.c +++ b/src/inet.c @@ -507,4 +507,54 @@ int inet_aton(const char *cp, struct in_addr *inp) } #endif +// inet_ntop/inet_pton for MinGW from http://mingw-users.1079350.n2.nabble.com/IPv6-getaddrinfo-amp-inet-ntop-td5891996.html +#ifdef INET_PTON +const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) +{ + if (af == AF_INET) + { + struct sockaddr_in in; + memset(&in, 0, sizeof(in)); + in.sin_family = AF_INET; + memcpy(&in.sin_addr, src, sizeof(struct in_addr)); + getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST); + return dst; + } + else if (af == AF_INET6) + { + struct sockaddr_in6 in; + memset(&in, 0, sizeof(in)); + in.sin6_family = AF_INET6; + memcpy(&in.sin6_addr, src, sizeof(struct in_addr6)); + getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST); + return dst; + } + return NULL; +} + +int inet_pton(int af, const char *src, void *dst) +{ + struct addrinfo hints, *res, *ressave; + + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = af; + + if (getaddrinfo(src, NULL, &hints, &res) != 0) + { + return -1; + } + + ressave = res; + + while (res) + { + memcpy(dst, res->ai_addr, res->ai_addrlen); + res = res->ai_next; + } + + freeaddrinfo(ressave); + return 0; +} + +#endif diff --git a/src/inet.h b/src/inet.h index 4678ba6..2f72533 100644 --- a/src/inet.h +++ b/src/inet.h @@ -20,6 +20,7 @@ #ifdef _WIN32 #define INET_ATON +#define INET_PTON #endif int inet_open(lua_State *L); @@ -42,4 +43,9 @@ int inet_optsocktype(lua_State* L, int narg, const char* def); int inet_aton(const char *cp, struct in_addr *inp); #endif +#ifdef INET_PTON +const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt); +int inet_pton(int af, const char *src, void *dst); +#endif + #endif /* INET_H */ From 571308a94e30f15669c1c5e2df4d7713885e8859 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Tue, 9 Apr 2013 09:25:40 -0700 Subject: [PATCH 02/13] Updated IPV6_V6ONLY to match header files on Windows. --- build-mingw.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-mingw.sh b/build-mingw.sh index 2387ae6..e636c2c 100644 --- a/build-mingw.sh +++ b/build-mingw.sh @@ -1,5 +1,5 @@ LUA=../lua-5.2.1/src/ -BUILD_FLAGS="-Wl,-s -O2 -shared -D LUA_COMPAT_MODULE -D IPV6_V6ONLY=1 -D WINVER=0x0501 -s -I src -I $LUA -L $LUA" +BUILD_FLAGS="-Wl,-s -O2 -shared -D LUA_COMPAT_MODULE -D IPV6_V6ONLY=27 -D WINVER=0x0501 -s -I src -I $LUA -L $LUA" mkdir -p lib/mime lib/socket gcc $BUILD_FLAGS -o "lib/mime/core.dll" src/mime.c -llua \ From bb0b31301a43e740f30cf438f9f2b3e68fbd7698 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 25 May 2013 18:07:38 +0800 Subject: [PATCH 03/13] Add MingW support. --- makefile | 19 ++++++--- mingw.cmd | 1 + src/inet.c | 80 ++++++++++++++++------------------- src/makefile | 114 ++++++++++++++++++++++++++++++++++---------------- src/udp.c | 34 +++++++-------- src/wsocket.c | 8 +++- src/wsocket.h | 4 ++ 7 files changed, 157 insertions(+), 103 deletions(-) create mode 100644 mingw.cmd diff --git a/makefile b/makefile index f9fa6fe..04cd894 100644 --- a/makefile +++ b/makefile @@ -3,13 +3,14 @@ # see src/makefile for description of how to customize the build # # Targets: -# install install system independent support -# install-unix also install unix-only support -# install-both install both lua5.1 and lua5.2 socket support -# print print the build settings +# install install system independent support +# install-unix also install unix-only support +# install-both install for both lua5.1 and lua5.2 +# install-both-unix also install unix-only +# print print the build settings PLAT?= linux -PLATS= macosx linux win32 +PLATS= macosx linux win32 mingw all: $(PLAT) @@ -23,6 +24,14 @@ test: lua test/hello.lua install-both: + $(MAKE) clean + @cd src; $(MAKE) $(PLAT) LUAV=5.1 + @cd src; $(MAKE) install LUAV=5.1 + $(MAKE) clean + @cd src; $(MAKE) $(PLAT) LUAV=5.2 + @cd src; $(MAKE) install LUAV=5.2 + +install-both-unix: $(MAKE) clean @cd src; $(MAKE) $(PLAT) LUAV=5.1 @cd src; $(MAKE) install-unix LUAV=5.1 diff --git a/mingw.cmd b/mingw.cmd new file mode 100644 index 0000000..bf2b7ed --- /dev/null +++ b/mingw.cmd @@ -0,0 +1 @@ +make PLAT=mingw LUAINC_mingw_base=/home/diego/build/mingw/include LUALIB_mingw_base=/home/diego/build/mingw/bin LUAPREFIX_mingw=/home/diego/build/mingw/bin DEBUG=DEBUG install-both diff --git a/src/inet.c b/src/inet.c index 1017022..1530fef 100644 --- a/src/inet.c +++ b/src/inet.c @@ -385,7 +385,6 @@ const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm) struct in6_addr addrany = IN6ADDR_ANY_INIT; memset((char *) &sin6, 0, sizeof(sin6)); sin6.sin6_family = AF_UNSPEC; -fprintf(stderr, "disconnecting\n"); sin6.sin6_addr = addrany; return socket_strerror(socket_connect(ps, (SA *) &sin6, sizeof(sin6), tm)); @@ -507,54 +506,49 @@ int inet_aton(const char *cp, struct in_addr *inp) } #endif -// inet_ntop/inet_pton for MinGW from http://mingw-users.1079350.n2.nabble.com/IPv6-getaddrinfo-amp-inet-ntop-td5891996.html +/*-------------------------------------------------------------------------*\ +* inet_ntop/inet_pton for MinGW from +* http://mingw-users.1079350.n2.nabble.com/IPv6-getaddrinfo-amp-inet-ntop-td5891996.html +\*-------------------------------------------------------------------------*/ #ifdef INET_PTON -const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) +const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) { - if (af == AF_INET) - { - struct sockaddr_in in; - memset(&in, 0, sizeof(in)); - in.sin_family = AF_INET; - memcpy(&in.sin_addr, src, sizeof(struct in_addr)); - getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST); - return dst; - } - else if (af == AF_INET6) - { - struct sockaddr_in6 in; - memset(&in, 0, sizeof(in)); - in.sin6_family = AF_INET6; - memcpy(&in.sin6_addr, src, sizeof(struct in_addr6)); - getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST); - return dst; - } - return NULL; + if (af == AF_INET) { + struct sockaddr_in in; + memset(&in, 0, sizeof(in)); + in.sin_family = AF_INET; + memcpy(&in.sin_addr, src, sizeof(struct in_addr)); + getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in), + dst, cnt, NULL, 0, NI_NUMERICHOST); + return dst; + } else if (af == AF_INET6) { + struct sockaddr_in6 in; + memset(&in, 0, sizeof(in)); + in.sin6_family = AF_INET6; + memcpy(&in.sin6_addr, src, sizeof(struct in_addr6)); + getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6), + dst, cnt, NULL, 0, NI_NUMERICHOST); + return dst; + } + return NULL; } -int inet_pton(int af, const char *src, void *dst) +int inet_pton(int af, const char *src, void *dst) { - struct addrinfo hints, *res, *ressave; - - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = af; - - if (getaddrinfo(src, NULL, &hints, &res) != 0) - { - return -1; - } - - ressave = res; - - while (res) - { - memcpy(dst, res->ai_addr, res->ai_addrlen); - res = res->ai_next; - } - - freeaddrinfo(ressave); - return 0; + struct addrinfo hints, *res, *ressave; + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = af; + if (getaddrinfo(src, NULL, &hints, &res) != 0) { + return -1; + } + ressave = res; + while (res) { + memcpy(dst, res->ai_addr, res->ai_addrlen); + res = res->ai_next; + } + freeaddrinfo(ressave); + return 0; } #endif diff --git a/src/makefile b/src/makefile index a75d5a6..a6e0033 100644 --- a/src/makefile +++ b/src/makefile @@ -12,7 +12,7 @@ # # make PLAT=linux DEBUG=DEBUG LUAV=5.2 prefix=/sw -# PLAT: linux macosx win32 +# PLAT: linux macosx win32 mingw # platform to build for PLAT?=linux @@ -33,6 +33,9 @@ LUAINC_macosx?=$(LUAINC_macosx_base)/lua$(LUAV) # FIXME default should this default to fink or to macports? # What happens when more than one Lua version is installed? LUAPREFIX_macosx?=/opt/local +CDIR_macosx?=lib/lua/$(LUAV) +LDIR_macosx?=share/lua/$(LUAV) + # LUAINC_linux: # /usr/include/lua$(LUAV) @@ -42,19 +45,38 @@ LUAPREFIX_macosx?=/opt/local LUAINC_linux_base?=/usr/include LUAINC_linux?=$(LUAINC_linux_base)/lua$(LUAV) LUAPREFIX_linux?=/usr/local +CDIR_linux?=lib/lua/$(LUAV) +LDIR_linux?=share/lua/$(LUAV) + +# where lua headers are found for mingw builds +# LUAINC_mingw: +# /opt/local/include +LUAINC_mingw_base?=/usr/include +LUAINC_mingw?=$(LUAINC_mingw_base)/lua/$(LUAV) +LUALIB_mingw_base?=/usr/bin +LUALIB_mingw?=$(LUALIB_mingw_base)/lua/$(LUAV)/lua$(subst .,,$(LUAV)).dll +LUAPREFIX_mingw?=/usr +CDIR_mingw?=lua/$(LUAV) +LDIR_mingw?=lua/$(LUAV)/lua + # LUAINC_win32: # LUALIB_win32: # where lua headers and libraries are found for win32 builds LUAINC_win32?="../../lua-5.1.3/src" -LUALIB_win32?="../../lua-5.1.3" +LUALIB_win32?=/LIBPATH:"../../lua-5.1.3" lua$(LUAV).lib + LUAPREFIX_win32?= -# FIXME default should be where lua-for-windows puts lua +CDIR_win32?=lua/$(LUAV) +LDIR_win32?=lua/$(LUAV)/lua # prefix: /usr/local /usr /opt/local /sw # the top of the default install tree prefix?=$(LUAPREFIX_$(PLAT)) +CDIR?=$(CDIR_$(PLAT)) +LDIR?=$(LDIR_$(PLAT)) + # DESTDIR: (no default) # used by package managers to install into a temporary destination DESTDIR= @@ -63,13 +85,6 @@ DESTDIR= # Definitions below can be overridden on the make command line, but # shouldn't have to be. -print: - @echo PLAT=$(PLAT) - @echo LUAV=$(LUAV) - @echo DEBUG=$(DEBUG) - @echo prefix=$(prefix) - @echo LUAINC_$(PLAT)=$(LUAINC_$(PLAT)) - @echo LUALIB_$(PLAT)=$(LUALIB_$(PLAT)) #------ # Install directories @@ -80,18 +95,28 @@ INSTALL_DATA=install -m644 INSTALL_EXEC=install INSTALL_TOP=$(DESTDIR)$(prefix) -INSTALL_TOP_SHARE=$(INSTALL_TOP)/share/lua/$(LUAV) -INSTALL_TOP_LIB=$(INSTALL_TOP)/lib/lua/$(LUAV) +INSTALL_TOP_LDIR=$(INSTALL_TOP)/$(LDIR) +INSTALL_TOP_CDIR=$(INSTALL_TOP)/$(CDIR) -INSTALL_SOCKET_SHARE=$(INSTALL_TOP_SHARE)/socket -INSTALL_SOCKET_LIB=$(INSTALL_TOP_LIB)/socket -INSTALL_MIME_SHARE=$(INSTALL_TOP_SHARE)/mime -INSTALL_MIME_LIB=$(INSTALL_TOP_LIB)/mime +INSTALL_SOCKET_LDIR=$(INSTALL_TOP_LDIR)/socket +INSTALL_SOCKET_CDIR=$(INSTALL_TOP_CDIR)/socket +INSTALL_MIME_LDIR=$(INSTALL_TOP_LDIR)/mime +INSTALL_MIME_CDIR=$(INSTALL_TOP_CDIR)/mime + +print: + @echo PLAT=$(PLAT) + @echo LUAV=$(LUAV) + @echo DEBUG=$(DEBUG) + @echo prefix=$(prefix) + @echo LUAINC_$(PLAT)=$(LUAINC_$(PLAT)) + @echo LUALIB_$(PLAT)=$(LUALIB_$(PLAT)) + @echo INSTALL_TOP_CDIR=$(INSTALL_TOP_CDIR) + @echo INSTALL_TOP_LDIR=$(INSTALL_TOP_LDIR) #------ # Supported platforms # -PLATS= macosx linux win32 +PLATS= macosx linux win32 mingw #------ # Compiler and linker settings @@ -117,12 +142,28 @@ CC_linux=gcc DEF_linux=-DLUASOCKET_$(DEBUG) -DLUA_COMPAT_MODULE \ -DLUASOCKET_API='__attribute__((visibility("default")))' \ -DMIME_API='__attribute__((visibility("default")))' -CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic \ - -fvisibility=hidden +CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra \ + -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden LDFLAGS_linux=-O -shared -fpic -o LD_linux=gcc SOCKET_linux=usocket.o +#------ +# Compiler and linker settings +# for MingW +SO_mingw=dll +O_mingw=o +CC_mingw=gcc +DEF_mingw= -DLUASOCKET_$(DEBUG) -DLUA_COMPAT_MODULE -DWINVER=0x0501 \ + -DLUASOCKET_API='__declspec(dllexport)' \ + -DMIME_API='__declspec(dllexport)' +CFLAGS_mingw= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \ + -fvisibility=hidden +LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lwsock32 -lws2_32 -o +LD_mingw=gcc +SOCKET_mingw=wsocket.o + + #------ # Compiler and linker settings # for Win32 @@ -135,12 +176,10 @@ DEF_win32= /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" \ /D "LUASOCKET_$(DEBUG)" CFLAGS_win32=/I "$(LUAINC)" $(DEF) /O2 /Ot /MD /W3 /nologo LDFLAGS_win32= /nologo /link /NOLOGO /DLL /INCREMENTAL:NO \ - /LIBPATH:"$(LUALIB)" \ - /MANIFEST \ - /MANIFESTFILE:"intermediate.manifest" \ + /MANIFEST /MANIFESTFILE:"intermediate.manifest" \ /MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /DYNAMICBASE:NO \ - /MACHINE:X86 ws2_32.lib lua$(LUAV).lib /OUT: + /MACHINE:X86 $(LUALIB) ws2_32.lib /OUT: LD_win32=cl SOCKET_win32=wsocket.obj @@ -223,7 +262,7 @@ SERIAL_OBJS:=\ #------ # Files to install # -TO_SOCKET_SHARE= \ +TO_SOCKET_LDIR= \ http.lua \ url.lua \ tp.lua \ @@ -231,7 +270,7 @@ TO_SOCKET_SHARE= \ headers.lua \ smtp.lua -TO_TOP_SHARE= \ +TO_TOP_LDIR= \ ltn12.lua \ socket.lua \ mime.lua @@ -250,6 +289,9 @@ win32: linux: $(MAKE) all-unix PLAT=linux +mingw: + $(MAKE) all PLAT=mingw + none: @echo "Please run" @echo " make PLATFORM" @@ -273,21 +315,21 @@ $(SERIAL_SO): $(SERIAL_OBJS) $(LD) $(SERIAL_OBJS) $(LDFLAGS)$@ install: - $(INSTALL_DIR) $(INSTALL_TOP_SHARE) - $(INSTALL_DATA) $(TO_TOP_SHARE) $(INSTALL_TOP_SHARE) - $(INSTALL_DIR) $(INSTALL_SOCKET_SHARE) - $(INSTALL_DATA) $(TO_SOCKET_SHARE) $(INSTALL_SOCKET_SHARE) - $(INSTALL_DIR) $(INSTALL_SOCKET_LIB) - $(INSTALL_EXEC) $(SOCKET_SO) $(INSTALL_SOCKET_LIB)/core.$(SO) - $(INSTALL_DIR) $(INSTALL_MIME_LIB) - $(INSTALL_EXEC) $(MIME_SO) $(INSTALL_MIME_LIB)/core.$(SO) + $(INSTALL_DIR) $(INSTALL_TOP_LDIR) + $(INSTALL_DATA) $(TO_TOP_LDIR) $(INSTALL_TOP_LDIR) + $(INSTALL_DIR) $(INSTALL_SOCKET_LDIR) + $(INSTALL_DATA) $(TO_SOCKET_LDIR) $(INSTALL_SOCKET_LDIR) + $(INSTALL_DIR) $(INSTALL_SOCKET_CDIR) + $(INSTALL_EXEC) $(SOCKET_SO) $(INSTALL_SOCKET_CDIR)/core.$(SO) + $(INSTALL_DIR) $(INSTALL_MIME_CDIR) + $(INSTALL_EXEC) $(MIME_SO) $(INSTALL_MIME_CDIR)/core.$(SO) install-unix: install - $(INSTALL_EXEC) $(UNIX_SO) $(INSTALL_SOCKET_LIB)/$(UNIX_SO) - $(INSTALL_EXEC) $(SERIAL_SO) $(INSTALL_SOCKET_LIB)/$(SERIAL_SO) + $(INSTALL_EXEC) $(UNIX_SO) $(INSTALL_SOCKET_CDIR)/$(UNIX_SO) + $(INSTALL_EXEC) $(SERIAL_SO) $(INSTALL_SOCKET_CDIR)/$(SERIAL_SO) local: - $(MAKE) install INSTALL_TOP_LIB=.. INSTALL_TOP_SHARE=.. + $(MAKE) install INSTALL_TOP_CDIR=.. INSTALL_TOP_LDIR=.. clean: rm -f $(SOCKET_SO) $(SOCKET_OBJS) $(SERIAL_OBJS) diff --git a/src/udp.c b/src/udp.c index 8e14fac..6e0de9f 100644 --- a/src/udp.c +++ b/src/udp.c @@ -159,7 +159,7 @@ static int meth_sendto(lua_State *L) { struct sockaddr_in addr; memset(&addr, 0, sizeof(addr)); if (!inet_pton(AF_INET, ip, &addr.sin_addr)) - luaL_argerror(L, 3, "invalid ip address"); + luaL_argerror(L, 3, "invalid ip address"); addr.sin_family = AF_INET; addr.sin_port = htons(port); timeout_markstart(tm); @@ -171,7 +171,7 @@ static int meth_sendto(lua_State *L) { struct sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); if (!inet_pton(AF_INET6, ip, &addr.sin6_addr)) - luaL_argerror(L, 3, "invalid ip address"); + luaL_argerror(L, 3, "invalid ip address"); addr.sin6_family = AF_INET6; addr.sin6_port = htons(port); timeout_markstart(tm); @@ -180,9 +180,9 @@ static int meth_sendto(lua_State *L) { break; } default: - lua_pushnil(L); - lua_pushfstring(L, "unknown family %d", udp->family); - return 2; + lua_pushnil(L); + lua_pushfstring(L, "unknown family %d", udp->family); + return 2; } if (err != IO_DONE) { lua_pushnil(L); @@ -259,19 +259,19 @@ static int meth_receivefrom(lua_State *L) { (SA *) &addr, &addr_len, tm); /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */ if (err == IO_CLOSED) - err = IO_DONE; + err = IO_DONE; if (err == IO_DONE) { - char addrstr[INET6_ADDRSTRLEN]; - lua_pushlstring(L, buffer, got); - if (!inet_ntop(AF_INET6, &addr.sin6_addr, - addrstr, sizeof(addrstr))) { - lua_pushnil(L); - lua_pushstring(L, "invalid source address"); - return 2; - } - lua_pushstring(L, addrstr); - lua_pushnumber(L, ntohs(addr.sin6_port)); - return 3; + char addrstr[INET6_ADDRSTRLEN]; + lua_pushlstring(L, buffer, got); + if (!inet_ntop(AF_INET6, &addr.sin6_addr, + addrstr, sizeof(addrstr))) { + lua_pushnil(L); + lua_pushstring(L, "invalid source address"); + return 2; + } + lua_pushstring(L, addrstr); + lua_pushnumber(L, ntohs(addr.sin6_port)); + return 3; } break; } diff --git a/src/wsocket.c b/src/wsocket.c index d6dd004..65f76bc 100644 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -400,13 +400,17 @@ const char *socket_gaistrerror(int err) { case EAI_MEMORY: return "memory allocation failure"; case EAI_NONAME: return "host or service not provided, or not known"; -// case EAI_OVERFLOW: return "argument buffer overflow"; +#ifdef EAI_OVERFLOW + case EAI_OVERFLOW: return "argument buffer overflow"; +#endif #ifdef EAI_PROTOCOL case EAI_PROTOCOL: return "resolved protocol is unknown"; #endif case EAI_SERVICE: return "service not supported for socket type"; case EAI_SOCKTYPE: return "ai_socktype not supported"; -// case EAI_SYSTEM: return strerror(errno); +#ifdef EAI_SYSTEM + case EAI_SYSTEM: return strerror(errno); +#endif default: return gai_strerror(err); } } diff --git a/src/wsocket.h b/src/wsocket.h index 0783b00..8fbc54d 100644 --- a/src/wsocket.h +++ b/src/wsocket.h @@ -16,6 +16,10 @@ typedef SOCKADDR_STORAGE t_sockaddr_storage; typedef SOCKET t_socket; typedef t_socket *p_socket; +#ifndef IPV6_V6ONLY +#define IPV6_V6ONLY 27 +#endif + #define SOCKET_INVALID (INVALID_SOCKET) #ifndef SO_REUSEPORT From 5d3a78b4a6ba5e71d526d62795f684c98eeee8eb Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Sat, 25 May 2013 18:10:46 +0800 Subject: [PATCH 04/13] Added my test command lines. --- .gitignore | 3 --- linux.cmd | 1 + macosx.cmd | 1 + win32.cmd | 12 ++++++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 linux.cmd create mode 100644 macosx.cmd create mode 100644 win32.cmd diff --git a/.gitignore b/.gitignore index 0e0b11f..4b30ae0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,4 @@ *.o *.so *.so.* -macosx.cmd -win32.cmd -linux.cmd diff --git a/linux.cmd b/linux.cmd new file mode 100644 index 0000000..dc7fcaa --- /dev/null +++ b/linux.cmd @@ -0,0 +1 @@ +make PLAT=linux LUAV=5.2 DEBUG=DEBUG diff --git a/macosx.cmd b/macosx.cmd new file mode 100644 index 0000000..f85141a --- /dev/null +++ b/macosx.cmd @@ -0,0 +1 @@ +make DEBUG=DEBUG PLAT=macosx LUAINC_macosx_base=/Users/diego/build/macosx LUAPREFIX_macosx=/Users/diego/build/macosx install-both diff --git a/win32.cmd b/win32.cmd new file mode 100644 index 0000000..48522f0 --- /dev/null +++ b/win32.cmd @@ -0,0 +1,12 @@ +make PLAT=win32 LUAV=5.2 LUAINC_win32='c:\cygwin\home\diego\build\include' LUALIB_win32='c:\cygwin\home\diego\build\bin\release' + +#!/bin/sh +for p in Release Debug x64/Release x64/Debug; do + for el in mime socket; do + for e in dll lib; do + cp $p/$el/core.$e ../bin/$p/$el/ + done; + done; + cp src/ltn12.lua src/socket.lua src/mime.lua ../bin/$p/ + cp src/http.lua src/url.lua src/tp.lua src/ftp.lua src/headers.lua src/smtp.lua ../bin/$p/socket/ +done; From 22107bb9fcb3eef565b93fb00d8f2cc8849ba08e Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Sat, 25 May 2013 07:25:02 -0300 Subject: [PATCH 05/13] Check linux build. --- linux.cmd | 2 +- src/makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/linux.cmd b/linux.cmd index dc7fcaa..bd59adc 100644 --- a/linux.cmd +++ b/linux.cmd @@ -1 +1 @@ -make PLAT=linux LUAV=5.2 DEBUG=DEBUG +make PLAT=linux DEBUG=DEBUG LUAINC_linux_base=/home/diego/build/linux/include LUAPREFIX_linux=/home/diego/build/linux diff --git a/src/makefile b/src/makefile index a6e0033..fbb26a0 100644 --- a/src/makefile +++ b/src/makefile @@ -29,7 +29,7 @@ DEBUG?=NODEBUG # LUAINC_macosx: # /opt/local/include LUAINC_macosx_base?=/opt/local/include -LUAINC_macosx?=$(LUAINC_macosx_base)/lua$(LUAV) +LUAINC_macosx?=$(LUAINC_macosx_base)/lua/$(LUAV) # FIXME default should this default to fink or to macports? # What happens when more than one Lua version is installed? LUAPREFIX_macosx?=/opt/local @@ -43,7 +43,7 @@ LDIR_macosx?=share/lua/$(LUAV) # /usr/local/include/lua$(LUAV) # where lua headers are found for linux builds LUAINC_linux_base?=/usr/include -LUAINC_linux?=$(LUAINC_linux_base)/lua$(LUAV) +LUAINC_linux?=$(LUAINC_linux_base)/lua/$(LUAV) LUAPREFIX_linux?=/usr/local CDIR_linux?=lib/lua/$(LUAV) LDIR_linux?=share/lua/$(LUAV) From 6d93fd7c8f04fecbcdc28994da8b8357f712463f Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Sun, 26 May 2013 15:18:13 +0800 Subject: [PATCH 06/13] Fix socket.connect Previous implementation was not making sure the socket had the same family as the addr returned by getaddrinfo. So instead of "connection refused", we could get "invalid argument", which was our fault. --- macosx.cmd | 2 +- src/tcp.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/macosx.cmd b/macosx.cmd index f85141a..46a0709 100644 --- a/macosx.cmd +++ b/macosx.cmd @@ -1 +1 @@ -make DEBUG=DEBUG PLAT=macosx LUAINC_macosx_base=/Users/diego/build/macosx LUAPREFIX_macosx=/Users/diego/build/macosx install-both +make DEBUG=DEBUG PLAT=macosx LUAINC_macosx_base=/Users/diego/build/macosx/include LUAPREFIX_macosx=/Users/diego/build/macosx install-both diff --git a/src/tcp.c b/src/tcp.c index 6734dc0..4b0451f 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -388,10 +388,20 @@ static int global_create6(lua_State *L) { return tcp_create(L, AF_INET6); } +const char *strfamily(int family) { + switch (family) { + case PF_UNSPEC: return "unspec"; + case PF_INET: return "inet"; + case PF_INET6: return "inet6"; + default: return "invalid"; + } +} + static const char *tryconnect6(const char *remoteaddr, const char *remoteserv, struct addrinfo *connecthints, p_tcp tcp) { struct addrinfo *iterator = NULL, *resolved = NULL; const char *err = NULL; + int i = 0; /* try resolving */ err = socket_gaistrerror(getaddrinfo(remoteaddr, remoteserv, connecthints, &resolved)); @@ -402,8 +412,13 @@ static const char *tryconnect6(const char *remoteaddr, const char *remoteserv, /* iterate over all returned addresses trying to connect */ for (iterator = resolved; iterator; iterator = iterator->ai_next) { p_timeout tm = timeout_markstart(&tcp->tm); - /* create new socket if one wasn't created by the bind stage */ - if (tcp->sock == SOCKET_INVALID) { + /* create new socket if necessary. if there was no + * bind, we need to create one for every new family + * that shows up while iterating. if there was a + * bind, all families will be the same and we will + * not enter this branch. */ + if (tcp->family != iterator->ai_family) { + socket_destroy(&tcp->sock); err = socket_strerror(socket_create(&tcp->sock, iterator->ai_family, iterator->ai_socktype, iterator->ai_protocol)); @@ -444,6 +459,7 @@ static int global_connect(lua_State *L) { timeout_init(&tcp->tm, -1, -1); buffer_init(&tcp->buf, &tcp->io, &tcp->tm); tcp->sock = SOCKET_INVALID; + tcp->family = PF_UNSPEC; /* allow user to pick local address and port */ memset(&bindhints, 0, sizeof(bindhints)); bindhints.ai_socktype = SOCK_STREAM; From 427220c7b177cdae2379ac419d975c69764ba8ee Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Sun, 26 May 2013 21:26:26 +0800 Subject: [PATCH 07/13] Merge tryconnect6 into inet_tryconnect. --- src/inet.c | 22 ++++++++++++++++++++-- src/inet.h | 2 +- src/tcp.c | 18 ++++++------------ src/udp.c | 3 ++- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/inet.c b/src/inet.c index 1530fef..5bc6364 100644 --- a/src/inet.c +++ b/src/inet.c @@ -396,7 +396,7 @@ const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm) /*-------------------------------------------------------------------------*\ * Tries to connect to remote address (address, port) \*-------------------------------------------------------------------------*/ -const char *inet_tryconnect(p_socket ps, const char *address, +const char *inet_tryconnect(p_socket ps, int *family, const char *address, const char *serv, p_timeout tm, struct addrinfo *connecthints) { struct addrinfo *iterator = NULL, *resolved = NULL; @@ -410,6 +410,23 @@ const char *inet_tryconnect(p_socket ps, const char *address, } for (iterator = resolved; iterator; iterator = iterator->ai_next) { timeout_markstart(tm); + /* create new socket if necessary. if there was no + * bind, we need to create one for every new family + * that shows up while iterating. if there was a + * bind, all families will be the same and we will + * not enter this branch. */ + if (*family != iterator->ai_family) { + socket_destroy(ps); + err = socket_strerror(socket_create(ps, iterator->ai_family, + iterator->ai_socktype, iterator->ai_protocol)); + if (err != NULL) { + freeaddrinfo(resolved); + return err; + } + *family = iterator->ai_family; + /* all sockets initially non-blocking */ + socket_setnonblocking(ps); + } /* try connecting to remote address */ err = socket_strerror(socket_connect(ps, (SA *) iterator->ai_addr, (socklen_t) iterator->ai_addrlen, tm)); @@ -424,7 +441,8 @@ const char *inet_tryconnect(p_socket ps, const char *address, /*-------------------------------------------------------------------------*\ * Tries to accept a socket \*-------------------------------------------------------------------------*/ -const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm) +const char *inet_tryaccept(p_socket server, int family, p_socket client, + p_timeout tm) { socklen_t len; t_sockaddr_storage addr; diff --git a/src/inet.h b/src/inet.h index 2f72533..252e293 100644 --- a/src/inet.h +++ b/src/inet.h @@ -26,7 +26,7 @@ int inet_open(lua_State *L); const char *inet_trycreate(p_socket ps, int family, int type); -const char *inet_tryconnect(p_socket ps, const char *address, +const char *inet_tryconnect(p_socket ps, int *family, const char *address, const char *serv, p_timeout tm, struct addrinfo *connecthints); const char *inet_trybind(p_socket ps, const char *address, const char *serv, struct addrinfo *bindhints); diff --git a/src/tcp.c b/src/tcp.c index 4b0451f..ca8eec2 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -248,7 +248,8 @@ static int meth_connect(lua_State *L) /* make sure we try to connect only to the same family */ connecthints.ai_family = tcp->family; timeout_markstart(&tcp->tm); - err = inet_tryconnect(&tcp->sock, address, port, &tcp->tm, &connecthints); + err = inet_tryconnect(&tcp->sock, &tcp->family, address, port, + &tcp->tm, &connecthints); /* have to set the class even if it failed due to non-blocking connects */ auxiliar_setclass(L, "tcp{client}", 1); if (err) { @@ -388,20 +389,11 @@ static int global_create6(lua_State *L) { return tcp_create(L, AF_INET6); } -const char *strfamily(int family) { - switch (family) { - case PF_UNSPEC: return "unspec"; - case PF_INET: return "inet"; - case PF_INET6: return "inet6"; - default: return "invalid"; - } -} - +#if 0 static const char *tryconnect6(const char *remoteaddr, const char *remoteserv, struct addrinfo *connecthints, p_tcp tcp) { struct addrinfo *iterator = NULL, *resolved = NULL; const char *err = NULL; - int i = 0; /* try resolving */ err = socket_gaistrerror(getaddrinfo(remoteaddr, remoteserv, connecthints, &resolved)); @@ -442,6 +434,7 @@ static const char *tryconnect6(const char *remoteaddr, const char *remoteserv, /* here, if err is set, we failed */ return err; } +#endif static int global_connect(lua_State *L) { const char *remoteaddr = luaL_checkstring(L, 1); @@ -479,7 +472,8 @@ static int global_connect(lua_State *L) { connecthints.ai_socktype = SOCK_STREAM; /* make sure we try to connect only to the same family */ connecthints.ai_family = bindhints.ai_family; - err = tryconnect6(remoteaddr, remoteserv, &connecthints, tcp); + err = inet_tryconnect(&tcp->sock, &tcp->family, remoteaddr, remoteserv, + &tcp->tm, &connecthints); if (err) { socket_destroy(&tcp->sock); lua_pushnil(L); diff --git a/src/udp.c b/src/udp.c index 6e0de9f..2a51d1c 100644 --- a/src/udp.c +++ b/src/udp.c @@ -376,7 +376,8 @@ static int meth_setpeername(lua_State *L) { /* make sure we try to connect only to the same family */ connecthints.ai_family = udp->family; if (connecting) { - err = inet_tryconnect(&udp->sock, address, port, tm, &connecthints); + err = inet_tryconnect(&udp->sock, &udp->family, address, + port, tm, &connecthints); if (err) { lua_pushnil(L); lua_pushstring(L, err); From fbe184f28af85cda61394790e8114c6143057364 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Sun, 26 May 2013 21:27:18 +0800 Subject: [PATCH 08/13] No need for build script: makefile target instead. --- build-mingw.sh | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 build-mingw.sh diff --git a/build-mingw.sh b/build-mingw.sh deleted file mode 100644 index e636c2c..0000000 --- a/build-mingw.sh +++ /dev/null @@ -1,9 +0,0 @@ -LUA=../lua-5.2.1/src/ -BUILD_FLAGS="-Wl,-s -O2 -shared -D LUA_COMPAT_MODULE -D IPV6_V6ONLY=27 -D WINVER=0x0501 -s -I src -I $LUA -L $LUA" - -mkdir -p lib/mime lib/socket -gcc $BUILD_FLAGS -o "lib/mime/core.dll" src/mime.c -llua \ - || { echo "Error: failed to build LuaSocket/mime"; exit 1; } -gcc $BUILD_FLAGS -o "lib/socket/core.dll" \ - src/{luasocket.c,auxiliar.c,buffer.c,except.c,inet.c,io.c,options.c,select.c,tcp.c,timeout.c,udp.c,wsocket.c} -lwsock32 -lws2_32 -llua \ - || { echo "Error: failed to build LuaSocket/socket"; exit 1; } From 56dbda39ed07faf2c14427797fe104213f734e00 Mon Sep 17 00:00:00 2001 From: moteus Date: Mon, 27 May 2013 11:20:52 +0400 Subject: [PATCH 09/13] Fix. getaddrinfo returns garbage as address on Windows. Add. test_getaddrinfo.lua --- src/inet.c | 21 ++++++++++++++++++--- test/test_getaddrinfo.lua | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 test/test_getaddrinfo.lua 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) { 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 @@ +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!") From e54f78c61cac7b0d7fe1e89d337b9ab06f40bdb0 Mon Sep 17 00:00:00 2001 From: moteus Date: Mon, 27 May 2013 11:25:31 +0400 Subject: [PATCH 10/13] Fix. setsockname fails with "*" as host. Add. test_bind.lua --- src/inet.c | 3 +++ src/tcp.c | 1 - test/test_bind.lua | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/test_bind.lua diff --git a/src/inet.c b/src/inet.c index b28852b..0469756 100644 --- a/src/inet.c +++ b/src/inet.c @@ -478,6 +478,9 @@ const char *inet_trybind(p_socket ps, const char *address, const char *serv, struct addrinfo *iterator = NULL, *resolved = NULL; const char *err = NULL; t_socket sock = *ps; + /* translate luasocket special values to C */ + if (strcmp(address, "*") == 0) address = NULL; + if (!serv) serv = "0"; /* try resolving */ err = socket_gaistrerror(getaddrinfo(address, serv, bindhints, &resolved)); if (err) { diff --git a/src/tcp.c b/src/tcp.c index ca8eec2..60c1e8a 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -222,7 +222,6 @@ static int meth_bind(lua_State *L) bindhints.ai_socktype = SOCK_STREAM; bindhints.ai_family = tcp->family; bindhints.ai_flags = AI_PASSIVE; - address = strcmp(address, "*")? address: NULL; err = inet_trybind(&tcp->sock, address, port, &bindhints); if (err) { lua_pushnil(L); diff --git a/test/test_bind.lua b/test/test_bind.lua new file mode 100644 index 0000000..93c42d7 --- /dev/null +++ b/test/test_bind.lua @@ -0,0 +1,6 @@ +local socket = require "socket" +local u = socket.udp() assert(u:setsockname("*", 5088)) u:close() +local u = socket.udp() assert(u:setsockname("*", 0)) u:close() +local t = socket.tcp() assert(t:bind("*", 5088)) t:close() +local t = socket.tcp() assert(t:bind("*", 0)) t:close() +print("done!") \ No newline at end of file From bd51d8c1a5bb30e6a358dee6e85963f777edfff4 Mon Sep 17 00:00:00 2001 From: moteus Date: Mon, 27 May 2013 11:26:35 +0400 Subject: [PATCH 11/13] Fix. Optional IPv6 test --- test/testclnt.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/testclnt.lua b/test/testclnt.lua index 8acb3d0..315783b 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua @@ -642,7 +642,10 @@ local tcp_methods = { "shutdown", } test_methods(socket.tcp(), tcp_methods) -test_methods(socket.tcp6(), tcp_methods) +do local sock = socket.tcp6() +if sock then test_methods(socket.tcp6(), tcp_methods) +else io.stderr:write("Warning! IPv6 does not support!\n") end +end local udp_methods = { "close", @@ -666,7 +669,10 @@ local udp_methods = { ------------------------------------------------------------------------ test_methods(socket.udp(), udp_methods) -test_methods(socket.udp6(), udp_methods) +do local sock = socket.tcp6() +if sock then test_methods(socket.udp6(), udp_methods) +else io.stderr:write("Warning! IPv6 does not support!\n") end +end test("partial receive") test_partialrecv() From 26704061a4e28eff573f02297e6da045d166afa4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 27 May 2013 20:30:06 +0800 Subject: [PATCH 12/13] Fix Visual Studio 2012 projects --- .gitignore | 12 ++++ Lua51.props | 28 +++++++++ Lua52.props | 28 +++++++++ mime.vcxproj | 54 ++++++++++++----- mime.vcxproj.filters | 16 +++++ socket.vcxproj | 133 ++++++++++++++++++++++++++++++++++++----- socket.vcxproj.filters | 51 ++++++++++++++++ src/inet.c | 4 +- src/inet.h | 7 +-- src/makefile | 39 ++++++------ 10 files changed, 316 insertions(+), 56 deletions(-) create mode 100644 Lua51.props create mode 100644 Lua52.props create mode 100644 mime.vcxproj.filters create mode 100644 socket.vcxproj.filters diff --git a/.gitignore b/.gitignore index 4b30ae0..8307483 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,16 @@ *.o *.so *.so.* +*.obj +*.lib +*.dll* +*.user +*.sdf +Lua.props +Debug +Release +*.manifest +*.swp +*.suo +x64 diff --git a/Lua51.props b/Lua51.props new file mode 100644 index 0000000..1bd6256 --- /dev/null +++ b/Lua51.props @@ -0,0 +1,28 @@ + + + + + ..\build\vc12\bin\lua\5.1\ + ..\build\vc12\bin\lua\5.1\ + ..\build\vc12\include\lua\5.1\ + lua51.lib + + + <_PropertySheetDisplayName>Lua51 + + + + + $(LUALIB_PATH) + + + $(LUABIN_PATH) + + + $(LUAINC_PATH) + + + $(LUALIB) + + + diff --git a/Lua52.props b/Lua52.props new file mode 100644 index 0000000..01afcfa --- /dev/null +++ b/Lua52.props @@ -0,0 +1,28 @@ + + + + + ..\build\vc12\bin\lua\5.2\ + ..\build\vc12\bin\lua\5.2\ + ..\build\vc12\include\lua\5.2\ + lua52.lib + + + <_PropertySheetDisplayName>Lua52 + + + + + $(LUALIB_PATH) + + + $(LUABIN_PATH) + + + $(LUAINC_PATH) + + + $(LUALIB) + + + diff --git a/mime.vcxproj b/mime.vcxproj index 95781f2..63f5452 100755 --- a/mime.vcxproj +++ b/mime.vcxproj @@ -21,6 +21,19 @@ + + + Document + copy %(FullPath) $(LUABIN_PATH)$(Configuration) + $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) + copy %(FullPath) $(LUABIN_PATH)$(Configuration) + $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) + copy %(FullPath) $(LUALIB_PATH)$(Platform)\$(Configuration) + copy %(FullPath) $(LUALIB_PATH)$(Platform)\$(Configuration) + $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) + $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) + + {128E8BD0-174A-48F0-8771-92B1E8D18713} Win32Proj @@ -52,25 +65,29 @@ + + + + <_ProjectFileVersion>11.0.50727.1 - $(SolutionDir)\$(Configuration)\mime\ + $(LUABIN_PATH)$(Configuration)\mime\ $(Configuration)\ true core @@ -78,23 +95,23 @@ true core - $(SolutionDir)$(Platform)\$(Configuration)\mime\ + $(LUABIN_PATH)$(Platform)\$(Configuration)\mime\ - $(SolutionDir)\$(Configuration)\mime\ + $(LUABIN_PATH)$(Configuration)\mime\ $(Configuration)\ false core false - $(SolutionDir)$(Platform)\$(Configuration)\mime\ + $(LUABIN_PATH)$(Platform)\$(Configuration)\mime\ core Disabled - ..\include;%(AdditionalIncludeDirectories) + $(LUAINC_PATH);%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUA_COMPAT_MODULE;%(PreprocessorDefinitions) true EnableFastChecks @@ -102,11 +119,12 @@ Level3 EditAndContinue + $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;%(AdditionalDependencies) + $(LUALIB);%(AdditionalDependencies) $(OutDir)$(TargetName).dll - ..\bin\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -114,12 +132,13 @@ $(OutDir)$(TargetName).lib MachineX86 + false Disabled - ..\include;%(AdditionalIncludeDirectories) + $(LUAINC_PATH);%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUA_COMPAT_MODULE;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL @@ -127,11 +146,12 @@ Level3 ProgramDatabase + $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;%(AdditionalDependencies) + $(LUALIB);%(AdditionalDependencies) $(OutDir)$(TargetName).dll - ..\bin\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -143,17 +163,18 @@ - ..\include;%(AdditionalIncludeDirectories) + $(LUAINC_PATH);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUA_COMPAT_MODULE;%(PreprocessorDefinitions) MultiThreadedDLL Level4 + $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;%(AdditionalDependencies) + $(LUALIB);%(AdditionalDependencies) $(OutDir)$(TargetName).dll - ..\bin\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories) true Windows true @@ -166,7 +187,7 @@ - ..\include;%(AdditionalIncludeDirectories) + $(LUAINC_PATH);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUA_COMPAT_MODULE;%(PreprocessorDefinitions) MultiThreadedDLL @@ -174,11 +195,12 @@ Level4 + $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;%(AdditionalDependencies) + $(LUALIB);%(AdditionalDependencies) $(OutDir)$(TargetName).dll - ..\bin\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) true Windows true diff --git a/mime.vcxproj.filters b/mime.vcxproj.filters new file mode 100644 index 0000000..621215b --- /dev/null +++ b/mime.vcxproj.filters @@ -0,0 +1,16 @@ + + + + + + + + {fad87a86-297c-4881-a114-73b967bb3c92} + + + + + cdir + + + \ No newline at end of file diff --git a/socket.vcxproj b/socket.vcxproj index 0256c90..53c5539 100755 --- a/socket.vcxproj +++ b/socket.vcxproj @@ -32,6 +32,98 @@ + + + Document + copy %(FullPath) $(LUABIN_PATH)$(Configuration) + copy %(FullPath) $(LUABIN_PATH)$(Configuration) + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration) + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration) + $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) + $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) + $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) + + + Document + copy %(FullPath) $(LUABIN_PATH)$(Configuration) + copy %(FullPath) $(LUABIN_PATH)$(Configuration) + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration) + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration) + $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) + $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) + $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) + + + + + Document + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + + + Document + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + + + Document + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + + + Document + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + + + Document + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + + + Document + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) + $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket + + {66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A} Win32Proj @@ -63,25 +155,29 @@ + + + + <_ProjectFileVersion>11.0.50727.1 - $(SolutionDir)\$(Configuration)\socket\ + $(LUALIB_PATH)$(Configuration)\socket\ $(Configuration)\ true core @@ -89,23 +185,23 @@ true core - $(SolutionDir)$(Platform)\$(Configuration)\socket\ + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\ - $(SolutionDir)\$(Configuration)\socket\ + $(LUALIB_PATH)$(Configuration)\socket\ $(Configuration)\ false core false - $(SolutionDir)$(Platform)\$(Configuration)\socket\ + $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\ core Disabled - ..\include;%(AdditionalIncludeDirectories) + $(LUAINC_PATH);%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUA_COMPAT_MODULE;LUASOCKET_DEBUG;%(PreprocessorDefinitions) true EnableFastChecks @@ -113,11 +209,12 @@ Level3 EditAndContinue + $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;ws2_32.lib;%(AdditionalDependencies) + $(LUALIB);wsock32.lib;ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - ..\bin\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -125,12 +222,13 @@ $(OutDir)$(TargetName).lib MachineX86 + false Disabled - ..\include;%(AdditionalIncludeDirectories) + $(LUAINC_PATH);%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUA_COMPAT_MODULE;LUASOCKET_DEBUG;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL @@ -138,11 +236,12 @@ Level3 ProgramDatabase + $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;ws2_32.lib;%(AdditionalDependencies) + $(LUALIB);wsock32.lib;ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - ..\bin\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -154,17 +253,18 @@ - ..\include;%(AdditionalIncludeDirectories) + $(LUAINC_PATH);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUA_COMPAT_MODULE;%(PreprocessorDefinitions) MultiThreadedDLL Level4 + $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;ws2_32.lib;%(AdditionalDependencies) + $(LUALIB);wsock32.lib;ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - ..\bin\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories) true Windows true @@ -177,7 +277,7 @@ - ..\include;%(AdditionalIncludeDirectories) + $(LUAINC_PATH);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUA_COMPAT_MODULE;%(PreprocessorDefinitions) MultiThreadedDLL @@ -185,11 +285,12 @@ Level4 + $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - lualib.lib;ws2_32.lib;%(AdditionalDependencies) + $(LUALIB);wsock32.lib;ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - ..\bin\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) true Windows true diff --git a/socket.vcxproj.filters b/socket.vcxproj.filters new file mode 100644 index 0000000..38f2f07 --- /dev/null +++ b/socket.vcxproj.filters @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + cdir + + + cdir + + + ldir + + + ldir + + + ldir + + + ldir + + + ldir + + + ldir + + + + + {b053460d-5439-4e3a-a2eb-c31a95b5691f} + + + {b301b82c-37cb-4e05-9333-194e92ed7a62} + + + \ No newline at end of file diff --git a/src/inet.c b/src/inet.c index 5bc6364..51e8cfe 100644 --- a/src/inet.c +++ b/src/inet.c @@ -502,7 +502,7 @@ const char *inet_trybind(p_socket ps, const char *address, const char *serv, * Some systems do not provide this so that we provide our own. It's not * marvelously fast, but it works just fine. \*-------------------------------------------------------------------------*/ -#ifdef INET_ATON +#ifdef LUASOCKET_INET_ATON int inet_aton(const char *cp, struct in_addr *inp) { unsigned int a = 0, b = 0, c = 0, d = 0; @@ -529,7 +529,7 @@ int inet_aton(const char *cp, struct in_addr *inp) * http://mingw-users.1079350.n2.nabble.com/IPv6-getaddrinfo-amp-inet-ntop-td5891996.html \*-------------------------------------------------------------------------*/ -#ifdef INET_PTON +#ifdef LUASOCKET_INET_PTON const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) { if (af == AF_INET) { diff --git a/src/inet.h b/src/inet.h index 252e293..1f1a96a 100644 --- a/src/inet.h +++ b/src/inet.h @@ -19,8 +19,7 @@ #include "timeout.h" #ifdef _WIN32 -#define INET_ATON -#define INET_PTON +#define LUASOCKET_INET_ATON #endif int inet_open(lua_State *L); @@ -39,11 +38,11 @@ int inet_meth_getsockname(lua_State *L, p_socket ps, int family); int inet_optfamily(lua_State* L, int narg, const char* def); int inet_optsocktype(lua_State* L, int narg, const char* def); -#ifdef INET_ATON +#ifdef LUASOCKET_INET_ATON int inet_aton(const char *cp, struct in_addr *inp); #endif -#ifdef INET_PTON +#ifdef LUASOCKET_INET_PTON const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt); int inet_pton(int af, const char *src, void *dst); #endif diff --git a/src/makefile b/src/makefile index fbb26a0..c44f4ef 100644 --- a/src/makefile +++ b/src/makefile @@ -63,12 +63,13 @@ LDIR_mingw?=lua/$(LUAV)/lua # LUAINC_win32: # LUALIB_win32: # where lua headers and libraries are found for win32 builds -LUAINC_win32?="../../lua-5.1.3/src" -LUALIB_win32?=/LIBPATH:"../../lua-5.1.3" lua$(LUAV).lib - +LUAINC_win32_base?= +LUAINC_win32?=$(LUAINC_win32_base)/lua/$(LUAV) +PLATFORM_win32?=Release LUAPREFIX_win32?= -CDIR_win32?=lua/$(LUAV) -LDIR_win32?=lua/$(LUAV)/lua +CDIR_win32?=lua/$(LUAV)/$(PLATFORM_win32) +LDIR_win32?=lua/$(LUAV)/$(PLATFORM_win32)/lua +LUALIB_win32?=$(LUAPREFIX_win32)/lua/$(LUAV)/$(PLATFORM_win32) # prefix: /usr/local /usr /opt/local /sw # the top of the default install tree @@ -154,8 +155,8 @@ SOCKET_linux=usocket.o SO_mingw=dll O_mingw=o CC_mingw=gcc -DEF_mingw= -DLUASOCKET_$(DEBUG) -DLUA_COMPAT_MODULE -DWINVER=0x0501 \ - -DLUASOCKET_API='__declspec(dllexport)' \ +DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) -DLUA_COMPAT_MODULE \ + -DWINVER=0x0501 -DLUASOCKET_API='__declspec(dllexport)' \ -DMIME_API='__declspec(dllexport)' CFLAGS_mingw= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \ -fvisibility=hidden @@ -170,23 +171,25 @@ SOCKET_mingw=wsocket.o SO_win32=dll O_win32=obj CC_win32=cl -DEF_win32= /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" \ - /D "LUASOCKET_API=__declspec(dllexport)" /D "_CRT_SECURE_NO_WARNINGS" \ - /D "_WINDLL" /D "LUA_COMPAT_MODULE" /D "MIME_API=__declspec(dllexport)" \ - /D "LUASOCKET_$(DEBUG)" -CFLAGS_win32=/I "$(LUAINC)" $(DEF) /O2 /Ot /MD /W3 /nologo -LDFLAGS_win32= /nologo /link /NOLOGO /DLL /INCREMENTAL:NO \ - /MANIFEST /MANIFESTFILE:"intermediate.manifest" \ - /MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ - /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /DYNAMICBASE:NO \ - /MACHINE:X86 $(LUALIB) ws2_32.lib /OUT: +DEF_win32= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \ + //D "LUASOCKET_API=__declspec(dllexport)" //D "_CRT_SECURE_NO_WARNINGS" \ + //D "_WINDLL" //D "LUA_COMPAT_MODULE" \ + //D "MIME_API=__declspec(dllexport)" \ + //D "LUASOCKET_$(DEBUG)" +CFLAGS_win32=//I "$(LUAINC)" $(DEF) //O2 //Ot //MD //W3 //nologo +LDFLAGS_win32= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \ + //MANIFEST //MANIFESTFILE:"intermediate.manifest" \ + //MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ + //SUBSYSTEM:WINDOWS //OPT:REF //OPT:ICF //DYNAMICBASE:NO \ + //MACHINE:X86 /LIBPATH:"$(shell cmd //c echo $(LUALIB))" lua$(subst .,,$(LUAV)).lib \ + wsock32.lib ws2_32.lib //OUT: LD_win32=cl SOCKET_win32=wsocket.obj .SUFFIXES: .obj .c.obj: - $(CC) $(CFLAGS) /Fo"$@" /c $< + $(CC) $(CFLAGS) //Fo"$@" //c $< #------ # Output file names From 834a3cf520637df0af9967e1f8ad9e40837771cb Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Mon, 27 May 2013 21:05:48 +0800 Subject: [PATCH 13/13] Simplifying getaddrinfo treatment. --- src/inet.c | 50 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/src/inet.c b/src/inet.c index eab325e..fe9769b 100644 --- a/src/inet.c +++ b/src/inet.c @@ -79,24 +79,22 @@ static int inet_global_tohostname(lua_State *L) { } static int inet_global_getnameinfo(lua_State *L) { + char hbuf[NI_MAXHOST]; + char sbuf[NI_MAXSERV]; int i, ret; - char host[1024]; - char serv[32]; struct addrinfo hints; struct addrinfo *resolved, *iter; - const char *node = luaL_optstring(L, 1, NULL); - const char *service = luaL_optstring(L, 2, NULL); + const char *host = luaL_optstring(L, 1, NULL); + const char *serv = luaL_optstring(L, 2, NULL); - if (!(node || service)) - luaL_error(L, "You have to specify a hostname, a service, or both"); + if (!(host || serv)) + luaL_error(L, "host and serv cannot be both nil"); memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; hints.ai_family = PF_UNSPEC; - /* getaddrinfo must get a node and a service argument */ - ret = getaddrinfo(node ? node : "127.0.0.1", service ? service : "7", - &hints, &resolved); + ret = getaddrinfo(host, serv, &hints, &resolved); if (ret != 0) { lua_pushnil(L); lua_pushstring(L, socket_gaistrerror(ret)); @@ -105,19 +103,19 @@ static int inet_global_getnameinfo(lua_State *L) { lua_newtable(L); for (i = 1, iter = resolved; iter; i++, iter = iter->ai_next) { - getnameinfo(iter->ai_addr, (socklen_t) iter->ai_addrlen, host, - node ? (socklen_t) sizeof(host) : 0, serv, service ? (socklen_t) sizeof(serv) : 0, 0); - - if (node) { + getnameinfo(iter->ai_addr, (socklen_t) iter->ai_addrlen, + hbuf, host? (socklen_t) sizeof(hbuf): 0, + sbuf, serv? (socklen_t) sizeof(sbuf): 0, 0); + if (host) { lua_pushnumber(L, i); - lua_pushstring(L, host); + lua_pushstring(L, hbuf); lua_settable(L, -3); } } freeaddrinfo(resolved); - if (service) { - lua_pushstring(L, serv); + if (serv) { + lua_pushstring(L, sbuf); return 2; } else { return 1; @@ -176,20 +174,10 @@ static int inet_global_getaddrinfo(lua_State *L) } lua_newtable(L); for (iterator = resolved; iterator; iterator = iterator->ai_next) { - 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){ + char hbuf[NI_MAXHOST]; + ret = getnameinfo(iterator->ai_addr, (socklen_t) iterator->ai_addrlen, + hbuf, (socklen_t) sizeof(hbuf), NULL, 0, NI_NUMERICHOST); + if (ret){ lua_pushnil(L); lua_pushstring(L, socket_gaistrerror(ret)); return 2; @@ -218,7 +206,6 @@ static int inet_global_getaddrinfo(lua_State *L) return 1; } - /*-------------------------------------------------------------------------*\ * Gets the host name \*-------------------------------------------------------------------------*/ @@ -237,7 +224,6 @@ static int inet_global_gethostname(lua_State *L) } - /*=========================================================================*\ * Lua methods \*=========================================================================*/