Skip to content

Commit 90d59cb

Browse files
authored
udp: add UDPAddrFromAddrPort from Big Go implementation (#49)
Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 35e809e commit 90d59cb

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

udpsock.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ func ResolveUDPAddr(network, address string) (*UDPAddr, error) {
113113
return &UDPAddr{IP: ip.AsSlice(), Port: port}, nil
114114
}
115115

116+
// UDPAddrFromAddrPort returns addr as a [UDPAddr]. If addr.IsValid() is false,
117+
// then the returned UDPAddr will contain a nil IP field, indicating an
118+
// address family-agnostic unspecified address.
119+
func UDPAddrFromAddrPort(addr netip.AddrPort) *UDPAddr {
120+
return &UDPAddr{
121+
IP: addr.Addr().AsSlice(),
122+
Zone: addr.Addr().Zone(),
123+
Port: int(addr.Port()),
124+
}
125+
}
126+
116127
// UDPConn is the implementation of the Conn and PacketConn interfaces
117128
// for UDP network connections.
118129
type UDPConn struct {

0 commit comments

Comments
 (0)