Index: mDNSResponder/Makefile
===================================================================
--- mDNSResponder/Makefile	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/Makefile	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -17,5 +17,5 @@
 include $(MAKEFILEPATH)/pb_makefiles/platform.make
 
-MVERS = "mDNSResponder-765.30.11"
+MVERS = "mDNSResponder-765.50.9"
 
 DDNSWRITECONFIG = "$(DSTROOT)/Library/Application Support/Bonjour/ddnswriteconfig"
Index: mDNSResponder/mDNSCore/DNSCommon.c
===================================================================
--- mDNSResponder/mDNSCore/DNSCommon.c	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/mDNSCore/DNSCommon.c	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -514,5 +514,5 @@
         length += mDNS_snprintf(buffer+length, RemSpc, "\t%s  %s  %d  %d  %s  %s  %d  %##s ",
                                 DNSTypeName(swap16(rrsig->typeCovered)), DNSSECAlgName(rrsig->alg), rrsig->labels, swap32(rrsig->origTTL),
-                                expTimeBuf, inceptTimeBuf, swap16(rrsig->keyTag), ((domainname *)(&rrsig->signerName))->c);
+                                expTimeBuf, inceptTimeBuf, swap16(rrsig->keyTag), rrsig->signerName);
 
         len = DomainNameLength((domainname *)&rrsig->signerName);
Index: mDNSResponder/mDNSCore/dnsproxy.c
===================================================================
--- mDNSResponder/mDNSCore/dnsproxy.c	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/mDNSCore/dnsproxy.c	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -495,9 +495,8 @@
 }
 
