Simplify MappedAddress IP slice initialization

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
This commit is contained in:
Xiaobo Liu
2025-05-26 18:42:34 +08:00
parent d07109b467
commit aa89af8123

12
addr.go
View File

@@ -84,15 +84,13 @@ func (a *MappedAddress) GetFromAs(m *Message, t AttrType) error {
}
// Ensuring len(a.IP) == ipLen and reusing a.IP.
if len(a.IP) < ipLen {
a.IP = a.IP[:cap(a.IP)]
for len(a.IP) < ipLen {
a.IP = append(a.IP, 0)
a.IP = make(net.IP, ipLen)
} else {
a.IP = a.IP[:ipLen]
for i := range a.IP {
a.IP[i] = 0
}
}
a.IP = a.IP[:ipLen]
for i := range a.IP {
a.IP[i] = 0
}
a.Port = int(bin.Uint16(value[2:4]))
copy(a.IP, value[4:])