iOS进行VPN链接获取tunfd , iOS15无法正常创建连接,14正常!
用以下方法获取:
//获取tunFd
func getTunFd() ->Int32?
{
if #available(iOS 15, *) {
var buf = [CChar](repeating: 0, count: Int(IFNAMSIZ))
let utunPrefix = "utun".utf8CString.dropLast()
return (0...1024).first { (_ fd: Int32) -> Bool in
var len = socklen_t(buf.count)
return getsockopt(fd, 2, 2, &buf, &len) == 0 && buf.starts(with: utunPrefix)
}
} else {
return self.packetFlow.value(forKeyPath: "socket.fileDescriptor") as? Int32
}
}
参考感谢:https://blog.csdn.net/qq_26359763/article/details/118331747