jvdias 9992df
--- bind-9.3.1/bin/dig/dighost.c.next_server_on_referral	2005-08-16 16:27:33.000000000 -0400
jvdias 9992df
+++ bind-9.3.1/bin/dig/dighost.c	2005-08-16 16:27:49.000000000 -0400
jvdias 9992df
@@ -2765,7 +2765,17 @@
jvdias d9e594
 		UNLOCK_LOOKUP;
jvdias d9e594
 		return;
jvdias d9e594
 	}			
jvdias d9e594
-	if (msg->rcode == dns_rcode_servfail && !l->servfail_stops) {
jvdias d9e594
+	if ( (!l->servfail_stops)
jvdias d9e594
+	   &&( (msg->rcode == dns_rcode_servfail)
jvdias d9e594
+	     ||(  (msg->rcode == dns_rcode_noerror) 
jvdias d9e594
+	        &&(msg->counts[DNS_SECTION_ANSWER] == 0)
jvdias 9992df
+	        &&(msg->counts[DNS_SECTION_ADDITIONAL] == 0)
jvdias 9992df
+		&&((msg->flags &  DNS_MESSAGEFLAG_RD) == DNS_MESSAGEFLAG_RD)
jvdias 9992df
+		&&((msg->flags & (DNS_MESSAGEFLAG_RA | DNS_MESSAGEFLAG_AA)) == 0)
jvdias d9e594
+	       )
jvdias d9e594
+	     )
jvdias d9e594
+	   )
jvdias d9e594
+	{
jvdias d9e594
 		dig_query_t *next = ISC_LIST_NEXT(query, link);
jvdias d9e594
 		if (l->current_query == query)
jvdias d9e594
 			l->current_query = NULL;
jvdias 9992df
@@ -2783,9 +2793,11 @@
jvdias d9e594
 		 */
jvdias d9e594
 		if ((ISC_LIST_HEAD(l->q) != query) ||
jvdias d9e594
 		    (ISC_LIST_NEXT(query, link) != NULL)) {
jvdias d9e594
-			printf(";; Got SERVFAIL reply from %s, "
jvdias d9e594
-			       "trying next server\n",
jvdias d9e594
-			       query->servname);
jvdias d9e594
+		        if( l->comments == ISC_TRUE )
jvdias d9e594
+			        printf(";; Got %s reply from %s, "
jvdias d9e594
+				       "trying next server\n",
jvdias d9e594
+				       msg->rcode == dns_rcode_servfail ? "SERVFAIL" : "referral",
jvdias d9e594
+				       query->servname);
jvdias d9e594
 			clear_query(query);
jvdias d9e594
 			check_next_lookup(l);
jvdias d9e594
 			dns_message_destroy(&msg;;