Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add cares librares
  • Loading branch information
Ryan Phillips committed Sep 5, 2012
1 parent 9e12e4f commit 2dd4d4a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -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
1 change: 1 addition & 0 deletions deps/cares
Submodule cares added at dc6093
2 changes: 2 additions & 0 deletions luvit.gyp
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
41 changes: 26 additions & 15 deletions src/luv_dns.c
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 0 additions & 4 deletions src/luv_portability.h
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion src/luvit_init.c
Expand Up @@ -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;
Expand Down

0 comments on commit 2dd4d4a

Please sign in to comment.