aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/conf/writer.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-05-07 09:27:01 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-07 09:34:38 +0200
commit0a6708f865fc6e8c89e0fe9ecf75aea4b617b7ec (patch)
tree54e89b2824e1f936abaa134663117087bbe13576 /conf/writer.go
parentinstaller: delete config file with custom action (diff)
downloadwireguard-windows-0a6708f865fc6e8c89e0fe9ecf75aea4b617b7ec.tar.xz
wireguard-windows-0a6708f865fc6e8c89e0fe9ecf75aea4b617b7ec.zip
conf: retry DNS resoluion when no internet present
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'conf/writer.go')
-rw-r--r--conf/writer.go27
1 files changed, 6 insertions, 21 deletions
diff --git a/conf/writer.go b/conf/writer.go
index 642d14a7..d9504178 100644
--- a/conf/writer.go
+++ b/conf/writer.go
@@ -6,9 +6,7 @@
package conf
import (
- "errors"
"fmt"
- "net"
"strings"
)
@@ -70,7 +68,7 @@ func (conf *Config) ToWgQuick() string {
return output.String()
}
-func (conf *Config) ToUAPI() (string, error) {
+func (conf *Config) ToUAPI() (uapi string, dnsErr error) {
var output strings.Builder
output.WriteString(fmt.Sprintf("private_key=%s\n", conf.Interface.PrivateKey.HexString()))
@@ -90,25 +88,12 @@ func (conf *Config) ToUAPI() (string, error) {
}
if !peer.Endpoint.IsEmpty() {
- ips, err := net.LookupIP(peer.Endpoint.Host)
- if err != nil {
- return "", err
+ var resolvedIp string
+ resolvedIp, dnsErr = resolveHostname(peer.Endpoint.Host)
+ if dnsErr != nil {
+ return
}
- var ip net.IP
- for _, iterip := range ips {
- iterip = iterip.To4()
- if iterip != nil {
- ip = iterip
- break
- }
- if ip == nil {
- ip = iterip
- }
- }
- if ip == nil {
- return "", errors.New("Unable to resolve IP address of endpoint")
- }
- resolvedEndpoint := Endpoint{ip.String(), peer.Endpoint.Port}
+ resolvedEndpoint := Endpoint{resolvedIp, peer.Endpoint.Port}
output.WriteString(fmt.Sprintf("endpoint=%s\n", resolvedEndpoint.String()))
}