Unreachabe when using SCNetworkReachabilityCreateWithAddressPair with VPN service

I am testing a local vpn service using NEPacketTunnelNetworkSettings that currently use the IP of the underlying network interface (WiFi or Cellular) as the IP of the VPN interface.


However, when I use SCNetworkReachabilityCreateWithAddressPair and set the IP of VPN interface as the local address, the result is unreachable

    var addr = sockaddr_in()
    addr.sin_len = UInt8(MemoryLayout.size(ofValue: addr))
    addr.sin_family = sa_family_t(AF_INET)
    addr.sin_addr.s_addr = inet_addr(address)
   
    let hostAddress = withUnsafePointer(to: &hostaddr) {
        $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
            return $0
        }
    }
   
    guard let reachability = withUnsafePointer(to: &addr, {
        $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
            SCNetworkReachabilityCreateWithAddressPair(kCFAllocatorDefault, $0, hostAddress)
        }
    })else{
        return false
    }


Can anybody tell me why that happens and how to workaround?

I have the same problem with SCNetworkReachabilityCreateWithAddressPair. I can't make it work at all. I use BSD sockets and try to follow it's reachability status via SCNetworkReachabilityCreateWithAddressPair which is recommended approach for BSD sockets. It never tell the correct status even for just connected socket nor it report any event when actual network disruption works. The only semi working variant is to listen viability of 0.0.0.0 as chromium does: https://source.chromium.org/chromium/chromium/src/+/main:net/base/network_change_notifier_apple.mm. But this seems to work across all network routes, not the actual route used to establish connectivity between two sockets. Still not workaround found.

Unreachabe when using SCNetworkReachabilityCreateWithAddressPair with VPN service
 
 
Q