Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use iphlpapi for Windows resolution #55

Open
kingle opened this issue Jun 3, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@kingle
Copy link
Collaborator

commented Jun 3, 2019

ResolverConfig currently parses ipconfig to grab DNS information as a fallback. With the sun ResolverConfiguration implementation possibly going away in the future, we should consider additional options. The most promising one is to use the iphlpapi library if on Windows using the (optional scoped) JNA dependency. Call GetNetworkParams:

C++ example code here:
https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getnetworkparams

@kingle

This comment has been minimized.

@ibauersachs

This comment has been minimized.

Copy link
Member

commented Jun 4, 2019

I was looking at a too old JNA version (some 4.x) yesterday and missed that it's now there. Awesome, something less to worry about.

@kingle

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 4, 2019

One caveat, when I did the testing, it looks like the GetNetworkParams only works with IPv4 addresses and doesn't return the IPv6 address like my ipconfig outputs. There may still need to be some work to make it a better "try-this-before-ipconfig" option on Windows. We may want to look at the GetAdaptersAddresses https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getadaptersaddresses

@ibauersachs

This comment has been minimized.

Copy link
Member

commented Jun 5, 2019

Just another example of where Java's built-in mechanism for nameserver lookup fails (via Netty/JNDA):

  • At home, connected via WiFi and Ethernet
  • Both NICs have the providers nameservers assigned via DHCP
  • The nameservers are public IPs, but are only accessible from within my ISPs network
  • A VPN connection to my office assigns the companys nameservers
  • The VPN is the default gateway (with metric=0), so everything goes via the VPN

Netty tries to query the ISPs nameservers and fails since the query reaches them via the public IP of my company. Yuck. Interestingly though, InetAddress.getByName("...") works - sun.net.dns.ResolverConfiguration.open().nameservers() contains seven nameservers, including the ones assigned via VPN (IPv4 only, the VPN is dual-stack and assigns nameservers).

@ibauersachs

This comment has been minimized.

Copy link
Member

commented Jul 20, 2019

See branch windows-dns-search for a demo of retrieving all DNS servers (IPv4/IPv6) via JNA. Needs cleanup and ordering of interfaces by metric.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.