-mDNSlocal void SendError(mDNS *const m, void *socket, void *const pkt, const mDNSu8 *const end, const mDNSAddr *dstaddr,
+mDNSlocal void SendError(mDNS *const m, void *socket, DNSMessage *const msg, const mDNSu8 *const end, const mDNSAddr *dstaddr,
     const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID, mDNSBool tcp, void *context, mDNSu8 rcode)
 {
-    int pktlen = (int)(end - (mDNSu8 *)pkt);
-    DNSMessage  *msg  = (DNSMessage *)pkt;
+    int pktlen = (int)(end - (mDNSu8 *)msg);
 
     // RFC 1035 requires that we copy the question back and RFC 2136 is okay with sending nothing
@@ -572,8 +571,7 @@
 }
 
-mDNSlocal void ProxyCallbackCommon(mDNS *const m, void *socket, void *const pkt, const mDNSu8 *const end, const mDNSAddr *const srcaddr,
+mDNSlocal void ProxyCallbackCommon(mDNS *const m, void *socket, DNSMessage *const msg, const mDNSu8 *const end, const mDNSAddr *const srcaddr,
     const mDNSIPPort srcport, const mDNSAddr *dstaddr, const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID, mDNSBool tcp, void *context)
 {
-    DNSMessage  *msg  = (DNSMessage *)pkt;
     mDNSu8 QR_OP;
     const mDNSu8 *ptr;
@@ -595,7 +593,7 @@
     }
     
-    if ((unsigned)(end - (mDNSu8 *)pkt) < sizeof(DNSMessageHeader))
-    {
-        debugf("ProxyCallbackCommon: DNS Message from %#a:%d to %#a:%d length %d too short", srcaddr, mDNSVal16(srcport), dstaddr, mDNSVal16(dstport), end - (mDNSu8 *)pkt);
+    if ((unsigned)(end - (mDNSu8 *)msg) < sizeof(DNSMessageHeader))
+    {
+        debugf("ProxyCallbackCommon: DNS Message from %#a:%d to %#a:%d length %d too short", srcaddr, mDNSVal16(srcport), dstaddr, mDNSVal16(dstport), (int)(end - (mDNSu8 *)msg));
         return;
     }
@@ -605,5 +603,5 @@
     {
         LogInfo("ProxyCallbackCommon: Not a query(%d) for pkt from %#a:%d", QR_OP, srcaddr, mDNSVal16(srcport));
-        SendError(m, socket, pkt, end, srcaddr, srcport, InterfaceID, tcp, context, kDNSFlag1_RC_NotImpl);
+        SendError(m, socket, msg, end, srcaddr, srcport, InterfaceID, tcp, context, kDNSFlag1_RC_NotImpl);
         return;
     }
@@ -620,5 +618,5 @@
         LogInfo("ProxyCallbackCommon: Malformed pkt from %#a:%d, Q:%d, An:%d, Au:%d", srcaddr, mDNSVal16(srcport),
             msg->h.numQuestions, msg->h.numAnswers, msg->h.numAuthorities);
-        SendError(m, socket, pkt, end, srcaddr, srcport, InterfaceID, tcp, context, kDNSFlag1_RC_FormErr);
+        SendError(m, socket, msg, end, srcaddr, srcport, InterfaceID, tcp, context, kDNSFlag1_RC_FormErr);
         return;
     }
@@ -628,5 +626,5 @@
     {
         LogInfo("ProxyCallbackCommon: Question cannot be parsed for pkt from %#a:%d", srcaddr, mDNSVal16(srcport));
-        SendError(m, socket, pkt, end, srcaddr, srcport, InterfaceID, tcp, context, kDNSFlag1_RC_FormErr);
+        SendError(m, socket, msg, end, srcaddr, srcport, InterfaceID, tcp, context, kDNSFlag1_RC_FormErr);
         return;
     }
@@ -733,19 +731,19 @@
 }
 
-mDNSexport void ProxyUDPCallback(mDNS *const m, void *socket, void *const pkt, const mDNSu8 *const end, const mDNSAddr *const srcaddr,
+mDNSexport void ProxyUDPCallback(mDNS *const m, void *socket, DNSMessage *const msg, const mDNSu8 *const end, const mDNSAddr *const srcaddr,
     const mDNSIPPort srcport, const mDNSAddr *dstaddr, const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID, void *context)
 {
-    LogInfo("ProxyUDPCallback: DNS Message from %#a:%d to %#a:%d length %d", srcaddr, mDNSVal16(srcport), dstaddr, mDNSVal16(dstport), end - (mDNSu8 *)pkt);
-    ProxyCallbackCommon(m, socket, pkt, end, srcaddr, srcport, dstaddr, dstport, InterfaceID, mDNSfalse, context);
-}
-
-mDNSexport void ProxyTCPCallback(mDNS *const m, void *socket, void *const pkt, const mDNSu8 *const end, const mDNSAddr *const srcaddr,
+    LogInfo("ProxyUDPCallback: DNS Message from %#a:%d to %#a:%d length %d", srcaddr, mDNSVal16(srcport), dstaddr, mDNSVal16(dstport), (int)(end - (mDNSu8 *)msg));
+    ProxyCallbackCommon(m, socket, msg, end, srcaddr, srcport, dstaddr, dstport, InterfaceID, mDNSfalse, context);
+}
+
+mDNSexport void ProxyTCPCallback(mDNS *const m, void *socket, DNSMessage *const msg, const mDNSu8 *const end, const mDNSAddr *const srcaddr,
     const mDNSIPPort srcport, const mDNSAddr *dstaddr, const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID, void *context)
 {
-    LogInfo("ProxyTCPCallback: DNS Message from %#a:%d to %#a:%d length %d", srcaddr, mDNSVal16(srcport), dstaddr, mDNSVal16(dstport), end - (mDNSu8 *)pkt);
+    LogInfo("ProxyTCPCallback: DNS Message from %#a:%d to %#a:%d length %d", srcaddr, mDNSVal16(srcport), dstaddr, mDNSVal16(dstport), (int)(end - (mDNSu8 *)msg));
     
     // If the connection was closed from the other side or incoming packet does not match stored input interface list, locate the client
     // state and free it.
-    if (((end - (mDNSu8 *)pkt) == 0) || (!CheckDNSProxyIpIntf(m, InterfaceID)))
+    if (((end - (mDNSu8 *)msg) == 0) || (!CheckDNSProxyIpIntf(m, InterfaceID)))
     {
         DNSProxyClient **ppc = &DNSProxyClients;
@@ -770,5 +768,5 @@
         return;
     }
-    ProxyCallbackCommon(m, socket, pkt, end, srcaddr, srcport, dstaddr, dstport, InterfaceID, mDNStrue, context);
+    ProxyCallbackCommon(m, socket, msg, end, srcaddr, srcport, dstaddr, dstport, InterfaceID, mDNStrue, context);
 }
 
@@ -800,9 +798,9 @@
 #else // UNICAST_DISABLED
 
-mDNSexport void ProxyUDPCallback(mDNS *const m, void *socket, void *const pkt, const mDNSu8 *const end, const mDNSAddr *const srcaddr, const mDNSIPPort srcport, const mDNSAddr *dstaddr, const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID, void *context)
+mDNSexport void ProxyUDPCallback(mDNS *const m, void *socket, DNSMessage *const msg, const mDNSu8 *const end, const mDNSAddr *const srcaddr, const mDNSIPPort srcport, const mDNSAddr *dstaddr, const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID, void *context)
 {
     (void) m;
     (void) socket;
-    (void) pkt;
+    (void) msg;
     (void) end;
     (void) srcaddr;
@@ -814,9 +812,9 @@
 }
 
-mDNSexport void ProxyTCPCallback(mDNS *const m, void *socket, void *const pkt, const mDNSu8 *const end, const mDNSAddr *const srcaddr, const mDNSIPPort srcport, const mDNSAddr *dstaddr, const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID, void *context)
+mDNSexport void ProxyTCPCallback(mDNS *const m, void *socket, DNSMessage *const msg, const mDNSu8 *const end, const mDNSAddr *const srcaddr, const mDNSIPPort srcport, const mDNSAddr *dstaddr, const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID, void *context)
 {
     (void) m;
     (void) socket;
-    (void) pkt;
+    (void) msg;
     (void) end;
     (void) srcaddr;
Index: mDNSResponder/mDNSCore/dnsproxy.h
===================================================================
--- mDNSResponder/mDNSCore/dnsproxy.h	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/mDNSCore/dnsproxy.h	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -22,7 +22,7 @@
 #include "DNSCommon.h"
 
-extern void ProxyUDPCallback(mDNS *const m, void *socket, void *const pkt, const mDNSu8 *const end, const mDNSAddr *const srcaddr,
+extern void ProxyUDPCallback(mDNS *const m, void *socket, DNSMessage *const msg, const mDNSu8 *const end, const mDNSAddr *const srcaddr,
                              const mDNSIPPort srcport, const mDNSAddr *dstaddr, const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID, void *context);
-extern void ProxyTCPCallback(mDNS *const m, void *socket, void *const pkt, const mDNSu8 *const end, const mDNSAddr *const srcaddr,
+extern void ProxyTCPCallback(mDNS *const m, void *socket, DNSMessage *const msg, const mDNSu8 *const end, const mDNSAddr *const srcaddr,
                              const mDNSIPPort srcport, const mDNSAddr *dstaddr, const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID, void *context);                          
 extern void DNSProxyInit(mDNS *const m, mDNSu32 IpIfArr[MaxIp], mDNSu32 OpIf);
Index: mDNSResponder/mDNSCore/mDNS.c
===================================================================
--- mDNSResponder/mDNSCore/mDNS.c	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/mDNSCore/mDNS.c	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -6629,4 +6629,7 @@
                     // mDNSCoreReadyForSleep() will conclude correctly that all the updates have already completed
 
+                    // Setting this flag activates the SleepLimit which delays sleep by 5 seconds and
+                    // will allow the system to deregister any BTMM records.
+                    m->NextScheduledSPRetry  = m->timenow + (5 * mDNSPlatformOneSecond);
                     registeredIntfIDS[registeredCount] = intf->InterfaceID;
                     registeredCount++;
@@ -10525,10 +10528,10 @@
 }
 
-mDNSexport void mDNSCoreReceive(mDNS *const m, void *const pkt, const mDNSu8 *const end,
+mDNSexport void mDNSCoreReceive(mDNS *const m, DNSMessage *const msg, const mDNSu8 *const end,
                                 const mDNSAddr *const srcaddr, const mDNSIPPort srcport, const mDNSAddr *dstaddr, const mDNSIPPort dstport,
                                 const mDNSInterfaceID InterfaceID)
 {
     mDNSInterfaceID ifid = InterfaceID;
-    DNSMessage  *msg  = (DNSMessage *)pkt;
+    const mDNSu8 *const pkt = (mDNSu8 *)msg;
     const mDNSu8 StdQ = kDNSFlag0_QR_Query    | kDNSFlag0_OP_StdQuery;
     const mDNSu8 StdR = kDNSFlag0_QR_Response | kDNSFlag0_OP_StdQuery;
@@ -10547,5 +10550,5 @@
         {
             mDNS_Lock(m);
-            LNT_ConfigureRouterInfo(m, InterfaceID, pkt, (mDNSu16)(end - (mDNSu8 *)pkt));
+            LNT_ConfigureRouterInfo(m, InterfaceID, (mDNSu8 *)msg, (mDNSu16)(end - pkt));
             mDNS_Unlock(m);
             return;
@@ -10555,5 +10558,5 @@
         {
             mDNS_Lock(m);
-            uDNS_ReceiveNATPacket(m, InterfaceID, pkt, (mDNSu16)(end - (mDNSu8 *)pkt));
+            uDNS_ReceiveNATPacket(m, InterfaceID, (mDNSu8 *)msg, (mDNSu16)(end - pkt));
             mDNS_Unlock(m);
             return;
@@ -10565,7 +10568,7 @@
 
 #endif
-    if ((unsigned)(end - (mDNSu8 *)pkt) < sizeof(DNSMessageHeader))
-    {
-        LogMsg("DNS Message from %#a:%d to %#a:%d length %d too short", srcaddr, mDNSVal16(srcport), dstaddr, mDNSVal16(dstport), end - (mDNSu8 *)pkt);
+    if ((unsigned)(end - pkt) < sizeof(DNSMessageHeader))
+    {
+        LogMsg("DNS Message from %#a:%d to %#a:%d length %d too short", srcaddr, mDNSVal16(srcport), dstaddr, mDNSVal16(dstport), (int)(end - pkt));
         return;
     }
@@ -10625,10 +10628,10 @@
                 int i = 0;
                 LogInfo("Unknown DNS packet type %02X%02X from %#-15a:%-5d to %#-15a:%-5d length %d on %p (ignored)",
-                        msg->h.flags.b[0], msg->h.flags.b[1], srcaddr, mDNSVal16(srcport), dstaddr, mDNSVal16(dstport), end - (mDNSu8 *)pkt, InterfaceID);
-                while (i<end - (mDNSu8 *)pkt)
+                        msg->h.flags.b[0], msg->h.flags.b[1], srcaddr, mDNSVal16(srcport), dstaddr, mDNSVal16(dstport), (int)(end - pkt), InterfaceID);
+                while (i < (int)(end - pkt))
                 {
                     char buffer[128];
                     char *p = buffer + mDNS_snprintf(buffer, sizeof(buffer), "%04X", i);
-                    do if (i<end - (mDNSu8 *)pkt) p += mDNS_snprintf(p, sizeof(buffer), " %02X", ((mDNSu8 *)pkt)[i]);while (++i & 15);
+                    do if (i < (int)(end - pkt)) p += mDNS_snprintf(p, sizeof(buffer), " %02X", pkt[i]);while (++i & 15);
                     LogInfo("%s", buffer);
                 }
@@ -13827,6 +13830,7 @@
                                         (rr->AnnounceCount == InitialAnnounceCount)     ? msg2 :
                                         mDNSSameEthAddress(&arp->sha, &intf->MAC)       ? msg3 : msg4;
-                LogSPS("%-7s %s %.6a %.4a for %.4a -- H-MAC %.6a I-MAC %.6a %s",
-                       intf->ifname, msg, &arp->sha, &arp->spa, &arp->tpa, &rr->WakeUp.HMAC, &rr->WakeUp.IMAC, ARDisplayString(m, rr));
+                LogMsg("Arp %-7s %s %.6a %.4a for %.4a -- H-MAC %.6a I-MAC %.6a %s",
+                       intf->ifname, msg, arp->sha.b, arp->spa.b, arp->tpa.b,
+                       &rr->WakeUp.HMAC, &rr->WakeUp.IMAC, ARDisplayString(m, rr));
                 if (msg == msg1)
                 {
@@ -13842,5 +13846,5 @@
                 else if (msg == msg4)
                 {
-                    SendARP(m, 2, rr, &arp->tpa, &arp->sha, &arp->spa, &arp->sha);
+                    SendARP(m, 2, rr, (mDNSv4Addr *)arp->tpa.b, &arp->sha, (mDNSv4Addr *)arp->spa.b, &arp->sha);
                 }
             }
@@ -13856,5 +13860,5 @@
     //   If the sender hardware address is *not* the original owner, then this is a conflict, and we need to wake the sleeping machine to handle it.
     if (mDNSSameEthAddress(&arp->sha, &intf->MAC))
-        debugf("ARP from self for %.4a", &arp->tpa);
+        debugf("ARP from self for %.4a", arp->tpa.b);
     else
     {
@@ -13866,6 +13870,6 @@
                     if (mDNSSameEthAddress(&zeroEthAddr, &rr->WakeUp.HMAC))
                     {
-                        LogSPS("%-7s ARP from %.6a %.4a for %.4a -- Invalid H-MAC %.6a I-MAC %.6a %s", intf->ifname,
-                                &arp->sha, &arp->spa, &arp->tpa, &rr->WakeUp.HMAC, &rr->WakeUp.IMAC, ARDisplayString(m, rr));
+                        LogMsg("%-7s ARP from %.6a %.4a for %.4a -- Invalid H-MAC %.6a I-MAC %.6a %s", intf->ifname,
+                                arp->sha.b, arp->spa.b, arp->tpa.b, &rr->WakeUp.HMAC, &rr->WakeUp.IMAC, ARDisplayString(m, rr));
                     }
                     else
@@ -13874,12 +13878,12 @@
                         if (mDNSSameEthAddress(&arp->sha, &rr->WakeUp.IMAC))
                         {
-                            LogSPS("%-7s ARP %s from owner %.6a %.4a for %-15.4a -- re-starting probing for %s", intf->ifname,
+                            LogMsg("%-7s ARP %s from owner %.6a %.4a for %-15.4a -- re-starting probing for %s", intf->ifname,
                                     mDNSSameIPv4Address(arp->spa, arp->tpa) ? "Announcement " : mDNSSameOpaque16(arp->op, ARP_op_request) ? "Request      " : "Response     ",
-                                    &arp->sha, &arp->spa, &arp->tpa, ARDisplayString(m, rr));
+                                    arp->sha.b, arp->spa.b, arp->tpa.b, ARDisplayString(m, rr));
                         }
                         else
                         {
                             LogMsg("%-7s Conflicting ARP from %.6a %.4a for %.4a -- waking H-MAC %.6a I-MAC %.6a %s", intf->ifname,
-                                    &arp->sha, &arp->spa, &arp->tpa, &rr->WakeUp.HMAC, &rr->WakeUp.IMAC, ARDisplayString(m, rr));
+                                    arp->sha.b, arp->spa.b, arp->tpa.b, &rr->WakeUp.HMAC, &rr->WakeUp.IMAC, ARDisplayString(m, rr));
                             ScheduleWakeup(m, rr->resrec.InterfaceID, &rr->WakeUp.HMAC);
                         }
@@ -14577,5 +14581,6 @@
                      cr->resrec.rrtype     == kDNSType_A ||
                      cr->resrec.rrtype     == kDNSType_AAAA ||
-                     cr->resrec.rrtype     == kDNSType_SRV;
+                     cr->resrec.rrtype     == kDNSType_SRV ||
+                     cr->resrec.rrtype     == kDNSType_CNAME;
 
     (void) lameduck;
Index: mDNSResponder/mDNSCore/mDNSEmbeddedAPI.h
===================================================================
--- mDNSResponder/mDNSCore/mDNSEmbeddedAPI.h	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/mDNSCore/mDNSEmbeddedAPI.h	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -483,5 +483,5 @@
 #define mDNS_numUpdates numAuthorities
 
-typedef packedstruct
+typedef struct
 {
     mDNSOpaque16 id;
@@ -500,5 +500,5 @@
 #endif
 #define NormalMaxDNSMessageData 1440
-typedef packedstruct
+typedef struct
 {
     DNSMessageHeader h;                     // Note: Size 12 bytes
@@ -618,5 +618,5 @@
 } UDPHeader;                // 8 bytes; IP protocol type 0x11
 
-typedef packedstruct
+typedef struct
 {
     mDNSu8 type;            // 0x87 == Neighbor Solicitation, 0x88 == Neighbor Advertisement
@@ -817,5 +817,5 @@
 //size of rdataRRSIG excluding signerName and signature (which are variable fields)
 #define RRSIG_FIXED_SIZE      18
-typedef packedstruct
+typedef struct
 {
     mDNSu16 typeCovered;
@@ -826,5 +826,5 @@
     mDNSu32 sigInceptTime;
     mDNSu16 keyTag;
-    mDNSu8 *signerName;
+    mDNSu8  signerName[1]; // signerName is a dynamically-sized array
     // mDNSu8 *signature
 } rdataRRSig;
@@ -939,5 +939,5 @@
 
 // Note: rdataOPT format may be repeated an arbitrary number of times in a single resource record
-typedef packedstruct
+typedef struct
 {
     mDNSu16 opt;
@@ -1183,5 +1183,5 @@
 } PCPResult_t;
 
-typedef packedstruct
+typedef struct
 {
     mDNSu8       version;
@@ -1198,5 +1198,5 @@
 } PCPMapRequest;
 
-typedef packedstruct
+typedef struct
 {
     mDNSu8     version;
@@ -3297,5 +3297,5 @@
 extern void     mDNS_DeregisterInterface(mDNS *const m, NetworkInterfaceInfo *set, mDNSBool flapping);
 extern void     mDNSCoreInitComplete(mDNS *const m, mStatus result);
-extern void     mDNSCoreReceive(mDNS *const m, void *const msg, const mDNSu8 *const end,
+extern void     mDNSCoreReceive(mDNS *const m, DNSMessage *const msg, const mDNSu8 *const end,
                                 const mDNSAddr *const srcaddr, const mDNSIPPort srcport,
                                 const mDNSAddr *dstaddr, const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID);
@@ -3367,5 +3367,5 @@
 #endif
 
-typedef void ProxyCallback (mDNS *const m, void *socket, void *const msg, const mDNSu8 *const end, const mDNSAddr *const srcaddr,
+typedef void ProxyCallback (mDNS *const m, void *socket, DNSMessage *const msg, const mDNSu8 *const end, const mDNSAddr *const srcaddr,
     const mDNSIPPort srcport, const mDNSAddr *dstaddr, const mDNSIPPort dstport, const mDNSInterfaceID InterfaceID, void *context);
 extern void mDNSPlatformInitDNSProxySkts(mDNS *const m, ProxyCallback *UDPCallback, ProxyCallback *TCPCallback);
@@ -3587,4 +3587,9 @@
     char assertL[(sizeof(IKEHeader     )   ==   28                         ) ? 1 : -1];
     char assertM[(sizeof(TCPHeader     )   ==   20                         ) ? 1 : -1];
+	char assertN[(sizeof(rdataOPT)		   ==   24                         ) ? 1 : -1];
+	char assertO[(sizeof(rdataRRSig)	   ==   20                         ) ? 1 : -1];
+	char assertP[(sizeof(PCPMapRequest)    ==   60                         ) ? 1 : -1];
+	char assertQ[(sizeof(PCPMapReply)      ==   60                         ) ? 1 : -1];
+
 
     // Check our structures are reasonable sizes. Including overly-large buffers, or embedding
Index: mDNSResponder/mDNSCore/uDNS.c
===================================================================
--- mDNSResponder/mDNSCore/uDNS.c	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/mDNSCore/uDNS.c	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -4110,4 +4110,5 @@
     else
     {
+        q->dnsPushState = DNSPUSH_NOSERVER;
         StartLLQPolling(m,q);
         if (err == mStatus_NoSuchNameErr)
@@ -4116,5 +4117,4 @@
             q->servAddr.type  = mDNSAddrType_IPv4;
             q->servAddr.ip.v4 = onesIPv4Addr;
-            q->dnsPushState   = DNSPUSH_NOSERVER;
         }
     }
Index: mDNSResponder/mDNSMacOSX/daemon.c
===================================================================
--- mDNSResponder/mDNSMacOSX/daemon.c	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/mDNSMacOSX/daemon.c	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -33,4 +33,5 @@
 #include <err.h>
 #include <sysexits.h>
+#include <dlfcn.h>
 
 #include "uDNS.h"
@@ -1441,4 +1442,16 @@
 #endif
 
+#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
+mDNSlocal mDNSBool initialize_networkserviceproxy(void)
+{
+    void *NSPImage = dlopen("/System/Library/PrivateFrameworks/NetworkServiceProxy.framework/NetworkServiceProxy", RTLD_LAZY | RTLD_LOCAL);
+    if (NSPImage == NULL) {
+        os_log_error(OS_LOG_DEFAULT, "dlopen NetworkServiceProxy.framework failed");
+        return mDNSfalse;
+    }
+    return mDNStrue;
+}
+#endif
+
 mDNSexport int main(int argc, char **argv)
 {
@@ -1612,4 +1625,10 @@
     UpdateDebugState();
 
+#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
+    if (initialize_networkserviceproxy() == mDNSfalse) {
+        LogMsg("Failed to initialize NetworkServiceProxy");
+    }
+#endif
+
 #ifdef MDNSRESPONDER_USES_LIB_DISPATCH_AS_PRIMARY_EVENT_LOOP_MECHANISM
     LogInfo("Daemon Start: Using LibDispatch");
Index: mDNSResponder/mDNSMacOSX/mDNSMacOSX.c
===================================================================
--- mDNSResponder/mDNSMacOSX/mDNSMacOSX.c	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/mDNSMacOSX/mDNSMacOSX.c	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -1926,49 +1926,38 @@
         s = (src ? src->ss : m->p->permanentsockets).sktv4;
 
-        if (info)   // Specify outgoing interface
-        {
-            if (!mDNSAddrIsDNSMulticast(dst))
+        if (!mDNSAddrIsDNSMulticast(dst))
+        {
+        #ifdef IP_BOUND_IF
+            const mDNSu32 ifindex = info ? info->scope_id : IFSCOPE_NONE;
+            setsockopt(s, IPPROTO_IP, IP_BOUND_IF, &ifindex, sizeof(ifindex));
+        #else
+            static int displayed = 0;
+            if (displayed < 1000)
             {
-                #ifdef IP_BOUND_IF
-                if (info->scope_id == 0)
-                    LogInfo("IP_BOUND_IF socket option not set -- info %p (%s) scope_id is zero", info, ifa_name);
-                else
-                    setsockopt(s, IPPROTO_IP, IP_BOUND_IF, &info->scope_id, sizeof(info->scope_id));
-                #else
-                {
-                    static int displayed = 0;
-                    if (displayed < 1000)
-                    {
-                        displayed++;
-                        LogInfo("IP_BOUND_IF socket option not defined -- cannot specify interface for unicast packets");
-                    }
-                }
-                #endif
+                displayed++;
+                LogInfo("IP_BOUND_IF socket option not defined -- cannot specify interface for unicast packets");
             }
-            else
-                #ifdef IP_MULTICAST_IFINDEX
+        #endif
+        }
+        else if (info)
+        {
+        #ifdef IP_MULTICAST_IFINDEX
+            err = setsockopt(s, IPPROTO_IP, IP_MULTICAST_IFINDEX, &info->scope_id, sizeof(info->scope_id));
+            // We get an error when we compile on a machine that supports this option and run the binary on
+            // a different machine that does not support it
+            if (err < 0)
             {
-                err = setsockopt(s, IPPROTO_IP, IP_MULTICAST_IFINDEX, &info->scope_id, sizeof(info->scope_id));
-                // We get an error when we compile on a machine that supports this option and run the binary on
-                // a different machine that does not support it
-                if (err < 0)
-                {
-                    if (errno != ENOPROTOOPT) LogInfo("mDNSPlatformSendUDP: setsockopt: IP_MUTLTICAST_IFINDEX returned %d", errno);
-                    err = setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &info->ifa_v4addr, sizeof(info->ifa_v4addr));
-                    if (err < 0 && !m->NetworkChanged)
-                        LogMsg("setsockopt - IP_MULTICAST_IF error %.4a %d errno %d (%s)", &info->ifa_v4addr, err, errno, strerror(errno));
-                }
-            }
-                #else
-            {
+                if (errno != ENOPROTOOPT) LogInfo("mDNSPlatformSendUDP: setsockopt: IP_MUTLTICAST_IFINDEX returned %d", errno);
                 err = setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &info->ifa_v4addr, sizeof(info->ifa_v4addr));
                 if (err < 0 && !m->NetworkChanged)
                     LogMsg("setsockopt - IP_MULTICAST_IF error %.4a %d errno %d (%s)", &info->ifa_v4addr, err, errno, strerror(errno));
-
             }
-                #endif
-        }
-    }
-
+        #else
+            err = setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &info->ifa_v4addr, sizeof(info->ifa_v4addr));
+            if (err < 0 && !m->NetworkChanged)
+                LogMsg("setsockopt - IP_MULTICAST_IF error %.4a %d errno %d (%s)", &info->ifa_v4addr, err, errno, strerror(errno));
+        #endif
+        }
+    }
     else if (dst->type == mDNSAddrType_IPv6)
     {
@@ -2274,10 +2263,10 @@
         if (ss->proxy)
         {
-            m->p->UDPProxyCallback(m, &m->p->UDPProxy, (unsigned char *)&m->imsg, (unsigned char*)&m->imsg + err, &senderAddr,
+            m->p->UDPProxyCallback(m, &m->p->UDPProxy, &m->imsg.m, (unsigned char*)&m->imsg + err, &senderAddr,
                 senderPort, &destAddr, ss->port, InterfaceID, NULL);
         }
         else
         {
-            mDNSCoreReceive(m, &m->imsg, (unsigned char*)&m->imsg + err, &senderAddr, senderPort, &destAddr, ss->port, InterfaceID);
+            mDNSCoreReceive(m, &m->imsg.m, (unsigned char*)&m->imsg + err, &senderAddr, senderPort, &destAddr, ss->port, InterfaceID);
         }
 
Index: mDNSResponder/mDNSMacOSX/mDNSResponder-entitlements.plist
===================================================================
--- mDNSResponder/mDNSMacOSX/mDNSResponder-entitlements.plist	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/mDNSMacOSX/mDNSResponder-entitlements.plist	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -21,4 +21,6 @@
     <key>com.apple.private.necp.match</key>
     <true/>
+    <key>com.apple.private.necp.policies</key>
+    <true/>
     <key>com.apple.security.network.server</key>
     <true/>
@@ -33,4 +35,12 @@
     <key>com.apple.BTServer.appleMfgDataScanner</key>
     <true/>
+    <key>com.apple.developer.networking.networkextension</key>
+    <array>
+      <string>app-proxy-provider-system</string>
+    </array>
+    <key>com.apple.private.neagent</key>
+    <true/>
+    <key>com.apple.private.nehelper.privileged</key>
+    <true/>
 </dict>
 </plist>
Index: mDNSResponder/mDNSMacOSX/mDNSResponder.sb
===================================================================
--- mDNSResponder/mDNSMacOSX/mDNSResponder.sb	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/mDNSMacOSX/mDNSResponder.sb	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -73,5 +73,7 @@
        (global-name "com.apple.blued")
        (global-name "com.apple.mobilegestalt.xpc")
-       (global-name "com.apple.snhelper"))
+       (global-name "com.apple.snhelper")
+       (global-name "com.apple.nehelper")
+       (global-name "com.apple.networkserviceproxy"))
 
 (allow mach-register
Index: mDNSResponder/mDNSShared/dns_sd.h
===================================================================
--- mDNSResponder/mDNSShared/dns_sd.h	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/mDNSShared/dns_sd.h	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -67,5 +67,5 @@
 
 #ifndef _DNS_SD_H
-#define _DNS_SD_H 7653011
+#define _DNS_SD_H 7655009
 
 #ifdef  __cplusplus
Index: mDNSResponder/mDNSShared/dnsextd.c
===================================================================
--- mDNSResponder/mDNSShared/dnsextd.c	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/mDNSShared/dnsextd.c	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -2356,5 +2356,5 @@
         qptr = getQuestion(&pkt->msg, qptr, end, 0, &q);
         if (!qptr) { Log("Malformatted LLQ from %s: cannot read question %d", addr, i); goto end; }
-        llq = (LLQOptData *)&opt.r.resrec.rdata->u.opt[0].u.llq + i; // point into OptData at index i
+        llq = &opt.r.resrec.rdata->u.opt[i].u.llq; // point into OptData at index i
         if (llq->vers != kLLQ_Vers) { Log("LLQ from %s contains bad version %d (expected %d)", addr, llq->vers, kLLQ_Vers); goto end; }
 
@@ -3095,5 +3095,5 @@
 void mDNS_ConfigChanged(mDNS *const m)  { ( void ) m; }
 void mDNSCoreMachineSleep(mDNS * const m, mDNSBool wake) { ( void ) m; ( void ) wake; }
-void mDNSCoreReceive(mDNS *const m, void *const msg, const mDNSu8 *const end,
+void mDNSCoreReceive(mDNS *const m, DNSMessage *const msg, const mDNSu8 *const end,
                      const mDNSAddr *const srcaddr, const mDNSIPPort srcport,
                      const mDNSAddr *const dstaddr, const mDNSIPPort dstport, const mDNSInterfaceID iid)
Index: mDNSResponder/mDNSShared/uds_daemon.c
===================================================================
--- mDNSResponder/mDNSShared/uds_daemon.c	(revision 7d33d36d73d2e902b107fb597e84e44ab11274a9)
+++ mDNSResponder/mDNSShared/uds_daemon.c	(revision a81495004c196cdbf5d1f918eb1510dd325c8283)
@@ -1284,4 +1284,8 @@
 {
     mStatus err = mStatus_BadParamErr;
+
+    if (request->terminate != connection_termination)
+    { LogMsg("%3d: DNSServiceRegisterRecord(not a shared connection ref)", request->sd); return(err); }
+
     AuthRecord *rr = read_rr_from_ipc_msg(request, 1, 1);
     if (rr)
@@ -4174,4 +4178,8 @@
     socklen_t len;
 
+    LogOperation("%3d: DNSServiceCreateDelegateConnection START PID[%d](%s)",
+                 request->sd, request->process_id, request->pid_name);
+    request->terminate = connection_termination;
+
     len = 0;
     pid = get_uint32(&request->msgptr, request->msgend);
@@ -4956,11 +4964,4 @@
             return;
         }
-        if (req->hdr.version != VERSION)
-        {
-            LogMsg("request_callback: ERROR: client IPC version %d incompatible with daemon IPC version %d PID[%d][%s]",
-                   req->hdr.version, VERSION, req->process_id, req->pid_name);
-            AbortUnlinkAndFree(req);
-            return;
-        }
 
         switch(req->hdr.op)            //          Interface       + other data
@@ -5063,10 +5064,5 @@
                             req->terminate = connection_termination;
                             break;
-                case connection_delegate_request:
-                            LogOperation("%3d: DNSServiceCreateDelegateConnection START PID[%d](%s)",
-                                req->sd, req->process_id, req->pid_name);
-                            req->terminate = connection_termination;
-                            handle_connection_delegate_request(req);
-                            break;
+                case connection_delegate_request:        handle_connection_delegate_request(req); break;
                 case resolve_request:              err = handle_resolve_request     (req);  break;
                 case query_request:                err = handle_queryrecord_request (req);  break;
