]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
added some higher level function for resolving
authorMiek Gieben <miekg@NLnetLabs.nl>
Thu, 10 Mar 2005 13:37:23 +0000 (13:37 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Thu, 10 Mar 2005 13:37:23 +0000 (13:37 +0000)
Makefile.in
higher.c [new file with mode: 0644]
ldns/dns.h
ldns/higher.h [new file with mode: 0644]
rr.c

index 0e5a231ba22a4a65825cfe9d3ddeaac60c907bb6..84086f9b2eeec8f7f5f3280a6b3824fae781c0b6 100644 (file)
@@ -25,7 +25,8 @@ LINTFLAGS     = +quiet -weak -warnposix -unrecog -Din_addr_t=uint32_t -Du_int=unsign
 
 LIBDNS_SOURCES =       rdata.c util.c rr.c packet.c wire2host.c \
                        host2str.c buffer.c str2host.c resolver.c \
-                       net.c host2wire.c dname.c dnssec.c keys.c
+                       net.c host2wire.c dname.c dnssec.c keys.c \
+                       higher.c
 LIBDNS_HEADERS =       ldns/error.h            \
                        ldns/packet.h           \
                        ldns/prototype.h        \
@@ -41,6 +42,7 @@ LIBDNS_HEADERS        =       ldns/error.h            \
                        ldns/dname.h            \
                        ldns/dnssec.h           \
                        ldns/keys.h             \
+                       ldns/higher.h           \
                        util.h
 PROG_SOURCES   =       mx.c
 PROG_TARGETS   =       $(PROG_SOURCES:.c=)
diff --git a/higher.c b/higher.c
new file mode 100644 (file)
index 0000000..164898a
--- /dev/null
+++ b/higher.c
@@ -0,0 +1,84 @@
+/*
+ * higher.c
+ *
+ * Specify some higher level functions that would
+ * be usefull to would be developers
+ *
+ * a Net::DNS like library for C
+ *
+ * (c) NLnet Labs, 2004
+ *
+ * See the file LICENSE for the license
+ */
+
+#include <config.h>
+#include <ldns/higher.h>
+#include "util.h"
+
+ldns_rr_list *
+ldns_get_rr_list_addr_by_name(ldns_resolver *res, ldns_rdf *name, ldns_rr_class c, 
+               uint16_t flags)
+{
+       ldns_pkt *pkt;
+       ldns_rr_list *aaaa;
+       ldns_rr_list *a;
+       ldns_rr_list *result;
+
+       a = NULL; aaaa = NULL;
+
+       if (!res) {
+               return NULL;
+       }
+       if (ldns_rdf_get_type(name) != LDNS_RDF_TYPE_DNAME) {
+               return NULL;
+       }
+
+       /* add the RD flags, because we want an answer */
+       pkt = ldns_resolver_query(res, name, LDNS_RR_TYPE_AAAA, c, flags | LDNS_RD);
+       if (pkt) {
+               /* extract the data we need */
+               aaaa = ldns_pkt_rr_list_by_type(pkt, 
+                               LDNS_RR_TYPE_AAAA, LDNS_SECTION_ANSWER);
+       }
+
+       pkt = ldns_resolver_query(res, name, LDNS_RR_TYPE_A, c, flags | LDNS_RD);
+       if (pkt) {
+               /* extract the data we need */
+               a = ldns_pkt_rr_list_by_type(pkt, 
+                               LDNS_RR_TYPE_A, LDNS_SECTION_ANSWER);
+       }
+       result = ldns_rr_list_cat(aaaa, a);
+       return result;
+}
+
+ldns_rr_list *
+ldns_get_rr_list_name_by_addr(ldns_resolver *res, ldns_rdf *addr, ldns_rr_class c, 
+               uint16_t flags)
+{
+       ldns_pkt *pkt;
+       ldns_rr_list *names;
+       ldns_rdf *name;
+       size_t i;
+
+       i = 0; names = NULL;
+
+       if (!res || !addr) {
+               return NULL;
+       }
+
+       if (ldns_rdf_get_type(addr) != LDNS_RDF_TYPE_A &&
+                       ldns_rdf_get_type(addr) != LDNS_RDF_TYPE_AAAA) {
+               return NULL;
+       }
+
+       name = ldns_rdf_address_reverse(addr);
+       
+       /* add the RD flags, because we want an answer */
+       pkt = ldns_resolver_query(res, name, LDNS_RR_TYPE_PTR, c, flags | LDNS_RD);
+       if (pkt) {
+               /* extract the data we need */
+               names = ldns_pkt_rr_list_by_type(pkt, 
+                               LDNS_RR_TYPE_PTR, LDNS_SECTION_ANSWER);
+       }
+       return names;
+}
index ffc7fffc3e395093d250941fcb0d39afb44ad174..9f0b7d202ef45fcd18f0372815568a27c8c9e76f 100644 (file)
@@ -17,6 +17,7 @@
 #include <ldns/dname.h>
 #include <ldns/dnssec.h>
 #include <ldns/error.h>
+#include <ldns/higher.h>
 #include <ldns/host2str.h>
 #include <ldns/host2wire.h>
 #include <ldns/ldns.h>
diff --git a/ldns/higher.h b/ldns/higher.h
new file mode 100644 (file)
index 0000000..03c9803
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * higher.h
+ *
+ * Specify some higher level functions that would
+ * be usefull to would be developers
+ *
+ * a Net::DNS like library for C
+ *
+ * (c) NLnet Labs, 2004
+ *
+ * See the file LICENSE for the license
+ */
+
+#include <ldns/resolver.h>
+#include <ldns/rdata.h>
+#include <ldns/rr.h>
+#include <ldns/host2str.h>
+
+/**
+ * Ask the resolver about name
+ * and return all address records
+ */
+ldns_rr_list *
+ldns_get_rr_list_addr_by_name(ldns_resolver *r, ldns_rdf *name, ldns_rr_class c, uint16_t flags);
+
+/**
+ * ask the resolver about the address
+ * and return the name
+ *
+ */
+ldns_rr_list *
+ldns_get_rr_list_name_by_addr(ldns_resolver *r, ldns_rdf *addr, ldns_rr_class c, uint16_t flags);
diff --git a/rr.c b/rr.c
index 5c983a0af7da7bd56f6430ceedf662225b500a85..9b4fc3e12ba642a71ae329c198a120117823c7a1 100644 (file)
--- a/rr.c
+++ b/rr.c
@@ -434,10 +434,22 @@ ldns_rr_list_cat(ldns_rr_list *left, ldns_rr_list *right)
        uint16_t i;
        ldns_rr_list *cat;
 
-       l_rr_count = ldns_rr_list_rr_count(left);
-       r_rr_count = ldns_rr_list_rr_count(right);
+       l_rr_count = 0;
+       r_rr_count = 0;
+
+       if (left) {
+               l_rr_count = ldns_rr_list_rr_count(left);
+       }
+       if (right) {
+               r_rr_count = ldns_rr_list_rr_count(right);
+       }
+
+       /* constant DEFINE? */
+       if (l_rr_count + r_rr_count > 65535 ) {
+               /* overflow error */
+               return NULL;
+       }
 
-       /* check it not exceeding uint16_t size XXX XXX MIEK TODO */
        cat = ldns_rr_list_new();
 
        if (!cat) {