feature-28 #30

Manually merged
nicolas.boufideline merged 18 commits from feature-28 into main 2026-05-23 20:43:51 +00:00
2 changed files with 35 additions and 0 deletions
Showing only changes of commit c0caf1a24c - Show all commits

f-28: add GetDefaultGateway to netif

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
GnomeZworc 2026-05-18 22:49:21 +02:00
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632

View file

@ -0,0 +1,23 @@
//go:build linux
package netif
import (
"fmt"
"net"
"github.com/vishvananda/netlink"
)
func GetDefaultGateway() (net.IP, error) {
routes, err := netlink.RouteList(nil, netlink.FAMILY_V4)
if err != nil {
return nil, fmt.Errorf("list routes: %w", err)
}
for _, r := range routes {
if r.Dst == nil && r.Gw != nil {
return r.Gw, nil
}
}
return nil, fmt.Errorf("no default gateway found")
}

View file

@ -0,0 +1,12 @@
//go:build !linux
package netif
import (
"fmt"
"net"
)
func GetDefaultGateway() (net.IP, error) {
return nil, fmt.Errorf("not supported on this platform")
}