[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] [PATCH]: libevent/dns DNS_ERR_NOANSWERS



Hello,

I think, that absence of DNS answers is probably not an "unknown
error". There is at least one case when it is quite a valid result:
"A" query for "AAAA"-only host. I would like to distinguish this case
from unknown bits in error field of DNS reply, so here is the patch.
Feel free to merge it in the mainline if you find it useful.

Also, I've spotted at least one error in docstring in event2/dns.h -
another patch for that.

--
WBRBW, Leonid Evdokimov
xmpp:leon@xxxxxxxxxxxx && http://darkk.net.ru
tel:+79816800702 && tel:+79050965222
From 16c16d801ced8835a7551f014bf58af4ebf073d5 Mon Sep 17 00:00:00 2001
From: Leonid Evdokimov <darkk@xxxxxxxxxxxxxx>
Date: Wed, 10 Aug 2011 15:58:19 +0400
Subject: [PATCH 1/2] Fix docstring in dns.h

---
 include/event2/dns.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/event2/dns.h b/include/event2/dns.h
index 113a154..f9f9d0b 100644
--- a/include/event2/dns.h
+++ b/include/event2/dns.h
@@ -206,7 +206,7 @@ struct event_base;
 
   @param event_base the event base to associate the dns client with
   @param initialize_nameservers 1 if resolve.conf processing should occur
-  @return 0 if successful, or -1 if an error occurred
+  @return evdns_base object if successful, or NULL if an error occurred.
   @see evdns_base_free()
  */
 struct evdns_base * evdns_base_new(struct event_base *event_base, int initialize_nameservers);
-- 
1.7.4.1

From fd074f3551d0e0fb6e9311499a87eb00b006476c Mon Sep 17 00:00:00 2001
From: Leonid Evdokimov <darkk@xxxxxxxxxxxxxx>
Date: Wed, 10 Aug 2011 15:58:47 +0400
Subject: [PATCH 2/2] Add DNS_ERR_NOANWERS error code to handle emptry replies.

---
 evdns.c              |    6 +++++-
 include/event2/dns.h |    2 ++
 2 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/evdns.c b/evdns.c
index 9beac91..72af3a8 100644
--- a/evdns.c
+++ b/evdns.c
@@ -842,13 +842,17 @@ reply_handle(struct request *const req, u16 flags, u32 ttl, struct reply *reply)
 		/* there was an error */
 		if (flags & 0x0200) {
 			error = DNS_ERR_TRUNCATED;
-		} else {
+		} else if (flags & 0x000f) {
 			u16 error_code = (flags & 0x000f) - 1;
 			if (error_code > 4) {
 				error = DNS_ERR_UNKNOWN;
 			} else {
 				error = error_codes[error_code];
 			}
+		} else if (reply && !reply->have_answer) {
+		    error = DNS_ERR_NOANWERS;
+		} else {
+		    error = DNS_ERR_UNKNOWN;
 		}
 
 		switch (error) {
diff --git a/include/event2/dns.h b/include/event2/dns.h
index f9f9d0b..743f47d 100644
--- a/include/event2/dns.h
+++ b/include/event2/dns.h
@@ -166,6 +166,8 @@ extern "C" {
 #define DNS_ERR_SHUTDOWN 68
 /** The request was canceled via a call to evdns_cancel_request */
 #define DNS_ERR_CANCEL 69
+/** There were no answers and no error condition in the DNS packet. */
+#define DNS_ERR_NOANWERS 70
 
 #define DNS_IPv4_A 1
 #define DNS_PTR 2
-- 
1.7.4.1