mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-05 14:57:49 +00:00
wgengine/magicsock: stringify [IPv6]:port normally in AddrSet.String
This commit is contained in:
parent
3c3ea8bc8a
commit
d321190578
@ -1629,13 +1629,14 @@ func (a *AddrSet) String() string {
|
||||
buf := new(strings.Builder)
|
||||
buf.WriteByte('[')
|
||||
if a.roamAddr != nil {
|
||||
fmt.Fprintf(buf, "roam:%s:%d", a.roamAddr.IP, a.roamAddr.Port)
|
||||
buf.WriteString("roam:")
|
||||
sbPrintAddr(buf, *a.roamAddr)
|
||||
}
|
||||
for i, addr := range a.addrs {
|
||||
if i > 0 || a.roamAddr != nil {
|
||||
buf.WriteString(", ")
|
||||
}
|
||||
fmt.Fprintf(buf, "%s:%d", addr.IP, addr.Port)
|
||||
sbPrintAddr(buf, addr)
|
||||
if a.curAddr == i {
|
||||
buf.WriteByte('*')
|
||||
}
|
||||
@ -1845,3 +1846,15 @@ func ip4or6(ip net.IP) net.IP {
|
||||
}
|
||||
return ip
|
||||
}
|
||||
|
||||
func sbPrintAddr(sb *strings.Builder, a net.UDPAddr) {
|
||||
is6 := a.IP.To4() == nil
|
||||
if is6 {
|
||||
sb.WriteByte('[')
|
||||
}
|
||||
fmt.Fprintf(sb, "%s", a.IP)
|
||||
if is6 {
|
||||
sb.WriteByte(']')
|
||||
}
|
||||
fmt.Fprintf(sb, ":%d", a.Port)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user