]> granicus.if.org Git - libevent/commitdiff
Add DNS_ERR_NODATA error code to handle empty replies.
authorLeonid Evdokimov <darkk@yandex-team.ru>
Wed, 10 Aug 2011 11:58:47 +0000 (15:58 +0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 12 Sep 2011 19:38:05 +0000 (15:38 -0400)
evdns.c
include/event2/dns.h

diff --git a/evdns.c b/evdns.c
index 4ff9f8dccee8f2698dcdf890c42a462220a35f02..6b50169871c7f8fcfdd99e557248e9a8ca5e7e84 100644 (file)
--- a/evdns.c
+++ b/evdns.c
@@ -843,13 +843,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_NODATA;
+               } else {
+                       error = DNS_ERR_UNKNOWN;
                }
 
                switch (error) {
@@ -3871,6 +3875,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_NODATA: return "no records in the reply";
        default: return "[Unknown error code]";
     }
 }
index a51da89974c705628a29e42bb224d1e8d8b5764e..61c6e4f11c39b43222c5e7c2d90829976fb53a97 100644 (file)
@@ -166,6 +166,10 @@ 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.
+ * This can happen when you ask for an address that exists, but a record
+ * type that doesn't. */
+#define DNS_ERR_NODATA 70
 
 #define DNS_IPv4_A 1
 #define DNS_PTR 2