Fix three issues previous cleanup introduces.

This commit is contained in:
Yang Tse 2007-12-03 19:57:18 +00:00
parent e1998e3b58
commit 15c304225f

View File

@ -58,8 +58,7 @@ static void addr_callback(void *arg, int status, int timeouts,
static void end_aquery(struct addr_query *aquery, int status, static void end_aquery(struct addr_query *aquery, int status,
struct hostent *host); struct hostent *host);
static int file_lookup(union ares_addr *addr, int family, struct hostent **host); static int file_lookup(union ares_addr *addr, int family, struct hostent **host);
static void ptr_rr_name(char *name, size_t len, int family, static void ptr_rr_name(char *name, int family, union ares_addr *addr);
union ares_addr *addr);
void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen, void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
int family, ares_host_callback callback, void *arg) int family, ares_host_callback callback, void *arg)
@ -111,7 +110,7 @@ static void next_lookup(struct addr_query *aquery)
switch (*p) switch (*p)
{ {
case 'b': case 'b':
ptr_rr_name(name, sizeof(name), aquery->family, &aquery->addr); ptr_rr_name(name, aquery->family, &aquery->addr);
aquery->remaining_lookups = p + 1; aquery->remaining_lookups = p + 1;
ares_query(aquery->channel, name, C_IN, T_PTR, addr_callback, ares_query(aquery->channel, name, C_IN, T_PTR, addr_callback,
aquery); aquery);
@ -245,21 +244,21 @@ static int file_lookup(union ares_addr *addr, int family, struct hostent **host)
return status; return status;
} }
static void ptr_rr_name(char *name, size_t len, int family, static void ptr_rr_name(char *name, int family, union ares_addr *addr)
union ares_addr *addr) { {
if (family == AF_INET) if (family == AF_INET)
{ {
in_addr_t s_addr = ntohl(addr->addr4.s_addr); unsigned long laddr = ntohl(addr->addr4.s_addr);
int a1 = (int)((s_addr >> 24) & 0xff); int a1 = (int)((laddr >> 24) & 0xff);
int a2 = (int)((s_addr >> 16) & 0xff); int a2 = (int)((laddr >> 16) & 0xff);
int a3 = (int)((s_addr >> 8) & 0xff); int a3 = (int)((laddr >> 8) & 0xff);
int a4 = (int)(s_addr & 0xff); int a4 = (int)(laddr & 0xff);
snprintf(name, len, "%d.%d.%d.%d.in-addr.arpa", a4, a3, a2, a1); sprintf(name, "%d.%d.%d.%d.in-addr.arpa", a4, a3, a2, a1);
} }
else else
{ {
unsigned char *bytes = (unsigned char *)&addr->addr6.s6_addr; unsigned char *bytes = (unsigned char *)&addr->addr6.s6_addr;
snprintf(name, len, sprintf(name,
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x." "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa", "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa",
bytes[15]&0xf, bytes[15] >> 4, bytes[14]&0xf, bytes[14] >> 4, bytes[15]&0xf, bytes[15] >> 4, bytes[14]&0xf, bytes[14] >> 4,