tjfontaine / node-dns

Replacement dns module in pure javascript for node.js
MIT License
584 stars 153 forks source link

Add rudimentary Windows support #1

Open daguej opened 12 years ago

daguej commented 12 years ago

AKA fix it so it doesn't crash as soon as you start up.

Under Windows, /etc/hosts and /etc/resolv.conf obviously don't exist. This patches platform.js so that you can at least get up and running under Windows.

tjfontaine commented 12 years ago

After looking around I see that there is also a way forward on windows with the registry entry System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces I would prefer to traverse this with a native mechanism from node itself, but in the absence of that reg query will work

daguej commented 12 years ago

Let's just do it properly: https://github.com/daguej/node-winnetinfo

tjfontaine commented 12 years ago

I'm all for doing things TheRightWay(tm) where possible.

I wonder if doing it properly is to actually use GetAdaptersAddresses since that's what c-ares and .net use. C-ares actually tries GetAdaptersAddresses, if that fails then GetNetworkParams, and if that fails registry. Considering the library is meant as a drop in replacement, it should probably behave similarly where appropriate.

GetAdaptersAddresses is used in uv_interface_addresses on HEAD. There's a part of me that wonders if os.networkInterfaces shouldn't in fact return this information. However most other platforms don't offer a similar interface, so it would be a quirk to win32 but only in the form of an additional field in the object.

So to use a third party solution like your new module for this, means we either include it as a dependency (in which case your module needs to install cleanly on unix platforms and essentially be a NOOP), or we add it as an optionalDependency and handle the case when its not installed gracefully.

Sadly NPM doesn't currently support conditional dependencies (or even platform dependencies for that matter)

Another option would be for native-dns to break a design goal of being pure javascript and have a binding portion just like your module, which is only built for the win32 platform.

tjfontaine commented 12 years ago

f6a794d contains some refactoring, watching of /etc/resolv.conf and /etc/hosts are disabled by default, unless someone sets dns.platform.watching at which point it simply doesn't work for windows currently.

On win32 the initial name servers are google's, and the it should theoretically load the proper hosts file.

Please let me know if this works (it's not currently published to npm)

taoeffect commented 8 years ago

This project is no longer maintained, but we are happy to link to a well maintained fork.

Please see: https://github.com/tjfontaine/node-dns/issues/111