netbird/client/internal/routemanager/systemops_windows.go

41 lines
871 B
Go
Raw Normal View History

//go:build windows
// +build windows
package routemanager
2023-06-09 19:15:39 +02:00
import (
"fmt"
"net/netip"
2023-06-09 19:17:26 +02:00
"github.com/yusufpapurcu/wmi"
2023-06-09 19:15:39 +02:00
)
type Win32_IP4RouteTable struct {
Destination string
Mask string
NextHop string
InterfaceIdx int
}
func existsInRouteTable(prefix netip.Prefix) (bool, error) {
var routes []Win32_IP4RouteTable
query := "SELECT Destination, Mask, NextHop, InterfaceIndex FROM Win32_IP4RouteTable"
err := wmi.Query(query, &routes)
if err != nil {
return true, err
}
fmt.Println("Destination Networks:")
for _, route := range routes {
fmt.Println("Destination :", route.Destination)
fmt.Println("Mask :", route.Mask)
// mask, _ := toIPAddr(m.Addrs[2])
// cidr, _ := net.IPMask(mask.To4()).Size()
// if route.Destination == prefix.Addr().String() && cidr == prefix.Bits() {
// return true, nil
// }
}
return false, nil
}