From 548908864c5b77fc686e71a3642ef561d2258eb8 Mon Sep 17 00:00:00 2001 From: Max Riveiro Date: Thu, 12 Jan 2017 19:09:32 +0300 Subject: [PATCH] Refactor UDP Signed-off-by: Max Riveiro --- tcp.go | 5 +++++ udp.go | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/tcp.go b/tcp.go index 2879a33..6594e32 100644 --- a/tcp.go +++ b/tcp.go @@ -138,3 +138,8 @@ func NewReusablePortListener(proto, addr string) (l net.Listener, err error) { return l, err } + +// Listen function is an alias for NewReusablePortListener. +func Listen(proto, addr string) (l net.Listener, err error) { + return NewReusablePortListener(proto, addr) +} diff --git a/udp.go b/udp.go index 622a3f9..79b98c2 100644 --- a/udp.go +++ b/udp.go @@ -46,6 +46,15 @@ func getUDPSockaddr(proto, addr string) (sa syscall.Sockaddr, soType int, err er copy(sa.Addr[:], udp.IP) // copy all bytes of slice to array } + if udp.Zone != "" { + iface, err := net.InterfaceByName(udp.Zone) + if err != nil { + return nil, -1, err + } + + sa.ZoneId = uint32(iface.Index) + } + return sa, syscall.AF_INET6, nil } @@ -124,3 +133,8 @@ func NewReusablePortPacketConn(proto, addr string) (l net.PacketConn, err error) return l, err } + +// ListenPacket is an alias for NewReusablePortPacketConn. +func ListenPacket(proto, addr string) (l net.PacketConn, err error) { + return NewReusablePortPacketConn(proto, addr) +}