direct: avoid panic when an interface link is down

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

View File

@ -27,7 +27,7 @@ import (
)
// VERSION .
const VERSION = "0.6.7"
const VERSION = "0.6.8"
func main() {
// read configs

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