0

I am looking to possibly add the Ios RequestPermission Github project into my app. I am a new self-taught developer actually majoring in cyber-security. This said, I am not familiar with code security. However, while looking through the project I noticed a file for internet connection. here is the code

   import SystemConfiguration

   public class SPInternetConnection {

static func check() -> Bool {
    var zeroAddress = sockaddr_in()
    zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress))
    zeroAddress.sin_family = sa_family_t(AF_INET)
    let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) {
        $0.withMemoryRebound(to: sockaddr.self, capacity: 1) 
 {zeroSockAddress in
            SCNetworkReachabilityCreateWithAddress(nil, zeroSockAddress)
        }
    }
    var flags = SCNetworkReachabilityFlags()
    if !SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) {
        return false
    }
    let isReachable = (flags.rawValue & UInt32(kSCNetworkFlagsReachable)) != 0
    let needsConnection = (flags.rawValue & UInt32(kSCNetworkFlagsConnectionRequired)) != 0
    return (isReachable && !needsConnection)
}
}

What is this? And is it safe to use in my app?

W P
  • 81
  • 2
  • 11
  • 1
    From another SO question, it appears to be safe. Checks to see if the network is available. https://stackoverflow.com/questions/25623272/how-to-use-scnetworkreachability-in-swift (Note: not a swift dev) – Phix Sep 15 '17 at 17:15
  • [SCNetworkReachability](https://developer.apple.com/documentation/systemconfiguration/scnetworkreachability-g7d) is from Apple's SystemConfiguration framework, and all methods are well documented. – Martin R Sep 15 '17 at 17:35
  • Can you clarify your question? "Safe" in what sense? What is "questionable" about the code? – Martin R Sep 15 '17 at 18:16
  • Just couldn't figure out why it was calling internet. The feature is supposed to be a way to stylize the "request for permission" to use Bluetooth for an example. – W P Sep 15 '17 at 18:37

0 Answers0