9.5 C
New York
Tuesday, March 11, 2025

ios – Getting a datagram too giant error whereas writing again to NEAppProxyUDPFlow


I’m attempting to setup an extension utilizing DNSProxyProvider that intercepts the DNS visitors on UDP and inserts our customized gadget identifier and ship it to our customized DNS Server which provides us the response which I ahead to the requesting consumer.

I’ve been capable of append the identifier with the area identify when sending out request to our customized DNS and I get the response again simply wonderful 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 giant" UserInfo={NSLocalizedDescription=The datagram was too giant}

Here’s what I’ve tried to this point.

  1. Truncating the datagram measurement to lower than 10 bytes.
  2. Sending in dummy Knowledge object whereas attempting to write down to the movement.
    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 perform which calls processUDPFlow

override func handleNewFlow(_ movement: NEAppProxyFlow) -> Bool {
        if movement is NEAppProxyTCPFlow {
            NSLog("BDDNSProxyProvider : Is TCP Move...")
        } else if let udpFlow = movement as? NEAppProxyUDPFlow {
            NSLog("BDDNSProxyProvider: handleNewFlow : (udpFlow)")
            processUDPFlow(udpFlow) // < --
        }
        
        return true
    }

Within the code beneath I concatenate area identify 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 acquired.")
                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.identify), Kind: (query.sort), Class: (query.klass)")
                }
                for reply in dnsMessage.solutions {
                    NSLog("tDatagram Reply: (reply.identify), Kind: (reply.sort), Knowledge: (reply.information)")
                }

                let oldDomain = self.extractDomainName(from: packet.0)!
                let packetWithNewDomain = self.replaceDomainName(in: packet.0, with: "827-(oldDomain)") // func to append gadget 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("Didn't 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 perform I exploit to exchange domainName

func extractDomainName(from datagram: Knowledge) -> 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 identify)
        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

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles