Skip to content
Permalink
Browse files

add cares librares

  • Loading branch information...
Ryan Phillips
Ryan Phillips committed Sep 5, 2012
1 parent 9e12e4f commit 2dd4d4a7b69ba491ee03fb7e02641b97e4fc4137
Showing with 33 additions and 20 deletions.
  1. +3 −0 .gitmodules
  2. +1 −0 deps/cares
  3. +2 −0 luvit.gyp
  4. +26 −15 src/luv_dns.c
  5. +0 −4 src/luv_portability.h
  6. +1 −1 src/luvit_init.c
@@ -30,3 +30,6 @@
path = tools/gyp
url = https://github.com/luvit/gyp.git
ignore = dirty
[submodule "deps/cares"]
path = deps/cares
url = git://github.com/piscisaureus/cares.git
Submodule cares added at dc6093
@@ -6,6 +6,7 @@
'deps/http-parser/http_parser.gyp:http_parser',
'deps/luajit.gyp:luajit',
'deps/luajit.gyp:libluajit',
'deps/cares/cares.gyp:cares',
'deps/yajl.gyp:yajl',
'deps/yajl.gyp:copy_headers',
'deps/uv/uv.gyp:uv',
@@ -16,6 +17,7 @@
'deps/http-parser/http_parser.gyp:http_parser',
'deps/luajit.gyp:luajit',
'deps/luajit.gyp:libluajit',
'deps/cares/cares.gyp:cares',
'deps/yajl.gyp:yajl',
'deps/uv/uv.gyp:uv',
'deps/luacrypto.gyp:luacrypto',
@@ -468,18 +468,24 @@ int luv_dns_getHostByAddr(lua_State* L)
int length, family;
const char* ip = luaL_checkstring(L, 1);
luv_dns_ref_t* ref = luv_dns_store_callback(L, 2);
uv_err_t err;

if (uv_inet_pton(AF_INET, ip, &address_buffer) == 1) {
err = uv_inet_pton(AF_INET, ip, &address_buffer);
if (err.code == 0) {
length = sizeof(struct in_addr);
family = AF_INET;
} else if (uv_inet_pton(AF_INET6, ip, &address_buffer) == 1) {
length = sizeof(struct in6_addr);
family = AF_INET6;
} else {
luv_dns_get_callback(ref);
luv_push_ares_async_error(ref->L, ARES_EBADSTR, "getHostByAddr");
luv_dns_ref_cleanup(ref);
return 0;
}
else {
err = uv_inet_pton(AF_INET6, ip, &address_buffer);
if (err.code == 0) {
length = sizeof(struct in6_addr);
family = AF_INET6;
} else {
luv_dns_get_callback(ref);
luv_push_ares_async_error(ref->L, ARES_EBADSTR, "getHostByAddr");
luv_dns_ref_cleanup(ref);
return 0;
}
}

ares_gethostbyaddr(channel, address_buffer, length, family,
@@ -546,15 +552,20 @@ int luv_dns_getAddrInfo(lua_State* L)
static int luv_dns__isIp(lua_State *L, const char *ip, int v4v6) {
int family;
char address_buffer[sizeof(struct in6_addr)];
uv_err_t err;

if (uv_inet_pton(AF_INET, ip, &address_buffer) == 1) {
err = uv_inet_pton(AF_INET, ip, &address_buffer);
if (err.code == 0) {
family = AF_INET;
} else if (uv_inet_pton(AF_INET6, ip, &address_buffer) == 1) {
family = AF_INET6;
} else {
/* failure */
lua_pushnumber(L, 0);
return 1;
err = uv_inet_pton(AF_INET6, ip, &address_buffer);
if (err.code == 0) {
family = AF_INET6;
} else {
/* failure */
lua_pushnumber(L, 0);
return 1;
}
}

if (v4v6 == 0) {
@@ -33,13 +33,9 @@
#if defined(__MINGW32__) || defined(_MSC_VER)
# include <inet_net_pton.h>
# include <inet_ntop.h>
# define uv_inet_pton ares_inet_pton
# define uv_inet_ntop ares_inet_ntop

#else /* __POSIX__ */
# include <arpa/inet.h>
# define uv_inet_pton inet_pton
# define uv_inet_ntop inet_ntop
#endif

/* Portable method of getting the environment. */
@@ -253,7 +253,7 @@ int luvit_init(lua_State *L, uv_loop_t* loop, int argc, char *argv[])
luv_set_loop(L, loop);

/* Store the ARES Channel */
uv_ares_init_options(luv_get_loop(L), &channel, &options, 0);
ares_init_options(&channel, &options, 0);
luv_set_ares_channel(L, channel);

return 0;

0 comments on commit 2dd4d4a

Please sign in to comment.
You can’t perform that action at this time.