wgengine/magicsock: stringify [IPv6]:port normally in AddrSet.String

pull/216/head
Brad Fitzpatrick 5 years ago
parent 3c3ea8bc8a
commit d321190578

@ -1629,13 +1629,14 @@ func (a *AddrSet) String() string {
buf := new(strings.Builder) buf := new(strings.Builder)
buf.WriteByte('[') buf.WriteByte('[')
if a.roamAddr != nil { 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 { for i, addr := range a.addrs {
if i > 0 || a.roamAddr != nil { if i > 0 || a.roamAddr != nil {
buf.WriteString(", ") buf.WriteString(", ")
} }
fmt.Fprintf(buf, "%s:%d", addr.IP, addr.Port) sbPrintAddr(buf, addr)
if a.curAddr == i { if a.curAddr == i {
buf.WriteByte('*') buf.WriteByte('*')
} }
@ -1845,3 +1846,15 @@ func ip4or6(ip net.IP) net.IP {
} }
return 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…
Cancel
Save