diff options
| author | unknown <diego@csz852.win2k.cs.ust.hk> | 2013-05-24 18:33:43 +0800 |
|---|---|---|
| committer | unknown <diego@csz852.win2k.cs.ust.hk> | 2013-05-24 18:33:43 +0800 |
| commit | cbc77440c8d84487ed652ee65551df0f8592a53f (patch) | |
| tree | 4a6fc94d2ea9149990ff0fa86fa34f132d99ad13 | |
| parent | ca48baf495d57a592030db82d5e4407596f0afde (diff) | |
| parent | 571308a94e30f15669c1c5e2df4d7713885e8859 (diff) | |
| download | luasocket-cbc77440c8d84487ed652ee65551df0f8592a53f.tar.gz luasocket-cbc77440c8d84487ed652ee65551df0f8592a53f.tar.bz2 luasocket-cbc77440c8d84487ed652ee65551df0f8592a53f.zip | |
Merge branch 'lua52-mingw' of https://github.com/pkulchenko/luasocket into pkulchenko
| -rw-r--r-- | build-mingw.sh | 9 | ||||
| -rw-r--r-- | src/inet.c | 50 | ||||
| -rw-r--r-- | src/inet.h | 6 |
3 files changed, 65 insertions, 0 deletions
diff --git a/build-mingw.sh b/build-mingw.sh new file mode 100644 index 0000000..e636c2c --- /dev/null +++ b/build-mingw.sh | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | LUA=../lua-5.2.1/src/ | ||
| 2 | BUILD_FLAGS="-Wl,-s -O2 -shared -D LUA_COMPAT_MODULE -D IPV6_V6ONLY=27 -D WINVER=0x0501 -s -I src -I $LUA -L $LUA" | ||
| 3 | |||
| 4 | mkdir -p lib/mime lib/socket | ||
| 5 | gcc $BUILD_FLAGS -o "lib/mime/core.dll" src/mime.c -llua \ | ||
| 6 | || { echo "Error: failed to build LuaSocket/mime"; exit 1; } | ||
| 7 | gcc $BUILD_FLAGS -o "lib/socket/core.dll" \ | ||
| 8 | 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 \ | ||
| 9 | || { echo "Error: failed to build LuaSocket/socket"; exit 1; } | ||
| @@ -507,4 +507,54 @@ int inet_aton(const char *cp, struct in_addr *inp) | |||
| 507 | } | 507 | } |
| 508 | #endif | 508 | #endif |
| 509 | 509 | ||
| 510 | // inet_ntop/inet_pton for MinGW from http://mingw-users.1079350.n2.nabble.com/IPv6-getaddrinfo-amp-inet-ntop-td5891996.html | ||
| 510 | 511 | ||
| 512 | #ifdef INET_PTON | ||
| 513 | const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) | ||
| 514 | { | ||
| 515 | if (af == AF_INET) | ||
| 516 | { | ||
| 517 | struct sockaddr_in in; | ||
| 518 | memset(&in, 0, sizeof(in)); | ||
| 519 | in.sin_family = AF_INET; | ||
| 520 | memcpy(&in.sin_addr, src, sizeof(struct in_addr)); | ||
| 521 | getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST); | ||
| 522 | return dst; | ||
| 523 | } | ||
| 524 | else if (af == AF_INET6) | ||
| 525 | { | ||
| 526 | struct sockaddr_in6 in; | ||
| 527 | memset(&in, 0, sizeof(in)); | ||
| 528 | in.sin6_family = AF_INET6; | ||
| 529 | memcpy(&in.sin6_addr, src, sizeof(struct in_addr6)); | ||
| 530 | getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST); | ||
| 531 | return dst; | ||
| 532 | } | ||
| 533 | return NULL; | ||
| 534 | } | ||
| 535 | |||
| 536 | int inet_pton(int af, const char *src, void *dst) | ||
| 537 | { | ||
| 538 | struct addrinfo hints, *res, *ressave; | ||
| 539 | |||
| 540 | memset(&hints, 0, sizeof(struct addrinfo)); | ||
| 541 | hints.ai_family = af; | ||
| 542 | |||
| 543 | if (getaddrinfo(src, NULL, &hints, &res) != 0) | ||
| 544 | { | ||
| 545 | return -1; | ||
| 546 | } | ||
| 547 | |||
| 548 | ressave = res; | ||
| 549 | |||
| 550 | while (res) | ||
| 551 | { | ||
| 552 | memcpy(dst, res->ai_addr, res->ai_addrlen); | ||
| 553 | res = res->ai_next; | ||
| 554 | } | ||
| 555 | |||
| 556 | freeaddrinfo(ressave); | ||
| 557 | return 0; | ||
| 558 | } | ||
| 559 | |||
| 560 | #endif | ||
| @@ -20,6 +20,7 @@ | |||
| 20 | 20 | ||
| 21 | #ifdef _WIN32 | 21 | #ifdef _WIN32 |
| 22 | #define INET_ATON | 22 | #define INET_ATON |
| 23 | #define INET_PTON | ||
| 23 | #endif | 24 | #endif |
| 24 | 25 | ||
| 25 | int inet_open(lua_State *L); | 26 | int inet_open(lua_State *L); |
| @@ -42,4 +43,9 @@ int inet_optsocktype(lua_State* L, int narg, const char* def); | |||
| 42 | int inet_aton(const char *cp, struct in_addr *inp); | 43 | int inet_aton(const char *cp, struct in_addr *inp); |
| 43 | #endif | 44 | #endif |
| 44 | 45 | ||
| 46 | #ifdef INET_PTON | ||
| 47 | const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt); | ||
| 48 | int inet_pton(int af, const char *src, void *dst); | ||
| 49 | #endif | ||
| 50 | |||
| 45 | #endif /* INET_H */ | 51 | #endif /* INET_H */ |
