//go:build darwin package netdetect import ( "context" "fmt" "os/exec" "time" ) // routeQueryTimeout bounds the external route-table query. const routeQueryTimeout = 2 * time.Second // DefaultRoutes returns the host's IPv4 default routes, read from the macOS // routing table. func DefaultRoutes() ([]Route, error) { ctx, cancel := context.WithTimeout(context.Background(), routeQueryTimeout) defer cancel() out, err := exec.CommandContext(ctx, "netstat", "-rn", "-f", "inet").Output() if err != nil { return nil, fmt.Errorf("running netstat: %w", err) } return parseNetstat(string(out)), nil }