iphone获取3G DNS主机名和ip地址 [英] iphone get 3G DNS host name and ip address

查看:32
本文介绍了iphone获取3G DNS主机名和ip地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Objective C/C/C++中是否可以获取当前DNS服务器ip地址用于3G/Cell数据连接?

Is it possible in Objective C / C / C++ to get the current DNS server ip address for 3G / Cell data connection?

环顾四周,找不到确切的答案.

Looked around and could not find definitive answer.

推荐答案

#include <arpa/inet.h>
#include <ifaddrs.h>
#include <resolv.h>
#include <dns.h>

// 
- (NSString *) getDNSServers 
{
    NSMutableString *addresses = [[NSMutableString alloc]initWithString:@"DNS Addresses 
"];

    res_state res = malloc(sizeof(struct __res_state));

    int result = res_ninit(res);

    if ( result == 0 )
    {    
        for ( int i = 0; i < res->nscount; i++ )
        {
            NSString *s = [NSString stringWithUTF8String :  inet_ntoa(res->nsaddr_list[i].sin_addr)];
            [addresses appendFormat:@"%@
",s];
            NSLog(@"%@",s);
        }
    }
    else 
        [addresses appendString:@" res_init result != 0"];

    return addresses;
    }

这篇关于iphone获取3G DNS主机名和ip地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