Obtaining the DNS Server IP Address on IPhone

I am trying to get the IP address of my DNS server using the libresolvframework, but all I get is "0.0.0.0"

-(void) getDns
{
    res_init();

    for (int i=0;i<MAXNS;i++)
    {       
        printf("%s",inet_ntoa(_res.nsaddr_list[i].sin_addr));

    }
}

Is there something wrong with my code here?

thank

Edit

Tried to use the code in another question, but this is what I get when the host is "apple.com"

2011-03-16 15:07:21.689 MobileMax[5876:207] RESOLVED 0:<17.149.160.49>
2011-03-16 15:07:21.691 MobileMax[5876:207] RESOLVED 1:<17.251.200.70>
2011-03-16 15:07:21.691 MobileMax[5876:207] RESOLVED 2:<17.112.152.57>

At run time: cat /etc/resolv.conf I get nameserver 10.0.0.138what I want.

Any idea how to get this?

Edit2

I tried this too, but still get the answer "0.0.0.0".

u_char buf[NS_PACKETSZ];
int responseLen;             

    res_query("www.google.com",ns_c_in,ns_t_ns,buf,sizeof(buf));
+3
source share
2 answers

, , . res_query res_search. iOS CFHost *, , . Apple ( MyResolveNameToAddress).

: /etc/resolv.conf (). , SystemConfigFramework, , iOS ( , ).

0

, DNS-. libresolv.lib

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

    - (NSString *) getDNSServers
    {
    // dont forget to link libresolv.lib
    NSMutableString *addresses = [[NSMutableString alloc]initWithString:@"DNS Addresses \n"];

    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:@"%@\n",s];
            NSLog(@"%@",s);
        }
    }
    else
        [addresses appendString:@" res_init result != 0"];

    return addresses;
}
0

All Articles