No need for inet_pton.

This commit is contained in:
Diego Nehab 2013-06-04 16:26:49 +08:00
parent 802567b7de
commit b1d1e721d1
3 changed files with 3 additions and 39 deletions

View File

@ -199,7 +199,7 @@ static int inet_global_getaddrinfo(lua_State *L)
lua_pushliteral(L, "family"); lua_pushliteral(L, "family");
lua_pushliteral(L, "inet6"); lua_pushliteral(L, "inet6");
lua_settable(L, -3); lua_settable(L, -3);
break;; break;
} }
lua_pushliteral(L, "addr"); lua_pushliteral(L, "addr");
lua_pushstring(L, hbuf); lua_pushstring(L, hbuf);
@ -487,8 +487,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 * Some systems do not provide these so that we provide our own.
* marvelously fast, but it works just fine.
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
#ifdef LUASOCKET_INET_ATON #ifdef LUASOCKET_INET_ATON
int inet_aton(const char *cp, struct in_addr *inp) int inet_aton(const char *cp, struct in_addr *inp)
@ -512,34 +511,7 @@ 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 LUASOCKET_INET_PTON #ifdef LUASOCKET_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) int inet_pton(int af, const char *src, void *dst)
{ {
struct addrinfo hints, *res; struct addrinfo hints, *res;

View File

@ -285,14 +285,6 @@ static int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name)
if (!lua_isnil(L, -1)) { if (!lua_isnil(L, -1)) {
if (lua_isnumber(L, -1)) { if (lua_isnumber(L, -1)) {
val.ipv6mr_interface = (unsigned int) lua_tonumber(L, -1); val.ipv6mr_interface = (unsigned int) lua_tonumber(L, -1);
#if 0
} else if (lua_isstring(L, -1)) {
if (!(val.ipv6mr_interface = if_nametoindex(lua_tostring(L, -1)))) {
lua_pushnil(L);
lua_pushstring(L, "nonexistent interface");
return 2;
}
#endif
} else } else
luaL_argerror(L, -1, "number 'interface' field expected"); luaL_argerror(L, -1, "number 'interface' field expected");
} }

View File

@ -146,4 +146,4 @@ sourcet["default"] = sourcet["until-closed"]
_M.source = _M.choose(sourcet) _M.source = _M.choose(sourcet)
return _M return _M