Skip to content

Commit

Permalink
fix: correct IPV6 detection
Browse files Browse the repository at this point in the history
  • Loading branch information
emiago committed Nov 21, 2024
1 parent 5fcba72 commit 9fd7186
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions sip/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 9fd7186

Please sign in to comment.