Hello!
I'd like to ask about the best way of getting a list of DNS servers from the system (iOS & macOS).
Why?
I am using NEPacketTunnelProvider
to implement a VPN app. When a device joins a network with a Captive Portal and the VPN is on, the VPN should redirect DNS queries to the DNS servers that were received from the network's DHCP server. So that my VPN is able to correctly reroute the traffic which is not blocked by the network's gateway and the Captive Portal landing page is served.
When I don't do anything, the traffic goes to the tunnel and the tunnel's encrypted traffic is then dropped by the gateway serving the Captive Portal.
When I temporarily turn off the VPN, opt out of all the traffic or pass the traffic to the system resolver, the traffic gets affected by other network settings (like DNSSettings) which leads to the same situation - the user not being able to authenticate with the Captive Portal.
So far, I have tried multiple ways, including res_9_getservers
but unsuccessfully. As a part of my investigation, I have found out that the /etc/resolv.conf
file is not populated with DNS servers until the Captive Portal is acknowledged by the user which makes getaddrinfo
unusable to achieve my goal. But I am not sure if that's a bug or intended behavior.
Thank you for your help!