Skip to content

Commit

Permalink
Add netiputil.AddrPortFromNet()
Browse files Browse the repository at this point in the history
Co-authored-by: Cory Snider <csnider@mirantis.com>
Signed-off-by: Rob Murray <rob.murray@docker.com>
  • Loading branch information
robmry and corhere committed Apr 15, 2024
1 parent 8d5d655 commit f07644e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libnetwork/internal/netiputil/netiputil.go
Expand Up @@ -51,3 +51,11 @@ func SubnetRange(network, subnet netip.Prefix) (start, end uint64) {
end = start + (1 << uint64(subnet.Addr().BitLen()-subnet.Bits())) - 1
return start, end
}

// AddrPortFromNet converts a net.Addr into a netip.AddrPort.
func AddrPortFromNet(addr net.Addr) netip.AddrPort {
if a, ok := addr.(interface{ AddrPort() netip.AddrPort }); ok {
return a.AddrPort()
}
return netip.AddrPort{}
}

0 comments on commit f07644e

Please sign in to comment.