From: Miek Gieben Date: Tue, 19 Apr 2005 12:15:05 +0000 (+0000) Subject: parse the /etc/hosts and return a list with all the address you found X-Git-Tag: release-0.50~113 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87e62c3385894913f8a5dde4b17a07e81cf3f337;p=thirdparty%2Fldns.git parse the /etc/hosts and return a list with all the address you found there. See run-test19 for an example. The resolver doesn't do any with /etc/hosts (yet?) --- diff --git a/SHOWSTOPPERS b/SHOWSTOPPERS index 19c613f6..987a583e 100644 --- a/SHOWSTOPPERS +++ b/SHOWSTOPPERS @@ -1,2 +1,6 @@ ::0 is printed as :: any ip6 addr with closing 0 is not printed correctly + +--- + +XMALLOC return code checking (bail out?!!?) extra function diff --git a/higher.c b/higher.c index 0b905b94..128899f4 100644 --- a/higher.c +++ b/higher.c @@ -98,7 +98,10 @@ ldns_get_rr_list_hosts_frm_fp(FILE *fp) char *line; char *word; char *addr; + char *rr_str; ldns_buffer *linebuf; + ldns_rr *rr; + ldns_rr_list *list; bool ip6; linebuf = ldns_buffer_new(MAXLINE_LEN); @@ -107,7 +110,10 @@ ldns_get_rr_list_hosts_frm_fp(FILE *fp) line = XMALLOC(char, MAXLINE_LEN + 1); word = XMALLOC(char, MAXLINE_LEN + 1); addr = XMALLOC(char, MAXLINE_LEN + 1); + rr_str = XMALLOC(char, MAXLINE_LEN + 1); ip6 = false; + list = ldns_rr_list_new(); + rr = NULL; for(i = ldns_fget_token(fp, line, "\n", 0); i > 0; @@ -142,17 +148,22 @@ ldns_get_rr_list_hosts_frm_fp(FILE *fp) } else { /* la al la la */ if (ip6) { - printf("%s IN AAAA %s\n", addr, word); + snprintf(rr_str, MAXLINE_LEN, "%s IN AAAA %s", word, addr); } else { - printf("%s IN A %s\n", addr, word); + snprintf(rr_str, MAXLINE_LEN, "%s IN A %s", word, addr); } + rr = ldns_rr_new_frm_str(rr_str); } } + if (rr) { + ldns_rr_list_push_rr(list, rr); + } } FREE(line); FREE(word); FREE(addr); - return NULL; + FREE(rr_str); + return list; } diff --git a/ldns/higher.h b/ldns/higher.h index 624451ff..4f927be1 100644 --- a/ldns/higher.h +++ b/ldns/higher.h @@ -49,7 +49,7 @@ ldns_get_rr_list_name_by_addr(ldns_resolver *r, ldns_rdf *addr, ldns_rr_class c, * \param[in] fp the file pointer to use * \return ldns_rr_list * with the names */ -ldns_rr_list * ldns_get_rr_list_host_frm_fp(FILE *fp); +ldns_rr_list * ldns_get_rr_list_hosts_frm_fp(FILE *fp); /** * wade through fp (a /etc/hosts like file) @@ -58,4 +58,4 @@ ldns_rr_list * ldns_get_rr_list_host_frm_fp(FILE *fp); * \param[in] filename the filename to use (NULL for /etc/hosts) * \return ldns_rr_list * with the names */ -ldns_rr_list * ldns_get_rr_list_host_frm_file(char *filename); +ldns_rr_list * ldns_get_rr_list_hosts_frm_file(char *filename); diff --git a/run-test19.c b/run-test19.c index a9558ba5..09bf81e2 100644 --- a/run-test19.c +++ b/run-test19.c @@ -19,6 +19,7 @@ main() { ldns_resolver *r; ldns_rdf *aaaa; + ldns_rr_list *hosts; r = ldns_resolver_new_frm_file(NULL); if (!r) { @@ -28,7 +29,11 @@ main() aaaa = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_AAAA, "::0"); ldns_rdf_print(stdout, aaaa); printf("\n\n"); - ldns_resolver_print(stdout, r); + + hosts = ldns_get_rr_list_hosts_frm_file(NULL); + + ldns_rr_list_print(stdout, hosts); + return 0; }