Replace netstat from net-tools by ip from iproute2 (linux)

This commit is contained in:
Daniel Rodriguez 2018-01-20 21:11:17 +01:00
commit 881126941b
3 changed files with 45 additions and 33 deletions

20
net/net_linux.go Normal file
View file

@ -0,0 +1,20 @@
package net
import "regexp"
// only matches gateway lines
var IPv4RouteParser = regexp.MustCompile("^(default|[0-9\\.]+)\\svia\\s([0-9\\.]+)\\sdev\\s(\\w+)\\s.*$")
var IPv4RouteTokens = 4
var IPv4RouteCmd = "ip"
var IPv4RouteCmdOpts = []string{"route"}
func IPv4RouteIsGateway(ifname string, tokens []string, f func(gateway string) (*Endpoint, error)) (*Endpoint, error) {
ifname2 := tokens[3]
if ifname == ifname2 {
gateway := tokens[2]
return f(gateway)
}
return nil, nil
}