Show IPv6 addresses with `[` and `]`

So that users can open IPv6 URLs on web browsers.
This commit is contained in:
Iwasaki Yudai 2015-08-24 05:05:58 +09:00
parent a0f6e8d051
commit 5d2cdd2768
1 changed files with 6 additions and 3 deletions

View File

@ -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:
addresses = append(addresses, v.IP.String()) if v.IP.To4() == nil {
addresses = append(addresses, "["+v.IP.String()+"]")
} else {
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())
} }
} }
} }