]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
parse the /etc/hosts and return a list with all the address you found
authorMiek Gieben <miekg@NLnetLabs.nl>
Tue, 19 Apr 2005 12:15:05 +0000 (12:15 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Tue, 19 Apr 2005 12:15:05 +0000 (12:15 +0000)
there. See run-test19 for an example. The resolver doesn't do any
with /etc/hosts (yet?)

SHOWSTOPPERS
higher.c
ldns/higher.h
run-test19.c

index 19c613f6ebe2caf10fb219a85d326435ce06458a..987a583e87f26ad44a815a4071b56905adfdf91a 100644 (file)
@@ -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
index 0b905b94b7f3ccef236fc39813ce3d3e0b036c5d..128899f455ad388e4baa2854ceca51f3cc53b347 100644 (file)
--- 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;
 }
 
 
index 624451ff79dc685bc6b4919b187cf3bcba40dd30..4f927be18b7f5c3e430aef25f4f61806d5de46da 100644 (file)
@@ -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);
index a9558ba5ef6ca65da3f22429ce360376b6f6a79b..09bf81e2dce9721db7e4b200b4292d3619fc531e 100644 (file)
@@ -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;
 }