I'm currently looking for a way to properly handle missing IPv6 connectivity.
The use case is, that i resolve a DNS record which might contain AAAA
records and connect to each of the resolved IPs. Now the system running that code might not have IPv6 connectivity.
So i'm looking for the proper way to handle this and ignore these records, but only if the host can't connect anyway.
My current approach is:
if ip.To4() == nil && err.(*net.OpError).Err.(*os.SyscallError).Err == syscall.EHOSTUNREACH {
log.Info("ignoring unreachable IPv6 address")
continue
}
But i'm not sure, if there is a better way.
A simple solution would be to use a net.Dialer
with DualStack
set to true
and just Dial()
using a name and let the library handle the "happy eyeballs" for you.