1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-08 05:47:07 +09:00

GO-4807 p2p: iface ip conversion fix

This commit is contained in:
Roman Khafizianov 2025-03-24 20:08:53 +01:00
parent 520223346d
commit e2c1bf41c7
No known key found for this signature in database
GPG key ID: F07A7D55A2684852
2 changed files with 22 additions and 8 deletions

View file

@ -53,6 +53,17 @@ func WrapInterfaces(ifaces []net.Interface) []NetInterfaceWithAddrCache {
return m
}
func AddrToIP(addr net.Addr) (net.IP, bool) {
switch ip := addr.(type) {
case *net.IPNet:
return ip.IP, true
case *net.IPAddr:
return ip.IP, true
default:
return nil, false
}
}
// GetAddr returns ipv4 only addresses for interface or cached one if set
func (i NetInterfaceWithAddrCache) GetAddr() []net.Addr {
if i.cachedAddrs != nil {
@ -67,8 +78,8 @@ func (i NetInterfaceWithAddrCache) GetAddr() []net.Addr {
}
// filter-out ipv6
i.cachedAddrs = slice.Filter(i.cachedAddrs, func(addr net.Addr) bool {
if ip, ok := addr.(*net.IPNet); ok {
if ip.IP.To4() == nil {
if ip, ok := AddrToIP(addr); ok {
if ip.To4() == nil {
return false
}
}