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:
committed by
Audrius Butkevicius
parent
a89d487510
commit
f6cc344623
0
vendor/github.com/jackpal/gateway/LICENSE → vendor/github.com/calmh/gateway/LICENSE
generated
vendored
0
vendor/github.com/jackpal/gateway/LICENSE → vendor/github.com/calmh/gateway/LICENSE
generated
vendored
@@ -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
|
||||
}
|
||||
16
vendor/github.com/calmh/gateway/gateway_windows.go
generated
vendored
Normal file
16
vendor/github.com/calmh/gateway/gateway_windows.go
generated
vendored
Normal 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)
|
||||
}
|
||||
7
vendor/github.com/jackpal/gateway/README.md
generated
vendored
7
vendor/github.com/jackpal/gateway/README.md
generated
vendored
@@ -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!
|
||||
10
vendor/github.com/jackpal/gateway/gateway_test.go
generated
vendored
10
vendor/github.com/jackpal/gateway/gateway_test.go
generated
vendored
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user