--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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);
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) {