From 9fd7186f21f6f8b258fa2db09a20f33ca5b53ca7 Mon Sep 17 00:00:00 2001 From: Emir Aganovic Date: Thu, 21 Nov 2024 22:49:50 +0100 Subject: [PATCH] fix: correct IPV6 detection --- sip/utils.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sip/utils.go b/sip/utils.go index ce2a473..a421a37 100644 --- a/sip/utils.go +++ b/sip/utils.go @@ -288,6 +288,7 @@ func resolveInterfaceIp(iface net.Interface, network string, targetIP *net.IPNet if err != nil { return nil, err } + for _, addr := range addrs { var ip net.IP ipNet, ok := addr.(*net.IPNet) @@ -312,14 +313,15 @@ func resolveInterfaceIp(iface net.Interface, network string, targetIP *net.IPNet switch network { case "ip4": - ip = ip.To4() + if ip.To4() == nil { + continue + } case "ip6": - ip = ip.To16() - } - - if ip == nil { - continue // not an ipv4 address + // IP is v6 only if this returns nil + if ip.To4() != nil { + continue + } } return ip, nil