func (r *RelayAddressGeneratorPortRange) AllocatePacketConn(network string, requestedPort int) (net.PacketConn, net.Addr, error) {
	if requestedPort != 0 {
		conn, err := r.Net.ListenPacket(network, fmt.Sprintf("%s:%d", r.Address, requestedPort))
		if err != nil {
			return nil, nil, err
		}
		relayAddr := conn.LocalAddr().(*net.UDPAddr)
		relayAddr.IP = r.RelayAddress
		return conn, relayAddr, nil
	}
	for try := 0; try < r.MaxRetries; try++ {
		port := r.MinPort + uint16(r.Rand.Intn(int((r.MaxPort+1)-r.MinPort)))
		conn, err := r.Net.ListenPacket(network, fmt.Sprintf("%s:%d", r.Address, port))
		if err != nil {
			continue
		}
		relayAddr := conn.LocalAddr().(*net.UDPAddr)
		relayAddr.IP = r.RelayAddress
		return conn, relayAddr, nil
	}
	return nil, nil, errMaxRetriesExceeded
}
AllocatePacketConn generates a new PacketConn to receive traffic on and the IP/Port to populate the allocation response with
package turn
import (
	"fmt"
	"net"
	"github.com/pion/randutil"
	"github.com/pion/transport/vnet"
)
type RelayAddressGeneratorPortRange struct {
	RelayAddress net.IP
	MinPort uint16
	MaxPort uint16
	MaxRetries int
	Rand randutil.MathRandomGenerator
	Address string
	Net *vnet.Net
}
func (r *RelayAddressGeneratorPortRange) Validate() error {
	if r.Net == nil {
		r.Net = vnet.NewNet(nil)
	}
	if r.Rand == nil {
		r.Rand = randutil.NewMathRandomGenerator()
	}
	if r.MaxRetries == 0 {
		r.MaxRetries = 10
	}
	switch {
	case r.MinPort == 0:
		return errMinPortNotZero
	case r.MaxPort == 0:
		return errMaxPortNotZero
	case r.RelayAddress == nil:
		return errRelayAddressInvalid
	case r.Address == "":
		return errListeningAddressInvalid
	default:
		return nil
	}
}