Retrieve Ipv4 and Ipv6 Nameservers Programmatically

Retrieve IPv4 and IPv6 nameservers programmatically

You really should not access the _u._ext parts of the resolver state, they are an internal implementation detail. The nscount6 member is currently unused and always zero. It had to be kept to avoid changing the ABI as the result of struct offset/size changes.

If you need the nameserver list, you should parse /etc/resolv.conf yourself. Note that eventually, glibc will also support more than three name servers, and those extra resolvers will not be reflected in the public resolver state.

Get IPv6 DNS Server Addresses using GetAdaptersAddresses()

You're passing the wrong data to inet_ntop. You should pass the sin_addr or sin6_addr member, depending on the protocol.

inet_ntop(AF_INET, &((struct sockaddr_in*)pDnServer->Address.lpSockaddr)->sin_addr, ipv4_addrstr, INET_ADDRSTRLEN);
inet_ntop(AF_INET6, &((struct sockaddr_in6*)pDnServer->Address.lpSockaddr)->sin6_addr, ipv6_addrstr, INET6_ADDRSTRLEN);

How to get IPv4 and IPv6 address of local machine?

string strHostName = System.Net.Dns.GetHostName();;
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
Console.WriteLine(addr[addr.Length-1].ToString());
if (addr[0].AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
{
Console.WriteLine(addr[0].ToString()); //ipv6
}


Related Topics



Leave a reply



Submit