Selaa lähdekoodia

vendor: Replace github.com/jackpal/gateway with github.com/calmh/gateway (fixes #3142)

Switch to my forked version which contains a fix for this issue. I'll
track upstream in the future if things update there, and attempt to
contribute back fixes...

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3149
Jakob Borg 10 vuotta sitten
vanhempi
sitoutus
f6cc344623

+ 1 - 1
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"
 )
 

+ 0 - 0
vendor/github.com/jackpal/gateway/LICENSE → vendor/github.com/calmh/gateway/LICENSE


+ 14 - 19
vendor/github.com/jackpal/gateway/gateway_windows.go → 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
 }

+ 0 - 0
vendor/github.com/jackpal/gateway/gateway_darwin.go → vendor/github.com/calmh/gateway/gateway_darwin.go


+ 0 - 0
vendor/github.com/jackpal/gateway/gateway_linux.go → vendor/github.com/calmh/gateway/gateway_linux.go


+ 0 - 0
vendor/github.com/jackpal/gateway/gateway_unimplemented.go → vendor/github.com/calmh/gateway/gateway_unimplemented.go


+ 16 - 0
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)
+}

+ 0 - 7
vendor/github.com/jackpal/gateway/README.md

@@ -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!

+ 0 - 10
vendor/github.com/jackpal/gateway/gateway_test.go

@@ -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)
-	}
-}

+ 7 - 6
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",