I'm trying to get the my dns server IP using using libresolv
framework , 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));
}
}
Anything wrong with my code here ?
Thanks
Edit
Tried to use the code in SO's other 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>
While when running the command : cat /etc/resolv.conf
I get nameserver 10.0.0.138
which is what I want.
Any idea how to get that ?
Edit2
I tried this as well, but still getting the "0.0.0.0" response.
u_char buf[NS_PACKETSZ];
int responseLen;
res_query("www.google.com",ns_c_in,ns_t_ns,buf,sizeof(buf));