Skip to content

Commit

Permalink
net: change GetIPAddresses() to use netip.ParseAddr() instead of type…
Browse files Browse the repository at this point in the history
… cast

Signed-off-by: Alejandro Mery <[email protected]>
  • Loading branch information
amery committed Jan 31, 2023
1 parent 41b437c commit 955aa80
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions net.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,14 @@ func GetIPAddresses(ifaces ...string) ([]netip.Addr, error) {
return out, err
}

for _, addr := range addrs {
var s []byte

switch v := addr.(type) {
case *net.IPAddr:
s = v.IP
case *net.IPNet:
s = v.IP
for _, netAddr := range addrs {
addr, err := netip.ParseAddr(netAddr.String())
if err != nil {
return out, err
}

if ip, ok := netip.AddrFromSlice(s); ok {
out = append(out, ip)
if addr.IsValid() {
out = append(out, addr)
}
}
}
Expand Down

0 comments on commit 955aa80

Please sign in to comment.