mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-27 04:48:21 +01:00
Added inet_pton/inet_ntop for MinGW on Windows; compiles with Lua52.
This commit is contained in:
parent
d548a78e55
commit
5a58786a39
9
build-mingw.sh
Normal file
9
build-mingw.sh
Normal file
@ -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; }
|
50
src/inet.c
50
src/inet.c
@ -507,4 +507,54 @@ int inet_aton(const char *cp, struct in_addr *inp)
|
|||||||
}
|
}
|
||||||
#endif
|
#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
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define INET_ATON
|
#define INET_ATON
|
||||||
|
#define INET_PTON
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int inet_open(lua_State *L);
|
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);
|
int inet_aton(const char *cp, struct in_addr *inp);
|
||||||
#endif
|
#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 */
|
#endif /* INET_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user