Add MingW support.

This commit is contained in:
unknown 2013-05-25 18:07:38 +08:00
parent cbc77440c8
commit bb0b31301a
7 changed files with 157 additions and 103 deletions

View file

@ -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;
}