diff --git a/lib/pmp/pmp.go b/lib/pmp/pmp.go index 9dcabe7d3..3327a1bfe 100644 --- a/lib/pmp/pmp.go +++ b/lib/pmp/pmp.go @@ -13,7 +13,7 @@ import ( "time" "github.com/AudriusButkevicius/go-nat-pmp" - "github.com/jackpal/gateway" + "github.com/calmh/gateway" "github.com/syncthing/syncthing/lib/nat" ) diff --git a/vendor/github.com/jackpal/gateway/LICENSE b/vendor/github.com/calmh/gateway/LICENSE similarity index 100% rename from vendor/github.com/jackpal/gateway/LICENSE rename to vendor/github.com/calmh/gateway/LICENSE diff --git a/vendor/github.com/jackpal/gateway/gateway_windows.go b/vendor/github.com/calmh/gateway/gateway_common.go similarity index 67% rename from vendor/github.com/jackpal/gateway/gateway_windows.go rename to vendor/github.com/calmh/gateway/gateway_common.go index 282c8f685..b04f4b9c5 100644 --- a/vendor/github.com/jackpal/gateway/gateway_windows.go +++ b/vendor/github.com/calmh/gateway/gateway_common.go @@ -2,25 +2,13 @@ package gateway import ( "bytes" - "io/ioutil" + "errors" "net" - "os/exec" ) -func DiscoverGateway() (ip net.IP, err error) { - routeCmd := exec.Command("route", "print", "0.0.0.0") - stdOut, err := routeCmd.StdoutPipe() - if err != nil { - return - } - if err = routeCmd.Start(); err != nil { - return - } - output, err := ioutil.ReadAll(stdOut) - if err != nil { - return - } +var errNoGateway = errors.New("no gateway found") +func parseRoutePrint(output []byte) (net.IP, error) { // Windows route output format is always like this: // =========================================================================== // Active Routes: @@ -33,11 +21,18 @@ func DiscoverGateway() (ip net.IP, err error) { outputLines := bytes.Split(output, []byte("\n")) for idx, line := range outputLines { if bytes.Contains(line, []byte("Active Routes:")) { + if len(outputLines) <= idx+2 { + return nil, errNoGateway + } + ipFields := bytes.Fields(outputLines[idx+2]) - ip = net.ParseIP(string(ipFields[2])) - break + if len(ipFields) < 3 { + return nil, errNoGateway + } + + ip := net.ParseIP(string(ipFields[2])) + return ip, nil } } - err = routeCmd.Wait() - return + return nil, errNoGateway } diff --git a/vendor/github.com/jackpal/gateway/gateway_darwin.go b/vendor/github.com/calmh/gateway/gateway_darwin.go similarity index 100% rename from vendor/github.com/jackpal/gateway/gateway_darwin.go rename to vendor/github.com/calmh/gateway/gateway_darwin.go diff --git a/vendor/github.com/jackpal/gateway/gateway_linux.go b/vendor/github.com/calmh/gateway/gateway_linux.go similarity index 100% rename from vendor/github.com/jackpal/gateway/gateway_linux.go rename to vendor/github.com/calmh/gateway/gateway_linux.go diff --git a/vendor/github.com/jackpal/gateway/gateway_unimplemented.go b/vendor/github.com/calmh/gateway/gateway_unimplemented.go similarity index 100% rename from vendor/github.com/jackpal/gateway/gateway_unimplemented.go rename to vendor/github.com/calmh/gateway/gateway_unimplemented.go diff --git a/vendor/github.com/calmh/gateway/gateway_windows.go b/vendor/github.com/calmh/gateway/gateway_windows.go new file mode 100644 index 000000000..5f68bc1b0 --- /dev/null +++ b/vendor/github.com/calmh/gateway/gateway_windows.go @@ -0,0 +1,16 @@ +package gateway + +import ( + "net" + "os/exec" +) + +func DiscoverGateway() (ip net.IP, err error) { + routeCmd := exec.Command("route", "print", "0.0.0.0") + output, err := routeCmd.CombinedOutput() + if err != nil { + return nil, err + } + + return parseRoutePrint(output) +} diff --git a/vendor/github.com/jackpal/gateway/README.md b/vendor/github.com/jackpal/gateway/README.md deleted file mode 100644 index 49cc0b85c..000000000 --- a/vendor/github.com/jackpal/gateway/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# gateway - -A very simple library for discovering the IP address of the local LAN gateway. - -Provides implementations for Linux, OS X (Darwin) and Windows. - -Pull requests for other OSs happily considered! diff --git a/vendor/github.com/jackpal/gateway/gateway_test.go b/vendor/github.com/jackpal/gateway/gateway_test.go deleted file mode 100644 index b127b02dc..000000000 --- a/vendor/github.com/jackpal/gateway/gateway_test.go +++ /dev/null @@ -1,10 +0,0 @@ -package gateway - -import "testing" - -func TestGateway(t *testing.T) { - ip, err := DiscoverGateway() - if err != nil { - t.Errorf("DiscoverGateway() = %v,%v", ip, err) - } -} diff --git a/vendor/manifest b/vendor/manifest index 80651c729..7b962ecdc 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -19,6 +19,13 @@ "revision": "3c0690cca16228b97741327b1b6781397afbdb24", "branch": "master" }, + { + "importpath": "github.com/calmh/gateway", + "repository": "https://github.com/calmh/gateway", + "revision": "edad739645120eeb82866bc1901d3317b57909b1", + "branch": "master", + "notests": true + }, { "importpath": "github.com/calmh/luhn", "repository": "https://github.com/calmh/luhn", @@ -49,12 +56,6 @@ "revision": "5f1c01d9f64b941dd9582c638279d046eda6ca31", "branch": "master" }, - { - "importpath": "github.com/jackpal/gateway", - "repository": "https://github.com/jackpal/gateway", - "revision": "32194371ec3f370166ee10a5ee079206532fdd74", - "branch": "master" - }, { "importpath": "github.com/juju/ratelimit", "repository": "https://github.com/juju/ratelimit",