diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/inet.c | 80 | ||||
| -rw-r--r-- | src/makefile | 114 | ||||
| -rw-r--r-- | src/udp.c | 34 | ||||
| -rw-r--r-- | src/wsocket.c | 8 | ||||
| -rw-r--r-- | src/wsocket.h | 4 |
5 files changed, 142 insertions, 98 deletions
| @@ -385,7 +385,6 @@ const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm) | |||
| 385 | struct in6_addr addrany = IN6ADDR_ANY_INIT; | 385 | struct in6_addr addrany = IN6ADDR_ANY_INIT; |
| 386 | memset((char *) &sin6, 0, sizeof(sin6)); | 386 | memset((char *) &sin6, 0, sizeof(sin6)); |
| 387 | sin6.sin6_family = AF_UNSPEC; | 387 | sin6.sin6_family = AF_UNSPEC; |
| 388 | fprintf(stderr, "disconnecting\n"); | ||
| 389 | sin6.sin6_addr = addrany; | 388 | sin6.sin6_addr = addrany; |
| 390 | return socket_strerror(socket_connect(ps, (SA *) &sin6, | 389 | return socket_strerror(socket_connect(ps, (SA *) &sin6, |
| 391 | sizeof(sin6), tm)); | 390 | sizeof(sin6), tm)); |
| @@ -507,54 +506,49 @@ int inet_aton(const char *cp, struct in_addr *inp) | |||
| 507 | } | 506 | } |
| 508 | #endif | 507 | #endif |
| 509 | 508 | ||
| 510 | // inet_ntop/inet_pton for MinGW from http://mingw-users.1079350.n2.nabble.com/IPv6-getaddrinfo-amp-inet-ntop-td5891996.html | 509 | /*-------------------------------------------------------------------------*\ |
| 510 | * inet_ntop/inet_pton for MinGW from | ||
| 511 | * http://mingw-users.1079350.n2.nabble.com/IPv6-getaddrinfo-amp-inet-ntop-td5891996.html | ||
| 512 | \*-------------------------------------------------------------------------*/ | ||
| 511 | 513 | ||
| 512 | #ifdef INET_PTON | 514 | #ifdef INET_PTON |
| 513 | const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) | 515 | const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) |
| 514 | { | 516 | { |
| 515 | if (af == AF_INET) | 517 | if (af == AF_INET) { |
| 516 | { | 518 | struct sockaddr_in in; |
| 517 | struct sockaddr_in in; | 519 | memset(&in, 0, sizeof(in)); |
| 518 | memset(&in, 0, sizeof(in)); | 520 | in.sin_family = AF_INET; |
| 519 | in.sin_family = AF_INET; | 521 | memcpy(&in.sin_addr, src, sizeof(struct in_addr)); |
| 520 | memcpy(&in.sin_addr, src, sizeof(struct in_addr)); | 522 | getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in), |
| 521 | getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST); | 523 | dst, cnt, NULL, 0, NI_NUMERICHOST); |
| 522 | return dst; | 524 | return dst; |
| 523 | } | 525 | } else if (af == AF_INET6) { |
| 524 | else if (af == AF_INET6) | 526 | struct sockaddr_in6 in; |
| 525 | { | 527 | memset(&in, 0, sizeof(in)); |
| 526 | struct sockaddr_in6 in; | 528 | in.sin6_family = AF_INET6; |
| 527 | memset(&in, 0, sizeof(in)); | 529 | memcpy(&in.sin6_addr, src, sizeof(struct in_addr6)); |
| 528 | in.sin6_family = AF_INET6; | 530 | getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6), |
| 529 | memcpy(&in.sin6_addr, src, sizeof(struct in_addr6)); | 531 | dst, cnt, NULL, 0, NI_NUMERICHOST); |
| 530 | getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST); | 532 | return dst; |
| 531 | return dst; | 533 | } |
| 532 | } | 534 | return NULL; |
| 533 | return NULL; | ||
| 534 | } | 535 | } |
| 535 | 536 | ||
| 536 | int inet_pton(int af, const char *src, void *dst) | 537 | int inet_pton(int af, const char *src, void *dst) |
| 537 | { | 538 | { |
| 538 | struct addrinfo hints, *res, *ressave; | 539 | struct addrinfo hints, *res, *ressave; |
| 539 | 540 | memset(&hints, 0, sizeof(struct addrinfo)); | |
| 540 | memset(&hints, 0, sizeof(struct addrinfo)); | 541 | hints.ai_family = af; |
| 541 | hints.ai_family = af; | 542 | if (getaddrinfo(src, NULL, &hints, &res) != 0) { |
| 542 | 543 | return -1; | |
| 543 | if (getaddrinfo(src, NULL, &hints, &res) != 0) | 544 | } |
| 544 | { | 545 | ressave = res; |
| 545 | return -1; | 546 | while (res) { |
| 546 | } | 547 | memcpy(dst, res->ai_addr, res->ai_addrlen); |
| 547 | 548 | res = res->ai_next; | |
| 548 | ressave = res; | 549 | } |
| 549 | 550 | freeaddrinfo(ressave); | |
| 550 | while (res) | 551 | return 0; |
| 551 | { | ||
| 552 | memcpy(dst, res->ai_addr, res->ai_addrlen); | ||
| 553 | res = res->ai_next; | ||
| 554 | } | ||
| 555 | |||
| 556 | freeaddrinfo(ressave); | ||
| 557 | return 0; | ||
| 558 | } | 552 | } |
| 559 | 553 | ||
| 560 | #endif | 554 | #endif |
diff --git a/src/makefile b/src/makefile index a75d5a6..a6e0033 100644 --- a/src/makefile +++ b/src/makefile | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | # | 12 | # |
| 13 | # make PLAT=linux DEBUG=DEBUG LUAV=5.2 prefix=/sw | 13 | # make PLAT=linux DEBUG=DEBUG LUAV=5.2 prefix=/sw |
| 14 | 14 | ||
| 15 | # PLAT: linux macosx win32 | 15 | # PLAT: linux macosx win32 mingw |
| 16 | # platform to build for | 16 | # platform to build for |
| 17 | PLAT?=linux | 17 | PLAT?=linux |
| 18 | 18 | ||
| @@ -33,6 +33,9 @@ LUAINC_macosx?=$(LUAINC_macosx_base)/lua$(LUAV) | |||
| 33 | # FIXME default should this default to fink or to macports? | 33 | # FIXME default should this default to fink or to macports? |
| 34 | # What happens when more than one Lua version is installed? | 34 | # What happens when more than one Lua version is installed? |
| 35 | LUAPREFIX_macosx?=/opt/local | 35 | LUAPREFIX_macosx?=/opt/local |
| 36 | CDIR_macosx?=lib/lua/$(LUAV) | ||
| 37 | LDIR_macosx?=share/lua/$(LUAV) | ||
| 38 | |||
| 36 | 39 | ||
| 37 | # LUAINC_linux: | 40 | # LUAINC_linux: |
| 38 | # /usr/include/lua$(LUAV) | 41 | # /usr/include/lua$(LUAV) |
| @@ -42,19 +45,38 @@ LUAPREFIX_macosx?=/opt/local | |||
| 42 | LUAINC_linux_base?=/usr/include | 45 | LUAINC_linux_base?=/usr/include |
| 43 | LUAINC_linux?=$(LUAINC_linux_base)/lua$(LUAV) | 46 | LUAINC_linux?=$(LUAINC_linux_base)/lua$(LUAV) |
| 44 | LUAPREFIX_linux?=/usr/local | 47 | LUAPREFIX_linux?=/usr/local |
| 48 | CDIR_linux?=lib/lua/$(LUAV) | ||
| 49 | LDIR_linux?=share/lua/$(LUAV) | ||
| 50 | |||
| 51 | # where lua headers are found for mingw builds | ||
| 52 | # LUAINC_mingw: | ||
| 53 | # /opt/local/include | ||
| 54 | LUAINC_mingw_base?=/usr/include | ||
| 55 | LUAINC_mingw?=$(LUAINC_mingw_base)/lua/$(LUAV) | ||
| 56 | LUALIB_mingw_base?=/usr/bin | ||
| 57 | LUALIB_mingw?=$(LUALIB_mingw_base)/lua/$(LUAV)/lua$(subst .,,$(LUAV)).dll | ||
| 58 | LUAPREFIX_mingw?=/usr | ||
| 59 | CDIR_mingw?=lua/$(LUAV) | ||
| 60 | LDIR_mingw?=lua/$(LUAV)/lua | ||
| 61 | |||
| 45 | 62 | ||
| 46 | # LUAINC_win32: | 63 | # LUAINC_win32: |
| 47 | # LUALIB_win32: | 64 | # LUALIB_win32: |
| 48 | # where lua headers and libraries are found for win32 builds | 65 | # where lua headers and libraries are found for win32 builds |
| 49 | LUAINC_win32?="../../lua-5.1.3/src" | 66 | LUAINC_win32?="../../lua-5.1.3/src" |
| 50 | LUALIB_win32?="../../lua-5.1.3" | 67 | LUALIB_win32?=/LIBPATH:"../../lua-5.1.3" lua$(LUAV).lib |
| 68 | |||
| 51 | LUAPREFIX_win32?= | 69 | LUAPREFIX_win32?= |
| 52 | # FIXME default should be where lua-for-windows puts lua | 70 | CDIR_win32?=lua/$(LUAV) |
| 71 | LDIR_win32?=lua/$(LUAV)/lua | ||
| 53 | 72 | ||
| 54 | # prefix: /usr/local /usr /opt/local /sw | 73 | # prefix: /usr/local /usr /opt/local /sw |
| 55 | # the top of the default install tree | 74 | # the top of the default install tree |
| 56 | prefix?=$(LUAPREFIX_$(PLAT)) | 75 | prefix?=$(LUAPREFIX_$(PLAT)) |
| 57 | 76 | ||
| 77 | CDIR?=$(CDIR_$(PLAT)) | ||
| 78 | LDIR?=$(LDIR_$(PLAT)) | ||
| 79 | |||
| 58 | # DESTDIR: (no default) | 80 | # DESTDIR: (no default) |
| 59 | # used by package managers to install into a temporary destination | 81 | # used by package managers to install into a temporary destination |
| 60 | DESTDIR= | 82 | DESTDIR= |
| @@ -63,13 +85,6 @@ DESTDIR= | |||
| 63 | # Definitions below can be overridden on the make command line, but | 85 | # Definitions below can be overridden on the make command line, but |
| 64 | # shouldn't have to be. | 86 | # shouldn't have to be. |
| 65 | 87 | ||
| 66 | print: | ||
| 67 | @echo PLAT=$(PLAT) | ||
| 68 | @echo LUAV=$(LUAV) | ||
| 69 | @echo DEBUG=$(DEBUG) | ||
| 70 | @echo prefix=$(prefix) | ||
| 71 | @echo LUAINC_$(PLAT)=$(LUAINC_$(PLAT)) | ||
| 72 | @echo LUALIB_$(PLAT)=$(LUALIB_$(PLAT)) | ||
| 73 | 88 | ||
| 74 | #------ | 89 | #------ |
| 75 | # Install directories | 90 | # Install directories |
| @@ -80,18 +95,28 @@ INSTALL_DATA=install -m644 | |||
| 80 | INSTALL_EXEC=install | 95 | INSTALL_EXEC=install |
| 81 | INSTALL_TOP=$(DESTDIR)$(prefix) | 96 | INSTALL_TOP=$(DESTDIR)$(prefix) |
| 82 | 97 | ||
| 83 | INSTALL_TOP_SHARE=$(INSTALL_TOP)/share/lua/$(LUAV) | 98 | INSTALL_TOP_LDIR=$(INSTALL_TOP)/$(LDIR) |
| 84 | INSTALL_TOP_LIB=$(INSTALL_TOP)/lib/lua/$(LUAV) | 99 | INSTALL_TOP_CDIR=$(INSTALL_TOP)/$(CDIR) |
| 100 | |||
| 101 | INSTALL_SOCKET_LDIR=$(INSTALL_TOP_LDIR)/socket | ||
| 102 | INSTALL_SOCKET_CDIR=$(INSTALL_TOP_CDIR)/socket | ||
| 103 | INSTALL_MIME_LDIR=$(INSTALL_TOP_LDIR)/mime | ||
| 104 | INSTALL_MIME_CDIR=$(INSTALL_TOP_CDIR)/mime | ||
| 85 | 105 | ||
| 86 | INSTALL_SOCKET_SHARE=$(INSTALL_TOP_SHARE)/socket | 106 | print: |
| 87 | INSTALL_SOCKET_LIB=$(INSTALL_TOP_LIB)/socket | 107 | @echo PLAT=$(PLAT) |
| 88 | INSTALL_MIME_SHARE=$(INSTALL_TOP_SHARE)/mime | 108 | @echo LUAV=$(LUAV) |
| 89 | INSTALL_MIME_LIB=$(INSTALL_TOP_LIB)/mime | 109 | @echo DEBUG=$(DEBUG) |
| 110 | @echo prefix=$(prefix) | ||
| 111 | @echo LUAINC_$(PLAT)=$(LUAINC_$(PLAT)) | ||
| 112 | @echo LUALIB_$(PLAT)=$(LUALIB_$(PLAT)) | ||
| 113 | @echo INSTALL_TOP_CDIR=$(INSTALL_TOP_CDIR) | ||
| 114 | @echo INSTALL_TOP_LDIR=$(INSTALL_TOP_LDIR) | ||
| 90 | 115 | ||
| 91 | #------ | 116 | #------ |
| 92 | # Supported platforms | 117 | # Supported platforms |
| 93 | # | 118 | # |
| 94 | PLATS= macosx linux win32 | 119 | PLATS= macosx linux win32 mingw |
| 95 | 120 | ||
| 96 | #------ | 121 | #------ |
| 97 | # Compiler and linker settings | 122 | # Compiler and linker settings |
| @@ -117,14 +142,30 @@ CC_linux=gcc | |||
| 117 | DEF_linux=-DLUASOCKET_$(DEBUG) -DLUA_COMPAT_MODULE \ | 142 | DEF_linux=-DLUASOCKET_$(DEBUG) -DLUA_COMPAT_MODULE \ |
| 118 | -DLUASOCKET_API='__attribute__((visibility("default")))' \ | 143 | -DLUASOCKET_API='__attribute__((visibility("default")))' \ |
| 119 | -DMIME_API='__attribute__((visibility("default")))' | 144 | -DMIME_API='__attribute__((visibility("default")))' |
| 120 | CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic \ | 145 | CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra \ |
| 121 | -fvisibility=hidden | 146 | -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden |
| 122 | LDFLAGS_linux=-O -shared -fpic -o | 147 | LDFLAGS_linux=-O -shared -fpic -o |
| 123 | LD_linux=gcc | 148 | LD_linux=gcc |
| 124 | SOCKET_linux=usocket.o | 149 | SOCKET_linux=usocket.o |
| 125 | 150 | ||
| 126 | #------ | 151 | #------ |
| 127 | # Compiler and linker settings | 152 | # Compiler and linker settings |
| 153 | # for MingW | ||
| 154 | SO_mingw=dll | ||
| 155 | O_mingw=o | ||
| 156 | CC_mingw=gcc | ||
| 157 | DEF_mingw= -DLUASOCKET_$(DEBUG) -DLUA_COMPAT_MODULE -DWINVER=0x0501 \ | ||
| 158 | -DLUASOCKET_API='__declspec(dllexport)' \ | ||
| 159 | -DMIME_API='__declspec(dllexport)' | ||
| 160 | CFLAGS_mingw= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \ | ||
| 161 | -fvisibility=hidden | ||
| 162 | LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lwsock32 -lws2_32 -o | ||
| 163 | LD_mingw=gcc | ||
| 164 | SOCKET_mingw=wsocket.o | ||
| 165 | |||
| 166 | |||
| 167 | #------ | ||
| 168 | # Compiler and linker settings | ||
| 128 | # for Win32 | 169 | # for Win32 |
| 129 | SO_win32=dll | 170 | SO_win32=dll |
| 130 | O_win32=obj | 171 | O_win32=obj |
| @@ -135,12 +176,10 @@ DEF_win32= /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" \ | |||
| 135 | /D "LUASOCKET_$(DEBUG)" | 176 | /D "LUASOCKET_$(DEBUG)" |
| 136 | CFLAGS_win32=/I "$(LUAINC)" $(DEF) /O2 /Ot /MD /W3 /nologo | 177 | CFLAGS_win32=/I "$(LUAINC)" $(DEF) /O2 /Ot /MD /W3 /nologo |
| 137 | LDFLAGS_win32= /nologo /link /NOLOGO /DLL /INCREMENTAL:NO \ | 178 | LDFLAGS_win32= /nologo /link /NOLOGO /DLL /INCREMENTAL:NO \ |
| 138 | /LIBPATH:"$(LUALIB)" \ | 179 | /MANIFEST /MANIFESTFILE:"intermediate.manifest" \ |
| 139 | /MANIFEST \ | ||
| 140 | /MANIFESTFILE:"intermediate.manifest" \ | ||
| 141 | /MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ | 180 | /MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ |
| 142 | /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /DYNAMICBASE:NO \ | 181 | /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /DYNAMICBASE:NO \ |
| 143 | /MACHINE:X86 ws2_32.lib lua$(LUAV).lib /OUT: | 182 | /MACHINE:X86 $(LUALIB) ws2_32.lib /OUT: |
| 144 | LD_win32=cl | 183 | LD_win32=cl |
| 145 | SOCKET_win32=wsocket.obj | 184 | SOCKET_win32=wsocket.obj |
| 146 | 185 | ||
| @@ -223,7 +262,7 @@ SERIAL_OBJS:=\ | |||
| 223 | #------ | 262 | #------ |
| 224 | # Files to install | 263 | # Files to install |
| 225 | # | 264 | # |
| 226 | TO_SOCKET_SHARE= \ | 265 | TO_SOCKET_LDIR= \ |
| 227 | http.lua \ | 266 | http.lua \ |
| 228 | url.lua \ | 267 | url.lua \ |
| 229 | tp.lua \ | 268 | tp.lua \ |
| @@ -231,7 +270,7 @@ TO_SOCKET_SHARE= \ | |||
| 231 | headers.lua \ | 270 | headers.lua \ |
| 232 | smtp.lua | 271 | smtp.lua |
| 233 | 272 | ||
| 234 | TO_TOP_SHARE= \ | 273 | TO_TOP_LDIR= \ |
| 235 | ltn12.lua \ | 274 | ltn12.lua \ |
| 236 | socket.lua \ | 275 | socket.lua \ |
| 237 | mime.lua | 276 | mime.lua |
| @@ -250,6 +289,9 @@ win32: | |||
| 250 | linux: | 289 | linux: |
| 251 | $(MAKE) all-unix PLAT=linux | 290 | $(MAKE) all-unix PLAT=linux |
| 252 | 291 | ||
| 292 | mingw: | ||
| 293 | $(MAKE) all PLAT=mingw | ||
| 294 | |||
| 253 | none: | 295 | none: |
| 254 | @echo "Please run" | 296 | @echo "Please run" |
| 255 | @echo " make PLATFORM" | 297 | @echo " make PLATFORM" |
| @@ -273,21 +315,21 @@ $(SERIAL_SO): $(SERIAL_OBJS) | |||
| 273 | $(LD) $(SERIAL_OBJS) $(LDFLAGS)$@ | 315 | $(LD) $(SERIAL_OBJS) $(LDFLAGS)$@ |
| 274 | 316 | ||
| 275 | install: | 317 | install: |
| 276 | $(INSTALL_DIR) $(INSTALL_TOP_SHARE) | 318 | $(INSTALL_DIR) $(INSTALL_TOP_LDIR) |
| 277 | $(INSTALL_DATA) $(TO_TOP_SHARE) $(INSTALL_TOP_SHARE) | 319 | $(INSTALL_DATA) $(TO_TOP_LDIR) $(INSTALL_TOP_LDIR) |
| 278 | $(INSTALL_DIR) $(INSTALL_SOCKET_SHARE) | 320 | $(INSTALL_DIR) $(INSTALL_SOCKET_LDIR) |
| 279 | $(INSTALL_DATA) $(TO_SOCKET_SHARE) $(INSTALL_SOCKET_SHARE) | 321 | $(INSTALL_DATA) $(TO_SOCKET_LDIR) $(INSTALL_SOCKET_LDIR) |
| 280 | $(INSTALL_DIR) $(INSTALL_SOCKET_LIB) | 322 | $(INSTALL_DIR) $(INSTALL_SOCKET_CDIR) |
| 281 | $(INSTALL_EXEC) $(SOCKET_SO) $(INSTALL_SOCKET_LIB)/core.$(SO) | 323 | $(INSTALL_EXEC) $(SOCKET_SO) $(INSTALL_SOCKET_CDIR)/core.$(SO) |
| 282 | $(INSTALL_DIR) $(INSTALL_MIME_LIB) | 324 | $(INSTALL_DIR) $(INSTALL_MIME_CDIR) |
| 283 | $(INSTALL_EXEC) $(MIME_SO) $(INSTALL_MIME_LIB)/core.$(SO) | 325 | $(INSTALL_EXEC) $(MIME_SO) $(INSTALL_MIME_CDIR)/core.$(SO) |
| 284 | 326 | ||
| 285 | install-unix: install | 327 | install-unix: install |
| 286 | $(INSTALL_EXEC) $(UNIX_SO) $(INSTALL_SOCKET_LIB)/$(UNIX_SO) | 328 | $(INSTALL_EXEC) $(UNIX_SO) $(INSTALL_SOCKET_CDIR)/$(UNIX_SO) |
| 287 | $(INSTALL_EXEC) $(SERIAL_SO) $(INSTALL_SOCKET_LIB)/$(SERIAL_SO) | 329 | $(INSTALL_EXEC) $(SERIAL_SO) $(INSTALL_SOCKET_CDIR)/$(SERIAL_SO) |
| 288 | 330 | ||
| 289 | local: | 331 | local: |
| 290 | $(MAKE) install INSTALL_TOP_LIB=.. INSTALL_TOP_SHARE=.. | 332 | $(MAKE) install INSTALL_TOP_CDIR=.. INSTALL_TOP_LDIR=.. |
| 291 | 333 | ||
| 292 | clean: | 334 | clean: |
| 293 | rm -f $(SOCKET_SO) $(SOCKET_OBJS) $(SERIAL_OBJS) | 335 | rm -f $(SOCKET_SO) $(SOCKET_OBJS) $(SERIAL_OBJS) |
| @@ -159,7 +159,7 @@ static int meth_sendto(lua_State *L) { | |||
| 159 | struct sockaddr_in addr; | 159 | struct sockaddr_in addr; |
| 160 | memset(&addr, 0, sizeof(addr)); | 160 | memset(&addr, 0, sizeof(addr)); |
| 161 | if (!inet_pton(AF_INET, ip, &addr.sin_addr)) | 161 | if (!inet_pton(AF_INET, ip, &addr.sin_addr)) |
| 162 | luaL_argerror(L, 3, "invalid ip address"); | 162 | luaL_argerror(L, 3, "invalid ip address"); |
| 163 | addr.sin_family = AF_INET; | 163 | addr.sin_family = AF_INET; |
| 164 | addr.sin_port = htons(port); | 164 | addr.sin_port = htons(port); |
| 165 | timeout_markstart(tm); | 165 | timeout_markstart(tm); |
| @@ -171,7 +171,7 @@ static int meth_sendto(lua_State *L) { | |||
| 171 | struct sockaddr_in6 addr; | 171 | struct sockaddr_in6 addr; |
| 172 | memset(&addr, 0, sizeof(addr)); | 172 | memset(&addr, 0, sizeof(addr)); |
| 173 | if (!inet_pton(AF_INET6, ip, &addr.sin6_addr)) | 173 | if (!inet_pton(AF_INET6, ip, &addr.sin6_addr)) |
| 174 | luaL_argerror(L, 3, "invalid ip address"); | 174 | luaL_argerror(L, 3, "invalid ip address"); |
| 175 | addr.sin6_family = AF_INET6; | 175 | addr.sin6_family = AF_INET6; |
| 176 | addr.sin6_port = htons(port); | 176 | addr.sin6_port = htons(port); |
| 177 | timeout_markstart(tm); | 177 | timeout_markstart(tm); |
| @@ -180,9 +180,9 @@ static int meth_sendto(lua_State *L) { | |||
| 180 | break; | 180 | break; |
| 181 | } | 181 | } |
| 182 | default: | 182 | default: |
| 183 | lua_pushnil(L); | 183 | lua_pushnil(L); |
| 184 | lua_pushfstring(L, "unknown family %d", udp->family); | 184 | lua_pushfstring(L, "unknown family %d", udp->family); |
| 185 | return 2; | 185 | return 2; |
| 186 | } | 186 | } |
| 187 | if (err != IO_DONE) { | 187 | if (err != IO_DONE) { |
| 188 | lua_pushnil(L); | 188 | lua_pushnil(L); |
| @@ -259,19 +259,19 @@ static int meth_receivefrom(lua_State *L) { | |||
| 259 | (SA *) &addr, &addr_len, tm); | 259 | (SA *) &addr, &addr_len, tm); |
| 260 | /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */ | 260 | /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */ |
| 261 | if (err == IO_CLOSED) | 261 | if (err == IO_CLOSED) |
| 262 | err = IO_DONE; | 262 | err = IO_DONE; |
| 263 | if (err == IO_DONE) { | 263 | if (err == IO_DONE) { |
| 264 | char addrstr[INET6_ADDRSTRLEN]; | 264 | char addrstr[INET6_ADDRSTRLEN]; |
| 265 | lua_pushlstring(L, buffer, got); | 265 | lua_pushlstring(L, buffer, got); |
| 266 | if (!inet_ntop(AF_INET6, &addr.sin6_addr, | 266 | if (!inet_ntop(AF_INET6, &addr.sin6_addr, |
| 267 | addrstr, sizeof(addrstr))) { | 267 | addrstr, sizeof(addrstr))) { |
| 268 | lua_pushnil(L); | 268 | lua_pushnil(L); |
| 269 | lua_pushstring(L, "invalid source address"); | 269 | lua_pushstring(L, "invalid source address"); |
| 270 | return 2; | 270 | return 2; |
| 271 | } | 271 | } |
| 272 | lua_pushstring(L, addrstr); | 272 | lua_pushstring(L, addrstr); |
| 273 | lua_pushnumber(L, ntohs(addr.sin6_port)); | 273 | lua_pushnumber(L, ntohs(addr.sin6_port)); |
| 274 | return 3; | 274 | return 3; |
| 275 | } | 275 | } |
| 276 | break; | 276 | break; |
| 277 | } | 277 | } |
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) { | |||
| 400 | case EAI_MEMORY: return "memory allocation failure"; | 400 | case EAI_MEMORY: return "memory allocation failure"; |
| 401 | case EAI_NONAME: | 401 | case EAI_NONAME: |
| 402 | return "host or service not provided, or not known"; | 402 | return "host or service not provided, or not known"; |
| 403 | // case EAI_OVERFLOW: return "argument buffer overflow"; | 403 | #ifdef EAI_OVERFLOW |
| 404 | case EAI_OVERFLOW: return "argument buffer overflow"; | ||
| 405 | #endif | ||
| 404 | #ifdef EAI_PROTOCOL | 406 | #ifdef EAI_PROTOCOL |
| 405 | case EAI_PROTOCOL: return "resolved protocol is unknown"; | 407 | case EAI_PROTOCOL: return "resolved protocol is unknown"; |
| 406 | #endif | 408 | #endif |
| 407 | case EAI_SERVICE: return "service not supported for socket type"; | 409 | case EAI_SERVICE: return "service not supported for socket type"; |
| 408 | case EAI_SOCKTYPE: return "ai_socktype not supported"; | 410 | case EAI_SOCKTYPE: return "ai_socktype not supported"; |
| 409 | // case EAI_SYSTEM: return strerror(errno); | 411 | #ifdef EAI_SYSTEM |
| 412 | case EAI_SYSTEM: return strerror(errno); | ||
| 413 | #endif | ||
| 410 | default: return gai_strerror(err); | 414 | default: return gai_strerror(err); |
| 411 | } | 415 | } |
| 412 | } | 416 | } |
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; | |||
| 16 | typedef SOCKET t_socket; | 16 | typedef SOCKET t_socket; |
| 17 | typedef t_socket *p_socket; | 17 | typedef t_socket *p_socket; |
| 18 | 18 | ||
| 19 | #ifndef IPV6_V6ONLY | ||
| 20 | #define IPV6_V6ONLY 27 | ||
| 21 | #endif | ||
| 22 | |||
| 19 | #define SOCKET_INVALID (INVALID_SOCKET) | 23 | #define SOCKET_INVALID (INVALID_SOCKET) |
| 20 | 24 | ||
| 21 | #ifndef SO_REUSEPORT | 25 | #ifndef SO_REUSEPORT |
