fix non local peer and add multihop

This commit is contained in:
Mayuresh Gaitonde
2018-11-26 16:44:39 -08:00
parent b641eb979e
commit e15172111e
2 changed files with 24 additions and 7 deletions

View File

@@ -16,6 +16,15 @@ func gateway() (net.IP, error) {
return net.ParseIP(strings.TrimSpace(string(out))), nil
}
func via(dest net.IP) (net.IP, error) {
cmd := fmt.Sprintf(`ip route get %s | grep via | cut -d" " -f3`, dest.String())
out, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
return nil, fmt.Errorf("Failed to execute command: %s", cmd)
}
return net.ParseIP(strings.TrimSpace(string(out))), nil
}
func localAddress(gw net.IP) (net.IP, error) {
addrs, err := net.InterfaceAddrs()
if err != nil {