简体   繁体   English

处理丢失的IPv6连接的正确方法

[英]proper way to handle missing IPv6 connectivity

I'm currently looking for a way to properly handle missing IPv6 connectivity. 我目前正在寻找一种正确处理丢失的IPv6连接的方法。

The use case is, that i resolve a DNS record which might contain AAAA records and connect to each of the resolved IPs. 用例是,我解析可能包含AAAA记录的DNS记录,并连接到每个解析的IP。 Now the system running that code might not have IPv6 connectivity. 现在,运行该代码的系统可能没有IPv6连接。

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. 但是我不确定是否有更好的方法。

一个简单的解决方案是使用net.Dialer (将DualStack设置为true然后仅使用名称使用Dial()然后让库为您处理“高兴的眼球”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM