udp: add UDPAddrFromAddrPort from Big Go implementation (#49)

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
Ron Evans
2026-04-16 16:07:07 +01:00
committed by GitHub
parent 35e809e0e5
commit 90d59cb488
+11
View File
@@ -113,6 +113,17 @@ func ResolveUDPAddr(network, address string) (*UDPAddr, error) {
return &UDPAddr{IP: ip.AsSlice(), Port: port}, nil
}
// UDPAddrFromAddrPort returns addr as a [UDPAddr]. If addr.IsValid() is false,
// then the returned UDPAddr will contain a nil IP field, indicating an
// address family-agnostic unspecified address.
func UDPAddrFromAddrPort(addr netip.AddrPort) *UDPAddr {
return &UDPAddr{
IP: addr.Addr().AsSlice(),
Zone: addr.Addr().Zone(),
Port: int(addr.Port()),
}
}
// UDPConn is the implementation of the Conn and PacketConn interfaces
// for UDP network connections.
type UDPConn struct {