I’m attempting to setup an extension utilizing DNSProxyProvider that intercepts the DNS site visitors on UDP and inserts our customized system identifier and ship it to our customized DNS Server which supplies us the response which I ahead to the requesting consumer.
I’ve been in a position to append the identifier with the area title when sending out request to our customized DNS and I get the response again simply positive however when I attempt to write the response to the udpflow I get this error in Console Logs.
Error Area=NEAppProxyFlowErrorDomain Code=9 "The datagram was too massive" UserInfo={NSLocalizedDescription=The datagram was too massive}
Here’s what I’ve tried thus far.
- Truncating the datagram measurement to lower than 10 bytes.
- Sending in dummy Information object whereas attempting to write down to the stream.
 3)Double checking the Signing and Capabilities, for Targets, the App and Community Extension.
Hooked up beneath is code from my NEDNSProxyProvider. The DNS request is course of within the handleNewFlow operate which calls processUDPFlow
override func handleNewFlow(_ stream: NEAppProxyFlow) -> Bool {
        if stream is NEAppProxyTCPFlow {
            NSLog("BDDNSProxyProvider : Is TCP Stream...")
        } else if let udpFlow = stream as? NEAppProxyUDPFlow {
            NSLog("BDDNSProxyProvider: handleNewFlow : (udpFlow)")
            processUDPFlow(udpFlow) // < --
        }
        
        return true
    }
Within the code beneath I concatenate area title within the request with deviceId and ship it to our server. Even have the Logs traces in, please ignore them.
// Learn incoming DNS packets from the consumer
personal func processUDPFlow(_ udpFlow: NEAppProxyUDPFlow) {
        self.udpAppProxyFlow = udpFlow
        udpFlow.readDatagrams { datagrams, error in
            if let error = error {
                NSLog("Error studying datagrams: (error.localizedDescription)")
                return
            }
            guard let datagrams = datagrams else {
                NSLog("No datagrams obtained.")
                return
            }
            // Ahead every DNS packet to the customized DNS server
            for (index, packet) in datagrams.enumerated() {
                
                let dnsMessage = self.parseDNSMessage(from: packet.0)
                NSLog("tDatagram Header: (dnsMessage.header)")
                for query in dnsMessage.questions {
                    NSLog("tDatagram Query: (query.title), Sort: (query.sort), Class: (query.klass)")
                }
                for reply in dnsMessage.solutions {
                    NSLog("tDatagram Reply: (reply.title), Sort: (reply.sort), Information: (reply.information)")
                }
                let oldDomain = self.extractDomainName(from: packet.0)!
                let packetWithNewDomain = self.replaceDomainName(in: packet.0, with: "827-(oldDomain)") // func to append system ID (827)
                NSLog("Packet's new area (self.extractDomainName(from: packetWithNewDomain ?? packet.0) ?? "Discovered nil")")
                self.sendToCustomDNSServer(packetWithNewDomain!) { responseDatagram in
                    guard let responseDatagram = responseDatagram else {
                        NSLog("Did not get a response from the customized DNS server")
                        return
                    }
                    let tDatagram = (responseDatagram, packet.1)
                    
                    udpFlow.writeDatagrams([tDatagram]) { error in
                        if let error = error {
                            NSLog("Failed to write down DNS response again to consumer: (error)")
                        } else {
                            NSLog("Efficiently wrote DNS response again to consumer.")
                        }
                    }
                }
            }
            // Proceed Studying Datagrams
            self.processUDPFlow(udpFlow)
        }
    }
Following is the operate I take advantage of to switch domainName
func extractDomainName(from datagram: Information) -> String? {
    // Make sure the datagram has sufficient information for a DNS header
    guard datagram.rely > 12 else { return nil }
    // Begin studying after the header (12 bytes)
    var offset = 12
    var domainName = ""
    whereas offset < datagram.rely {
        // Learn the size of the following label
        let size = Int(datagram[offset])
        offset += 1
        // Test for the null terminator (finish of area title)
        if size == 0 {
            break
        }
        // Guarantee there's sufficient information for the label
        guard offset + size <= datagram.rely else { return nil }
        // Extract the label as a string
        if let label = String(information: datagram[offset..Everything is falling into place other than this last Error I get when I try to write back to flow. What am I missing here and how can I resolve this issue?
Any help would be appreciated.
Thanks

