Skip to content

Commit 764113b

Browse files
committed
ipv6 support
1 parent b6609e0 commit 764113b

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

internal/list/list.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,13 @@ func getCurrentDeviceRemoteIP() (net.IP, error) {
196196
return nil, err
197197
}
198198

199-
remoteIP := net.ParseIP(string(b)).To4()
199+
var remoteIP net.IP
200+
ipAddr := string(b)
201+
if strings.Contains(ipAddr, ":") {
202+
remoteIP = net.ParseIP(ipAddr).To16()
203+
} else {
204+
remoteIP = net.ParseIP(ipAddr).To4()
205+
}
200206
if remoteIP == nil {
201207
return nil, fmt.Errorf("failed to get resolve ip %q as ipv4", b)
202208
}

internal/resolve/lookup.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,16 @@ func AddrByHostName(hostname string) (*Record, error) {
7878
return nil, fmt.Errorf("no addresses found for hostname %q", hostname)
7979
}
8080

81-
ipv4 := ipAddrs[0].To4()
82-
if ipv4 == nil {
83-
return &Record{
84-
Hostname: hostname,
85-
IP: *ipAddrs[0],
86-
}, nil
81+
var ipAddr net.IP
82+
if strings.Contains(string(*ipAddrs[0]), ":") {
83+
ipAddr = ipAddrs[0].To16()
84+
} else {
85+
ipAddr = ipAddrs[0].To4()
8786
}
8887

8988
return &Record{
9089
Hostname: hostname,
91-
IP: ipv4,
90+
IP: ipAddr,
9291
}, err
9392
}
9493

0 commit comments

Comments
 (0)