From 1ebbaaaebb97d40e5464b29ed6b75f31ae383c02 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 19 Nov 2020 09:05:32 -0800 Subject: [PATCH] net/interfaces: make syscall and netstat agree when multiple gateways are present likelyHomeRouterIPDarwinSyscall iterates through the list of routes, looking for a private gateway, returning the first one it finds. likelyHomeRouterIPDarwinExec does the same thing, except that it returns the last one it finds. As a result, when there are multiple gateways, TestLikelyHomeRouterIPSyscallExec fails. (At least, I think that that is what is happening; I am going inferring from observed behavior.) Signed-off-by: Josh Bleecher Snyder --- net/interfaces/interfaces_darwin.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/interfaces/interfaces_darwin.go b/net/interfaces/interfaces_darwin.go index 43fdfa096..77d975f1c 100644 --- a/net/interfaces/interfaces_darwin.go +++ b/net/interfaces/interfaces_darwin.go @@ -5,6 +5,7 @@ package interfaces import ( + "errors" "os/exec" "go4.org/mem" @@ -62,8 +63,12 @@ func likelyHomeRouterIPDarwinExec() (ret netaddr.IP, ok bool) { ip, err := netaddr.ParseIP(string(mem.Append(nil, ipm))) if err == nil && isPrivateIP(ip) { ret = ip + // We've found what we're looking for. + return stopReadingNetstatTable } return nil }) return ret, !ret.IsZero() } + +var stopReadingNetstatTable = errors.New("found private gateway")