是否连接VPN

//需要导入ifadds头文件
//是否连接VPN
- (BOOL)isVPNConnected{
    struct ifaddrs *interfaces = NULL;
    struct ifaddrs *temp_addr = NULL;
    int success = 0;
    //检索当前接口,0 成功
    success = getifaddrs(&interfaces);
    if (success == 0) {
        //循环链表接口
        temp_addr = interfaces;
        while (temp_addr != NULL) {
            NSString *string = [NSString stringWithFormat:@"%s" , temp_addr->ifa_name];
            if ([string rangeOfString:@"tap"].location != NSNotFound ||
                [string rangeOfString:@"tun"].location != NSNotFound ||
                [string rangeOfString:@"ppp"].location != NSNotFound){
                return YES;
            }
            temp_addr = temp_addr->ifa_next;
        }
    }
    // Free memory
    freeifaddrs(interfaces);
    [inspirationDetailVC.view myMBProgressShowView:MBLocalizedString(KNetworkFailed)];
    return NO;
}
上一篇:C#生成DLL,在Unity中导入/调用DLL


下一篇:C++顺序性容器、关联性容器与容器适配器