+mDNSlocal const domainname *DNSRelayTestQuestion = (domainname*)
+ "\x1" "1" "\x1" "0" "\x1" "0" "\x3" "127" "\xa" "dnsbugtest"
+ "\x1" "1" "\x1" "0" "\x1" "0" "\x3" "127" "\x7" "in-addr" "\x4" "arpa";
+
+// Returns mDNStrue if response was handled
+mDNSlocal mDNSBool uDNS_ReceiveTestQuestionResponse(mDNS *const m, DNSMessage *const msg, const mDNSu8 *const end,
+ const mDNSAddr *const srcaddr, const mDNSInterfaceID InterfaceID)
+ {
+ const mDNSu8 *ptr = msg->data;
+ DNSQuestion q;
+ DNSServer *s;
+ mDNSu32 result = 0;
+ mDNSBool found = mDNSfalse;
+
+ // 1. Find out if this is an answer to one of our test questions
+ if (msg->h.numQuestions != 1) return(mDNSfalse);
+ ptr = getQuestion(msg, ptr, end, InterfaceID, &q);
+ if (!ptr) return(mDNSfalse);
+ if (q.qtype != kDNSType_PTR || q.qclass != kDNSClass_IN) return(mDNSfalse);
+ if (!SameDomainName(&q.qname, DNSRelayTestQuestion)) return(mDNSfalse);
+
+ // 2. If the DNS relay gave us a positive response, then it's got buggy firmware
+ // else, if the DNS relay gave us an error or no-answer response, it passed our test
+ if ((msg->h.flags.b[1] & kDNSFlag1_RC) == kDNSFlag1_RC_NoErr && msg->h.numAnswers > 0)
+ result = DNSServer_Failed;
+ else
+ result = DNSServer_Passed;
+
+ // 3. Find occurrences of this server in our list, and mark them appropriately
+ for (s = m->uDNS_info.Servers; s; s = s->next)
+ if (mDNSSameAddress(srcaddr, &s->addr) && s->teststate != result)
+ { s->teststate = result; found = mDNStrue; }
+
+ // 4. Assuming we found the server in question in our list (don't want to risk being victim of a deliberate DOS attack here)
+ // log a message to let the user know why Wide-Area Service Discovery isn't working
+ if (found && result == DNSServer_Failed)
+ LogMsg("NOTE: Wide-Area Service Discovery disabled to avoid crashing defective DNS relay %#a.", srcaddr);
+
+ return(mDNStrue); // Return mDNStrue to tell uDNS_ReceiveMsg it doens't need to process this packet further
+ }
+