Skip to content

Commit

Permalink
wgcfg: fix bug preventing IPv6 addresses from working
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
bradfitz authored and crawshaw committed Mar 30, 2020
1 parent 3c7ec55 commit 14b87e5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions wgcfg/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package wgcfg

import (
"errors"
"fmt"
"net"
"strings"
Expand Down Expand Up @@ -46,17 +45,16 @@ func (conf *Config) ToUAPI() (string, error) {
}
var ip net.IP
for _, iterip := range ips {
iterip = iterip.To4()
if iterip != nil {
ip = iterip
if ip4 := iterip.To4(); ip4 != nil {
ip = ip4
break
}
if ip == nil {
ip = iterip
}
}
if ip == nil {
return "", errors.New("Unable to resolve IP address of endpoint")
return "", fmt.Errorf("unable to resolve IP address of endpoint %q (%v)", ep.Host, ips)
}
resolvedEndpoint := Endpoint{ip.String(), ep.Port}
reps = append(reps, resolvedEndpoint.String())
Expand Down

0 comments on commit 14b87e5

Please sign in to comment.