2024-05-21 20:38:53 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
|
|
//go:build darwin || windows
|
|
|
|
|
|
|
|
package netns
|
|
|
|
|
|
|
|
import (
|
2024-07-31 17:45:14 +00:00
|
|
|
"errors"
|
2024-05-21 20:38:53 +00:00
|
|
|
"net"
|
|
|
|
"net/netip"
|
|
|
|
)
|
|
|
|
|
2024-07-31 17:45:14 +00:00
|
|
|
var errUnspecifiedHost = errors.New("unspecified host")
|
|
|
|
|
2024-05-21 20:38:53 +00:00
|
|
|
func parseAddress(address string) (addr netip.Addr, err error) {
|
|
|
|
host, _, err := net.SplitHostPort(address)
|
|
|
|
if err != nil {
|
|
|
|
// error means the string didn't contain a port number, so use the string directly
|
|
|
|
host = address
|
|
|
|
}
|
2024-07-31 17:45:14 +00:00
|
|
|
if host == "" {
|
|
|
|
return addr, errUnspecifiedHost
|
|
|
|
}
|
2024-05-21 20:38:53 +00:00
|
|
|
|
|
|
|
return netip.ParseAddr(host)
|
|
|
|
}
|