IPv6 and IPv4 name resolution with Go
As part of a work-related project, I'm writing code that needs to resolve DNS names using Go , on illumos . While doing this work, I noticed a very surprising thing. When a host has both IPv6 and IPv4 addresses associated with a name (such as localhost ), Go prefers to resolve to the IPv4 version of the name, unless one has asked specifically for v6 names. This flies in the fact of existing practice on illumos & Solaris systems, where resolving a name tends to give an IPv6 result, assuming that any IPv6 address is plumbed on the system. (And on modern installations, that is the default -- at least the loopback interface of ::1 is always plumbed by default. And not only that, but services listening on that address will automatically serve up both v6 and v4 clients that connect on either ::1 or 127.0.0.1.) The rationale for this logic is buried in the Go net/ipsock.go file, in comments for the function firstFavoriteAddr () : 76 // We'll take any IP address