libnetwork: resolveAddr: add GoDoc

Describe the behavior of this function, as it was not documented.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-08-27 19:07:11 +02:00
parent 5b53ddfcdd
commit b75e831567
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -84,15 +84,22 @@ func getBindAddr(ifaceName string) (string, error) {
return "", fmt.Errorf("failed to get bind address")
}
// resolveAddr resolves the given address, which can be one of, and
// parsed in the following order or priority:
//
// - a well-formed IP-address
// - a hostname
// - an interface-name
func resolveAddr(addrOrInterface string) (string, error) {
// Try and see if this is a valid IP address
if net.ParseIP(addrOrInterface) != nil {
return addrOrInterface, nil
}
// If not a valid IP address, it could be a hostname.
addr, err := net.ResolveIPAddr("ip", addrOrInterface)
if err != nil {
// If not a valid IP address, it should be a valid interface
// If hostname lookup failed, try to look for an interface with the given name.
return getBindAddr(addrOrInterface)
}
return addr.String(), nil