diff --git a/route_info_aix.go b/route_info_aix.go new file mode 100644 index 00000000..4e23d9d4 --- /dev/null +++ b/route_info_aix.go @@ -0,0 +1,35 @@ +//go:build aix + +package sockaddr + +import ( + "errors" + "os/exec" +) + +var cmds map[string][]string = map[string][]string{ + "route": {"/usr/sbin/route", "-n", "get", "default"}, +} + +// NewRouteInfo returns a BSD-specific implementation of the RouteInfo +// interface. +func NewRouteInfo() (routeInfo, error) { + return routeInfo{ + cmds: cmds, + }, nil +} + +// GetDefaultInterfaceName returns the interface name attached to the default +// route on the default interface. +func (ri routeInfo) GetDefaultInterfaceName() (string, error) { + out, err := exec.Command(cmds["route"][0], cmds["route"][1:]...).Output() + if err != nil { + return "", err + } + + var ifName string + if ifName, err = parseDefaultIfNameFromRoute(string(out)); err != nil { + return "", errors.New("No default interface found") + } + return ifName, nil +} diff --git a/route_info_android.go b/route_info_android.go index 9885915a..059ddaeb 100644 --- a/route_info_android.go +++ b/route_info_android.go @@ -1,3 +1,5 @@ +//go:build android + package sockaddr import ( @@ -5,10 +7,6 @@ import ( "os/exec" ) -type routeInfo struct { - cmds map[string][]string -} - // NewRouteInfo returns a Android-specific implementation of the RouteInfo // interface. func NewRouteInfo() (routeInfo, error) { diff --git a/route_info_default.go b/route_info_default.go index 6df864ba..db0052fa 100644 --- a/route_info_default.go +++ b/route_info_default.go @@ -1,5 +1,5 @@ -//go:build android || nacl || plan9 || js -// +build android nacl plan9 js +//go:build nacl || plan9 || js +// +build nacl plan9 js package sockaddr diff --git a/route_info_solaris.go b/route_info_solaris.go index 5843d58c..1354a73b 100644 --- a/route_info_solaris.go +++ b/route_info_solaris.go @@ -1,3 +1,5 @@ +//go:build solaris + package sockaddr import (