]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
getline prob is gnu-ism...
authorMiek Gieben <miekg@NLnetLabs.nl>
Tue, 1 Mar 2005 15:28:51 +0000 (15:28 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Tue, 1 Mar 2005 15:28:51 +0000 (15:28 +0000)
ldns/resolver.h
resolver.c

index b1ca2cf950aab8a40b72c0081046f5559568256a..0382869469688dd13544f3c479d76fbee1df2e6b 100644 (file)
 #include <ldns/packet.h>
 #include <sys/time.h>
 
+
+/** \brief where to find the resolv.conf file */
+#define RESOLV_CONF    "/etc/resolv.conf"
+#define MAXLINE_LEN    256
+
 /**
  * \brief Structure of a dns resolver
  *
@@ -107,6 +112,7 @@ ldns_pkt * ldns_resolver_query(ldns_resolver *, ldns_rdf*, ldns_rr_type, ldns_rr
 ldns_pkt * ldns_resolver_search(ldns_resolver *, ldns_rdf*, ldns_rr_type, ldns_rr_class, uint16_t);
 
 ldns_resolver *ldns_resolver_new(void);
+ldns_resolver *ldns_resolver_new_frm_file(const char *);
 void ldns_resolver_free(ldns_resolver *);
 void ldns_resolver_set_defnames(ldns_resolver *, bool);
 void ldns_resolver_set_usevc(ldns_resolver *, bool);
index 2978680214a1920398d02ae34b61f1877a63d98b..5c7f140fe2c3a8fd1f417c2452bec40460f542a8 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <config.h>
+#include <stdio.h>
 
 #include <ldns/rdata.h>
 #include <ldns/error.h>
@@ -247,11 +248,16 @@ ldns_resolver_new(void)
        ldns_resolver *r;
 
        r = MALLOC(ldns_resolver);
+       if (!r) {
+               return NULL;
+       }
 
-       /* allow for 3 of these each */
        r->_searchlist = MALLOC(ldns_rdf *);
        r->_nameservers = MALLOC(ldns_rdf *);
-       
+       if (!r->_searchlist || !r->_nameservers) {
+               return NULL;
+       }
+
        /* defaults are filled out */
        ldns_resolver_set_searchlist_count(r, 0);
        ldns_resolver_set_nameserver_count(r, 0);
@@ -270,6 +276,60 @@ ldns_resolver_new(void)
        return r;
 }
 
+
+/**
+ * configure a resolver by means of a resolv.conf file
+ * The file may be NULL in which case there will  be
+ * looked the RESOLV_CONF (defaults to /etc/resolv.conf
+ * \param[in] filename the filename to use
+ * \return ldns_resolver pointer
+ */
+/* keyword recognized:
+ * nameserver
+ * domain
+ */
+ldns_resolver *
+ldns_resolver_new_frm_file(const char *filename)
+{
+       ldns_resolver *r;
+       FILE *fp;
+       const char *keyword[3];
+       char *line;
+       size_t len;
+       
+
+       keyword[0] = "nameserver";
+       keyword[1] = "domain";
+       keyword[2] = "searchlist";
+       line = XMALLOC(char, MAXLINE_LEN);
+       len = MAXLINE_LEN;
+
+       r = ldns_resolver_new();
+       if (!r) {
+               return NULL;
+       }
+       if (!filename) {
+               fp = fopen(RESOLV_CONF, "r");
+
+       } else {
+               fp = fopen(filename, "r");
+       }
+       if (!fp) {
+               return NULL;
+       }
+       /* the file is opened. it's line based - this will be a bit messy
+        */
+       
+       while (getline(&line, &len, fp) != -1) {
+               /* do something */
+               printf("line %s\n", line);
+       }
+
+       fclose(fp);
+       return r;
+}
+
+
 /**
  * Frees the allocated space for this resolver and all it's data
  *