Commit 5d2cdd27 by Iwasaki Yudai

Show IPv6 addresses with `[` and `]`

So that users can open IPv6 URLs on web browsers.
1 parent a0f6e8d0
Showing with 5 additions and 2 deletions
...@@ -221,10 +221,13 @@ func listAddresses() (addresses []string) { ...@@ -221,10 +221,13 @@ func listAddresses() (addresses []string) {
for _, ifAddr := range ifAddrs { for _, ifAddr := range ifAddrs {
switch v := ifAddr.(type) { switch v := ifAddr.(type) {
case *net.IPNet: case *net.IPNet:
if v.IP.To4() == nil {
addresses = append(addresses, "["+v.IP.String()+"]")
} else {
addresses = append(addresses, v.IP.String()) addresses = append(addresses, v.IP.String())
}
case *net.IPAddr: case *net.IPAddr:
addresses = append(addresses, v.IP.To16().String()) addresses = append(addresses, v.IP.String())
addresses = append(addresses, v.IP.To4().String())
} }
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!