Subject: Re: Re: support for multiple entries in /etc/hosts

Re: Re: support for multiple entries in /etc/hosts

From: Ashish Sharma <asharma_at_rediffmail.com>
Date: 20 Mar 2007 04:46:37 -0000

Daniel Kindly find mentioned below the "diff -u" of my changes Thanks Ashish ------------------------------------------------------- --- ../test/c-ares-1.3.2/ares_gethostbyname.c 2006-08-07 02:15:33.000000000 +0530 +++ ares_gethostbyname.c 2007-03-16 14:09:39.000000000 +0530 @@ -117,7 +117,7 @@ { int status; const char *p; - struct hostent *host; + struct hostent *host = NULL; for (p = hquery->remaining_lookups; *p; p++) { @@ -152,7 +152,7 @@ { struct host_query *hquery = (struct host_query *) arg; ares_channel channel = hquery->channel; - struct hostent *host; + struct hostent *host = NULL; if (status == ARES_SUCCESS) { @@ -242,13 +242,89 @@ free(hostent.h_name); return 1; } +static void add_host(struct hostent *hostent, struct hostent **host) +{ + char **p; + char **h_addr_list = NULL; + struct hostent *hostptr = *host; + int count = 0; + int index = 0; + + if (hostptr == NULL) + { + *host = hostent; + return; + } + + for (p = hostptr->h_addr_list; *p; p++) + { + count++; + } + + for (p = hostent->h_addr_list; *p; p++) + { + count++; + } + + h_addr_list = malloc((count+1) * sizeof(char *)); + if (!h_addr_list) + { + ares_free_hostent(hostent); + return; + } + + for (p = hostptr->h_addr_list; *p; p++) + { + h_addr_list[index] = malloc(sizeof(struct in_addr)); + if (h_addr_list[index]) + { + memcpy(h_addr_list[index], *p, sizeof(struct in_addr)); + } + else + { + ares_free_hostent(hostent); + free(h_addr_list); + return; + } + index++; + } + + for(p = hostent->h_addr_list; *p; p++) + { + h_addr_list[index] = malloc(sizeof(struct in_addr)); + if (h_addr_list[index]) + { + memcpy(h_addr_list[index], *p, sizeof(struct in_addr)); + } + else + { + ares_free_hostent(hostent); + free(h_addr_list); + return; + } + index++; + } + + h_addr_list[index] = NULL; + + for (p = hostptr->h_addr_list; *p; p++) + { + free(*p); + } + free(hostptr->h_addr_list); + hostptr->h_addr_list = h_addr_list; + + ares_free_hostent(hostent); +} static int file_lookup(const char *name, int family, struct hostent **host) { FILE *fp; char **alias; int status; - + int match; + struct hostent *hostent = NULL; + #ifdef WIN32 char PATH_HOSTS[MAX_PATH]; if (IS_NT()) { @@ -284,20 +360,39 @@ while ((status = ares__get_hostent(fp, family, host)) == ARES_SUCCESS) { + match = 0; if (strcasecmp((*host)->h_name, name) == 0) - break; - for (alias = (*host)->h_aliases; *alias; alias++) + { + match = 1; + } + else + { + for (alias = (*host)->h_aliases; *alias; alias++) { if (strcasecmp(*alias, name) == 0) + { + match = 1; break; + } } - if (*alias) - break; - ares_free_hostent(*host); + } + if (match) + { + add_host(hostent, host); + } + else + { + ares_free_hostent(*host); + } } fclose(fp); if (status == ARES_EOF) - status = ARES_ENOTFOUND; + { + if ( *host) + status = ARES_SUCCESS; + else + status = ARES_ENOTFOUND; + } if (status != ARES_SUCCESS) *host = NULL; return status; --- ../test/c-ares-1.3.2/ares_free_hostent.c 2006-07-26 00:09:21.000000000 +0530 +++ ./ares_free_hostent.c 2007-03-16 14:14:56.000000000 +0530 @@ -33,6 +33,10 @@ for (p = host->h_aliases; *p; p++) free(*p); free(host->h_aliases); + for(p = host->h_addr_list; *p; p++) + { + free(*p); + } free(host->h_addr_list[0]); free(host->h_addr_list); free(host); ------------------------------------------------------------------ On Fri, 16 Mar 2007 Daniel Stenberg wrote : >On Fri, 16 Mar 2007, Ashish Sharma wrote: > >>I have added support for multiple entries in the /etc/hosts file; The changed files are ove ares-1.3.2; > >Can you please send your changes as 'diff -u' output instead? > >-- c-ares -- my preferred DNS asynch resolver library
Received on 2007-03-20