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

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



I'm sorry, 0002-Add-DNS_ERR_â.patch had no error description and had
too much typos per line.
Here is correct patch.

--
WBRBW, Leonid Evdokimov
xmpp:leon@xxxxxxxxxxxx && http://darkk.net.ru
tel:+79816800702 && tel:+79050965222
From eade47790a2ca423390565eee87bf69bd46ee1b1 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_NOANSWER error code to handle emptry replies.

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

diff --git a/evdns.c b/evdns.c
index 9beac91..b6c2916 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_NOANSWER;
+		} else {
+		    error = DNS_ERR_UNKNOWN;
 		}
 
 		switch (error) {
@@ -3841,6 +3845,7 @@ evdns_err_to_string(int err)
 	case DNS_ERR_TIMEOUT: return "request timed out";
 	case DNS_ERR_SHUTDOWN: return "dns subsystem shut down";
 	case DNS_ERR_CANCEL: return "dns request canceled";
+	case DNS_ERR_NOANSWER: return "no answer in the reply";
 	default: return "[Unknown error code]";
     }
 }
diff --git a/include/event2/dns.h b/include/event2/dns.h
index f9f9d0b..a8165db 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_NOANSWER 70
 
 #define DNS_IPv4_A 1
 #define DNS_PTR 2
-- 
1.7.4.1