From 97f1eb4d6d0ba10ac8902a3abb84200430563a2b Mon Sep 17 00:00:00 2001
From: Dan Egnor <egnor@ofb.net>
Date: Thu, 7 Aug 2003 15:29:49 +0000
Subject: [PATCH] Add reverse lookup capability, patch from /ceder

---
 adns.c     | 32 ++++++++++++++++++++++++++++++--
 oop-adns.h |  7 ++++++-
 test-oop.c |  2 +-
 3 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/adns.c b/adns.c
index f3ae4b3..2159af3 100644
--- a/adns.c
+++ b/adns.c
@@ -70,13 +70,41 @@ void oop_adns_delete(oop_adapter_adns *a) {
 }
 
 oop_adns_query *oop_adns_submit(
-	oop_adapter_adns *a,
+	oop_adapter_adns *a,int *errcode,
 	const char *owner,adns_rrtype type,adns_queryflags flags,
 	oop_adns_call *call,void *data)
 {
 	oop_adns_query *q = oop_malloc(sizeof(*q));
+	int err;
 	if (NULL == q) return NULL;
-	if (adns_submit(a->state,owner,type,flags,q,&q->query)) {
+
+	err = adns_submit(a->state,owner,type,flags,q,&q->query);
+	if (errcode) *errcode = err;
+	if (err) {
+		oop_free(q);
+		return NULL;
+	}
+
+	q->a = a;
+	q->call = call;
+	q->data = data;
+	++q->a->count;
+	set_select(a);
+	return q;
+}
+
+oop_adns_query *oop_adns_submit_reverse(
+	oop_adapter_adns *a,int *errcode,
+	const struct sockaddr *addr,adns_rrtype type,adns_queryflags flags,
+	oop_adns_call *call,void *data)
+{
+	oop_adns_query *q = oop_malloc(sizeof(*q));
+	int err;
+	if (NULL == q) return NULL;
+
+	err = adns_submit_reverse(a->state,addr,type,flags,q,&q->query)));
+	if (errcode) *errcode = err;
+	if (err) {
 		oop_free(q);
 		return NULL;
 	}
diff --git a/oop-adns.h b/oop-adns.h
index 030875b..5016a6d 100644
--- a/oop-adns.h
+++ b/oop-adns.h
@@ -26,10 +26,15 @@ void oop_adns_delete(oop_adapter_adns *);
    The returned pointer is valid until the callback occurs or the
    query is cancelled (see below). */
 oop_adns_query *oop_adns_submit(
-	oop_adapter_adns *,
+	oop_adapter_adns *,int *errcode,
 	const char *owner,adns_rrtype type,adns_queryflags flags,
 	oop_adns_call *,void *);
 
+oop_adns_query *oop_adns_submit_reverse(
+	oop_adapter_adns *,int *errcode,
+	const struct sockaddr *addr,adns_rrtype type,adns_queryflags flags,
+	oop_adns_call *,void *);
+
 /* Cancel a running query. */
 void oop_adns_cancel(oop_adns_query *);
 
diff --git a/test-oop.c b/test-oop.c
index c909a91..c1f5281 100644
--- a/test-oop.c
+++ b/test-oop.c
@@ -251,7 +251,7 @@ static void *on_lookup(oop_adapter_adns *adns,adns_answer *reply,void *data) {
 
 static void get_name(int i,const char *name) {
 	q[i] = oop_adns_submit(
-	       adns,name,adns_r_a,adns_qf_owner,
+	       adns,NULL,name,adns_r_a,adns_qf_owner,
 	       on_lookup,&q[i]);
 }
 
-- 
GitLab