fix: refactored routing logic (fixes #701)

This commit is contained in:
Simone Margaritelli 2021-04-10 21:55:00 +02:00
commit 43a93fd866
11 changed files with 202 additions and 80 deletions

View file

@ -3,25 +3,11 @@ package network
import (
"fmt"
"net"
"regexp"
"strings"
"github.com/google/gopacket/pcap"
)
// only matches gateway lines
var IPv4RouteParser = regexp.MustCompile("^.+\\s+.+\\s+\\d+\\s+([0-9\\.]+/\\d+)\\s+\\d+\\s+([0-9\\.]+).*$")
var IPv4RouteTokens = 3
var IPv4RouteCmd = "netsh"
var IPv4RouteCmdOpts = []string{"interface", "ipv4", "show", "route"}
func IPv4RouteIsGateway(ifname string, tokens []string, f func(gateway string) (*Endpoint, error)) (*Endpoint, error) {
// TODO check if the subnet is the same as iface ?
// subnet := tokens[1]
gateway := tokens[2]
return f(gateway)
}
/*
* net.Interface does not have the correct name on Windows and pcap.Interface
* does not have the hardware address for some reason ... so this is what I