From ced944ffc2390b6526863444d13596478bc8611f Mon Sep 17 00:00:00 2001 From: xtaci Date: Tue, 23 Apr 2019 20:09:51 +0800 Subject: [PATCH] revert back the network type detection --- sess.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sess.go b/sess.go index d185a4a..ebe2a90 100644 --- a/sess.go +++ b/sess.go @@ -1038,7 +1038,17 @@ func Dial(raddr string) (net.Conn, error) { return DialWithOptions(raddr, nil, 0 // DialWithOptions connects to the remote address "raddr" on the network "udp" with packet encryption func DialWithOptions(raddr string, block BlockCrypt, dataShards, parityShards int) (*UDPSession, error) { - conn, err := net.ListenUDP("udp", nil) + // network type detection + udpaddr, err := net.ResolveUDPAddr("udp", raddr) + if err != nil { + return nil, errors.Wrap(err, "net.ResolveUDPAddr") + } + network := "udp4" + if udpaddr.IP.To4() == nil { + network = "udp" + } + + conn, err := net.ListenUDP(network, nil) if err != nil { return nil, errors.Wrap(err, "net.DialUDP") }