Skip to content

Commit

Permalink
Refactor UDP
Browse files Browse the repository at this point in the history
Signed-off-by: Max Riveiro <[email protected]>
  • Loading branch information
kavu committed Jan 14, 2017
1 parent b9e3ac0 commit 5489088
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
14 changes: 14 additions & 0 deletions udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}

0 comments on commit 5489088

Please sign in to comment.