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
This commit is contained in:
Jakob Borg 2016-05-22 09:04:27 +00:00 committed by Audrius Butkevicius
parent a89d487510
commit f6cc344623
10 changed files with 38 additions and 43 deletions

View File

@ -13,7 +13,7 @@ import (
"time" "time"
"github.com/AudriusButkevicius/go-nat-pmp" "github.com/AudriusButkevicius/go-nat-pmp"
"github.com/jackpal/gateway" "github.com/calmh/gateway"
"github.com/syncthing/syncthing/lib/nat" "github.com/syncthing/syncthing/lib/nat"
) )

View File

@ -2,25 +2,13 @@ package gateway
import ( import (
"bytes" "bytes"
"io/ioutil" "errors"
"net" "net"
"os/exec"
) )
func DiscoverGateway() (ip net.IP, err error) { var errNoGateway = errors.New("no gateway found")
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
}
func parseRoutePrint(output []byte) (net.IP, error) {
// Windows route output format is always like this: // Windows route output format is always like this:
// =========================================================================== // ===========================================================================
// Active Routes: // Active Routes:
@ -33,11 +21,18 @@ func DiscoverGateway() (ip net.IP, err error) {
outputLines := bytes.Split(output, []byte("\n")) outputLines := bytes.Split(output, []byte("\n"))
for idx, line := range outputLines { for idx, line := range outputLines {
if bytes.Contains(line, []byte("Active Routes:")) { if bytes.Contains(line, []byte("Active Routes:")) {
if len(outputLines) <= idx+2 {
return nil, errNoGateway
}
ipFields := bytes.Fields(outputLines[idx+2]) ipFields := bytes.Fields(outputLines[idx+2])
ip = net.ParseIP(string(ipFields[2])) if len(ipFields) < 3 {
break return nil, errNoGateway
}
ip := net.ParseIP(string(ipFields[2]))
return ip, nil
} }
} }
err = routeCmd.Wait() return nil, errNoGateway
return
} }

16
vendor/github.com/calmh/gateway/gateway_windows.go generated vendored Normal file
View File

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

View File

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

View File

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

13
vendor/manifest vendored
View File

@ -19,6 +19,13 @@
"revision": "3c0690cca16228b97741327b1b6781397afbdb24", "revision": "3c0690cca16228b97741327b1b6781397afbdb24",
"branch": "master" "branch": "master"
}, },
{
"importpath": "github.com/calmh/gateway",
"repository": "https://github.com/calmh/gateway",
"revision": "edad739645120eeb82866bc1901d3317b57909b1",
"branch": "master",
"notests": true
},
{ {
"importpath": "github.com/calmh/luhn", "importpath": "github.com/calmh/luhn",
"repository": "https://github.com/calmh/luhn", "repository": "https://github.com/calmh/luhn",
@ -49,12 +56,6 @@
"revision": "5f1c01d9f64b941dd9582c638279d046eda6ca31", "revision": "5f1c01d9f64b941dd9582c638279d046eda6ca31",
"branch": "master" "branch": "master"
}, },
{
"importpath": "github.com/jackpal/gateway",
"repository": "https://github.com/jackpal/gateway",
"revision": "32194371ec3f370166ee10a5ee079206532fdd74",
"branch": "master"
},
{ {
"importpath": "github.com/juju/ratelimit", "importpath": "github.com/juju/ratelimit",
"repository": "https://github.com/juju/ratelimit", "repository": "https://github.com/juju/ratelimit",