You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
naza/pkg/nazanet/helper.go

28 lines
600 B
Go

// Copyright 2020, Chef. All rights reserved.
// https://github.com/q191201771/naza
//
// Use of this source code is governed by a MIT-style license
// that can be found in the License file.
//
// Author: Chef (191201771@qq.com)
package nazanet
import (
"fmt"
"net"
)
func listenUdpWithPort(port uint16) (*net.UDPConn, error) {
addr := fmt.Sprintf(":%d", port)
return listenUdpWithAddr(addr)
}
func listenUdpWithAddr(addr string) (*net.UDPConn, error) {
udpAddr, err := net.ResolveUDPAddr(udpNetwork, addr)
if err != nil {
return nil, err
}
return net.ListenUDP(udpNetwork, udpAddr)
}