Vincent Batts
d5812860fc
https://github.com/WireGuard/wireguard-windows/pull/10 don't appear to be of interest, and now need big rebasing. Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
35 lines
582 B
Go
35 lines
582 B
Go
// +build !windows
|
|
|
|
/* SPDX-License-Identifier: MIT
|
|
*
|
|
* Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
|
|
*/
|
|
|
|
package conf
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
)
|
|
|
|
func resolveHostname(name string) (resolvedIPString string, err error) {
|
|
ips, err := net.LookupIP(name)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
var ip net.IP
|
|
for _, iterip := range ips {
|
|
if ip4 := iterip.To4(); ip4 != nil {
|
|
ip = ip4
|
|
break
|
|
}
|
|
if ip == nil {
|
|
ip = iterip
|
|
}
|
|
}
|
|
if ip == nil {
|
|
return "", fmt.Errorf("unable to resolve IP address of endpoint %q (%v)", name, ips)
|
|
}
|
|
|
|
return ip.String(), nil
|
|
}
|