refact: i will just comment with 'Thank you Microsoft <3'

This commit is contained in:
evilsocket 2018-02-07 23:10:57 +01:00
commit 8a5916c685
4 changed files with 53 additions and 39 deletions

View file

@ -2,6 +2,7 @@ package net
import (
"regexp"
"runtime"
)
// only matches gateway lines
@ -16,3 +17,37 @@ func IPv4RouteIsGateway(ifname string, tokens []string, f func(gateway string) (
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
* had to do in Windows ... tnx Microsoft <3
*/
func areTheSame(iface net.Interface, piface pcap.Interface) bool {
if addrs, err := iface.Addrs(); err == nil {
for _, ia := range addrs {
for _, ib := range piface.Addresses {
if ia.String() == ib.IP.String() || strings.HasPrefix(ia.String(), ib.IP.String()) {
return true
}
}
}
}
return false
}
func getInterfaceName(iface net.Interface) string {
devs, err := pcap.FindAllDevs()
if err != nil {
return iface.Name
}
for _, dev := range devs {
if areTheSame(iface, dev) {
return dev.Name
}
}
return iface.Name
}