From f07644e17e151307d4fe302ee3b292d866b56de9 Mon Sep 17 00:00:00 2001 From: Rob Murray Date: Mon, 18 Mar 2024 10:14:50 +0000 Subject: [PATCH] Add netiputil.AddrPortFromNet() Co-authored-by: Cory Snider Signed-off-by: Rob Murray --- libnetwork/internal/netiputil/netiputil.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libnetwork/internal/netiputil/netiputil.go b/libnetwork/internal/netiputil/netiputil.go index 76cb5922a3..7c907569f5 100644 --- a/libnetwork/internal/netiputil/netiputil.go +++ b/libnetwork/internal/netiputil/netiputil.go @@ -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{} +}