Skip to content

Commit

Permalink
force getaddrinfo to call the callback with an error
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Phillips committed Jan 4, 2012
1 parent 3f3c47f commit c3de4d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/luv_dns.c
Expand Up @@ -446,18 +446,21 @@ int luv_dns_getHostByAddr(lua_State* L)
{
char address_buffer[sizeof(struct in6_addr)];
int length, family;
const char* name = luaL_checkstring(L, 1);
const char* ip = luaL_checkstring(L, 1);
luv_dns_ref_t* ref = luv_dns_store_callback(L, 2);

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

ares_gethostbyaddr(channel, address_buffer, length, family,
Expand Down
3 changes: 2 additions & 1 deletion tests/test-dns.lua
Expand Up @@ -36,7 +36,8 @@ dns.reverse('2001:4860:4860::8888', function(err, addresses)
end)

dns.reverse('bogus ip', function(err, addresses)
assert(false) -- never called
assert(type(err) ~= 'nil')
assert(type(addresses) == 'nil')
end)

dns.resolveMx('gmail.com', function(err, addresses)
Expand Down

0 comments on commit c3de4d4

Please sign in to comment.