direct: avoid panic when an interface link is down

This commit is contained in:
nadoo committed 2018-08-30 07:35:37 +08:00
1 parent 1c2ad64000
commit 0170fd7c98
2 files changed
+7 -4

No files matched your search

+6 -3
View File
@@ -55,6 +55,11 @@ func (d *Direct) Dial(network, addr string) (c net.Conn, err error) {
}
}
// no ip available (so no dials made), maybe the interface link is down
if c == nil && err == nil {
err = errors.New("dial failed, maybe the interface link is down, please check it")
}
return
}
@@ -113,9 +118,7 @@ func (d *Direct) IFaceIPs() (ips []net.IP) {
}
for _, ipnet := range ipnets {
if ip := ipnet.(*net.IPNet).IP; !ip.IsLinkLocalUnicast() {
ips = append(ips, ip)
}
ips = append(ips, ipnet.(*net.IPNet).IP) //!ip.IsLinkLocalUnicast()
}
return