From 52b887bc87f6d54cdd9a0ef5da74a9e9f1c4d662 Mon Sep 17 00:00:00 2001 From: wtklcx Date: Mon, 19 Oct 2026 19:52:34 +0800 Subject: [PATCH 1/3] Fix prevent panic on empty ips slice in SOCKS5 handshake --- phantomtcp/proxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phantomtcp/proxy.go b/phantomtcp/proxy.go index e14f1f5..e8df4da 100755 --- a/phantomtcp/proxy.go +++ b/phantomtcp/proxy.go @@ -576,7 +576,7 @@ func (outbound *Outbound) ProxyHandshake(conn net.Conn, synpacket *ConnectionInf if outbound.DNS != "" { _, ips := outbound.NSLookup(host, 0) - if ips != nil { + if len(ips) > 0 { ip := ips[rand.Intn(len(ips))] ip4 := ip.To4() if ip4 != nil { From 406b5a16263c06d9a2ef2dc3013ce11cee362ce2 Mon Sep 17 00:00:00 2001 From: wtklcx Date: Mon, 19 Oct 2026 19:53:05 +0800 Subject: [PATCH 2/3] Fix broken auto dual-stack and DNS type handling introduced by #fd3b45b --- phantomtcp/dns.go | 14 ++++++++++++++ phantomtcp/tcp_root.go | 16 ++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/phantomtcp/dns.go b/phantomtcp/dns.go index 3300c97..065e62a 100755 --- a/phantomtcp/dns.go +++ b/phantomtcp/dns.go @@ -1129,10 +1129,24 @@ func (outbound *Outbound) NSLookup(name string, qtype uint16) (uint32, []net.IP) hint := outbound.Hint if qtype == 0 { + // Honor the DNS "type=A/AAAA" option on the outbound resolution + // path as well. It was previously respected only by NSRequest (the + // DNS server path), so outbounds still issued AAAA queries under + // type=A and could adopt poisoned answers injected into DNS + // responses (e.g. 2a03:2880:...:face:b00c...). + var typeOption string + if u, err := url.Parse(outbound.DNS); err == nil && u.RawQuery != "" { + typeOption = ParseOptions(u.RawQuery).Type + } + ipv4 := hint&HINT_IPV4 != 0 ipv6 := hint&HINT_IPV6 != 0 if (outbound.Protocol == NAT64) { qtype = 1 + } else if typeOption == "A" { + qtype = 1 + } else if typeOption == "AAAA" { + qtype = 28 } else if ipv4 == ipv6 { ch := make(chan []net.IP, 1) var index uint32 diff --git a/phantomtcp/tcp_root.go b/phantomtcp/tcp_root.go index 034ea24..b471657 100644 --- a/phantomtcp/tcp_root.go +++ b/phantomtcp/tcp_root.go @@ -171,10 +171,16 @@ func (outbound *Outbound) dial(host string, port int, b []byte, offset int, leng } } - conn, err = net.DialTCP("tcp", laddr, raddr) - if err == nil { - conn, err = outbound.ProxyHandshake(conn, nil, host, port) + // net.DialTCP returns a typed nil ((*net.TCPConn)(nil)) inside + // a non-nil net.Conn interface on failure, which defeats the + // "conn != nil" guard below and panics in conn.Close(). Assign + // the connection only when the dial succeeded. + tcpConn, dialErr := net.DialTCP("tcp", laddr, raddr) + if dialErr != nil { + return nil, nil, dialErr } + conn = tcpConn + conn, err = outbound.ProxyHandshake(conn, nil, host, port) if err == nil && b != nil { if length > 0 { @@ -192,7 +198,9 @@ func (outbound *Outbound) dial(host string, port int, b []byte, offset int, leng } if err != nil { - conn.Close() + if conn != nil { + conn.Close() + } return nil, nil, err } From 29c18655b2f89315ccb38d14e2606e660c150a1b Mon Sep 17 00:00:00 2001 From: wtklcx Date: Thu, 22 Oct 2026 21:15:29 +0800 Subject: [PATCH 3/3] Add order-sensitive IPv4/IPv6 preference with cross-family fallback --- phantomtcp/dns.go | 241 +++++++++++++++++++++++++++++++++-------- phantomtcp/phantom.go | 38 +++++-- phantomtcp/proxy.go | 3 +- phantomtcp/tcp.go | 60 +++++++++- phantomtcp/tcp_root.go | 4 +- phantomtcp/tcp_user.go | 4 +- phantomtcp/udp.go | 7 +- 7 files changed, 293 insertions(+), 64 deletions(-) diff --git a/phantomtcp/dns.go b/phantomtcp/dns.go index 065e62a..ce57cc4 100755 --- a/phantomtcp/dns.go +++ b/phantomtcp/dns.go @@ -8,7 +8,6 @@ import ( "fmt" "io" "log" - "math/rand" "net" "net/http" "net/url" @@ -293,7 +292,7 @@ func HTTPSlookup(request []byte, u *url.URL, servername string) ([]byte, error) Timeout: time.Duration(5 * time.Second), } client.Transport = &http.Transport{ - TLSClientConfig: tlsConfig, + TLSClientConfig: tlsConfig, ForceAttemptHTTP2: true, } @@ -1005,8 +1004,8 @@ func PackRequest(name string, qtype uint16, id uint16, ecs string, qtype2 uint16 } else { binary.BigEndian.PutUint16(Request[4:], 1) //QDCount } - binary.BigEndian.PutUint16(Request[6:], 0) //ANCount - binary.BigEndian.PutUint16(Request[8:], 0) //NSCount + binary.BigEndian.PutUint16(Request[6:], 0) //ANCount + binary.BigEndian.PutUint16(Request[8:], 0) //NSCount if ecs != "" { binary.BigEndian.PutUint16(Request[10:], 1) //ARCount } else { @@ -1125,6 +1124,119 @@ func GetDNSLie(index int) (string, *Outbound) { return lie.Name, lie.Interface } +// dnsPlan is the address-family query decision for an outbound when the +// caller does not mandate a qtype. +type dnsPlan struct { + // conflict marks a single-family DNS type option contradicted by an + // explicit hint of the opposite family: no usable family remains and + // NSLookup refuses to resolve. + conflict bool + // qtype is the query family of a single-family plan: 1 (A) or 28 + // (AAAA). 0 means both families are queried. + qtype int + // v4first is the preferred family of a dual-family plan: true + // queries A first, false queries AAAA first. + v4first bool +} + +// planDNSQuery is the single source of truth for which address families an +// outbound queries, and in which order, when the caller does not mandate a +// qtype (NSLookup with qtype==0): NAT64 forces A, then the DNS "type" +// option, then an explicit hint, then the device probe / dual-family +// fallback recorded in Hint at startup. CreateOutbounds previews the +// plan into the QueryOrder field (describeDNSQuery) so the outbound +// dump printed at profile load shows the effective query order +// before the program serves any request. +func (outbound *Outbound) planDNSQuery() dnsPlan { + var typeOption string + if u, err := url.Parse(outbound.DNS); err == nil && u.RawQuery != "" { + typeOption = ParseOptions(u.RawQuery).Type + } + + hint := outbound.Hint + ipv4 := hint&HINT_IPV4 != 0 + ipv6 := hint&HINT_IPV6 != 0 + v4first := hint&HINT_V4FIRST != 0 + + if outbound.Protocol == NAT64 { + // NAT64 always queries A and synthesizes AAAA from the + // answers; type/hint/device must not interfere. + return dnsPlan{qtype: 1} + } else if typeOption == "A" || typeOption == "AAAA" { + // A single-family type option sets the query scope and the + // connection follows it. An explicit hint of the opposite + // single family is a conflict: no usable family remains; a + // hint of the same family or a dual-family hint is not. + if outbound.HasIPHint && ipv4 != ipv6 { + if typeOption == "A" && ipv6 || typeOption == "AAAA" && ipv4 { + return dnsPlan{conflict: true} + } + } + if typeOption == "A" { + return dnsPlan{qtype: 1} + } + return dnsPlan{qtype: 28} + } else if (typeOption == "A,AAAA" || typeOption == "AAAA,A") && outbound.HasIPHint && ipv4 != ipv6 { + // Dual-family type narrowed by an explicit single-family + // hint: query that family only (exclusive, no fallback). + if ipv4 { + return dnsPlan{qtype: 1} + } + return dnsPlan{qtype: 28} + } else if typeOption == "A,AAAA" || typeOption == "AAAA,A" { + // Dual-family type without a narrowing hint: dual-stack with + // fallback. An explicit dual-family hint keeps its own order; + // otherwise the type order decides. + if !outbound.HasIPHint { + v4first = typeOption == "A,AAAA" + } + return dnsPlan{v4first: v4first} + } else if ipv4 == ipv6 { + // No type option: hint, device probe or the no-hint + // dual-family fallback recorded in Hint. + return dnsPlan{v4first: v4first} + } else if ipv6 { + return dnsPlan{qtype: 28} + } + return dnsPlan{qtype: 1} +} + +// describeDNSQuery renders the startup preview of an outbound's DNS +// decision: the query family order, one of "A", "AAAA", "A,AAAA", +// "AAAA,A", or "none" when no query can be made (no DNS server, +// invalid URL, unsupported scheme, or a type-vs-hint conflict). +// CreateOutbounds stores it in the QueryOrder field so the &{...} +// outbound dump printed at profile load shows the plan next to the +// DNS URL. +func (outbound *Outbound) describeDNSQuery() string { + if outbound.DNS == "" { + return "none" + } + u, err := url.Parse(outbound.DNS) + if err != nil || u.Host == "" { + return "none" + } + switch u.Scheme { + case "udp", "tcp", "tls", "https", "tfo": + default: + return "none" + } + + plan := outbound.planDNSQuery() + if plan.conflict { + return "none" + } + switch { + case plan.qtype == 1: + return "A" + case plan.qtype == 28: + return "AAAA" + case plan.v4first: + return "A,AAAA" + } + return "AAAA,A" +} + func (outbound *Outbound) NSLookup(name string, qtype uint16) (uint32, []net.IP) { hint := outbound.Hint @@ -1134,37 +1246,72 @@ func (outbound *Outbound) NSLookup(name string, qtype uint16) (uint32, []net.IP) // DNS server path), so outbounds still issued AAAA queries under // type=A and could adopt poisoned answers injected into DNS // responses (e.g. 2a03:2880:...:face:b00c...). + // The option also accepts both families as "type=A,AAAA" or + // "type=AAAA,A". The type option defines the query scope; + // the connection strategy still follows an explicit hint + // (hint order wins over type order, and a single-family + // hint narrows a dual-family type); only when no hint is + // given does the type order decide the preference. + // The family decision lives in planDNSQuery so the startup + // preview (describeDNSQuery) always matches the runtime. var typeOption string if u, err := url.Parse(outbound.DNS); err == nil && u.RawQuery != "" { typeOption = ParseOptions(u.RawQuery).Type } - ipv4 := hint&HINT_IPV4 != 0 - ipv6 := hint&HINT_IPV6 != 0 - if (outbound.Protocol == NAT64) { - qtype = 1 - } else if typeOption == "A" { - qtype = 1 - } else if typeOption == "AAAA" { - qtype = 28 - } else if ipv4 == ipv6 { + plan := outbound.planDNSQuery() + if plan.conflict { + // An explicit hint of the opposite single family is a + // conflict: log a warning and refuse to connect. + if typeOption == "A" { + logPrintln(1, "Conflict: DNS type=A vs hint ipv6, no usable family for", name) + } else { + logPrintln(1, "Conflict: DNS type=AAAA vs hint ipv4, no usable family for", name) + } + return 0, nil + } + if (typeOption == "A" || typeOption == "AAAA") && outbound.HasIPHint && + hint&HINT_IPV4 != 0 && hint&HINT_IPV6 != 0 { + // A dual-family hint only logs that the other family + // goes unused. + queryFamily, ignoredFamily, dnsType := "ipv4", "ipv6", "A" + if typeOption == "AAAA" { + queryFamily, ignoredFamily, dnsType = "ipv6", "ipv4", "AAAA" + } + // Show the hinted families in the order the profile lists + // them: CreateOutbounds sets HINT_V4FIRST when the hint string + // named ipv4 before ipv6, so this is the configured order. + hintFamilies := "ipv6,ipv4" + if hint&HINT_V4FIRST != 0 { + hintFamilies = "ipv4,ipv6" + } + // DNS: ipv4-only. query=A, hint=ipv6,ipv4 -> ignoring ipv6 for www.test + logPrintln(1, "DNS: "+queryFamily+"-only. query="+dnsType+", hint="+hintFamilies+" -> ignoring "+ignoredFamily+" for "+name) + } + + if plan.qtype == 0 { ch := make(chan []net.IP, 1) var index uint32 + first, second := 28, 1 // preferred family queried first (IPv6 by default) + if plan.v4first { + first, second = 1, 28 + } go func() { - _, addresses := outbound.NSLookup(name, 1) + _, addresses := outbound.NSLookup(name, uint16(second)) ch <- addresses }() - index, addresses := outbound.NSLookup(name, 28) - if len(addresses) != 0 { - return index, addresses + index, pref_addrs := outbound.NSLookup(name, uint16(first)) + rest_addrs := <-ch + var addresses []net.IP + if len(pref_addrs) != 0 || len(rest_addrs) != 0 { + addresses = make([]net.IP, 0, len(pref_addrs)+len(rest_addrs)) + addresses = append(addresses, pref_addrs...) + addresses = append(addresses, rest_addrs...) } - return index, <-ch - } else if ipv6 { - qtype = 28 - } else { - qtype = 1 + return index, addresses } + qtype = uint16(plan.qtype) } records := LoadDNSCache(name) @@ -1460,37 +1607,37 @@ func NSRequest(request []byte, cache bool) (uint32, []byte) { default: return 0, response } -/* - if UseVaddr && (records.Index == 0) { - records.Index = AddDNSLie(name, outbound) + /* + if UseVaddr && (records.Index == 0) { + records.Index = AddDNSLie(name, outbound) - if options.Output != "" { - f, err := os.OpenFile(options.Output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) - if err != nil { - logPrintln(1, options.Output, err) - } - defer f.Close() + if options.Output != "" { + f, err := os.OpenFile(options.Output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) + if err != nil { + logPrintln(1, options.Output, err) + } + defer f.Close() - if _qtype == 1 { - if records.IPv4Hint.Addresses != nil { - f.WriteString(name + "=") - for _, ip := range records.IPv4Hint.Addresses { - f.WriteString(ip.String()) + if _qtype == 1 { + if records.IPv4Hint.Addresses != nil { + f.WriteString(name + "=") + for _, ip := range records.IPv4Hint.Addresses { + f.WriteString(ip.String()) + } + f.WriteString("\n") } - f.WriteString("\n") - } - } else if _qtype == 28 { - if records.IPv6Hint.Addresses != nil { - f.WriteString(name + "=") - for _, ip := range records.IPv6Hint.Addresses { - f.WriteString(ip.String()) + } else if _qtype == 28 { + if records.IPv6Hint.Addresses != nil { + f.WriteString(name + "=") + for _, ip := range records.IPv6Hint.Addresses { + f.WriteString(ip.String()) + } + f.WriteString("\n") } - f.WriteString("\n") } } } - } -*/ + */ return records.Index, records.BuildResponse(request, qtype, 0) } @@ -1506,7 +1653,7 @@ func (outbound *Outbound) ResolveTCPAddr(host string, port int) (*net.TCPAddr, e return nil, errors.New("no such host") } - return &net.TCPAddr{IP: addrs[rand.Intn(len(addrs))], Port: port}, nil + return &net.TCPAddr{IP: addrs[preferredIPIndex(addrs)], Port: port}, nil } func (outbound *Outbound) ResolveTCPAddrs(host string, port int) ([]*net.TCPAddr, error) { diff --git a/phantomtcp/phantom.go b/phantomtcp/phantom.go index 4b143b6..0774163 100755 --- a/phantomtcp/phantom.go +++ b/phantomtcp/phantom.go @@ -57,10 +57,16 @@ const ( type Outbound struct { Device string DNS string - Hint uint32 - MTU uint16 - TTL byte - MaxTTL byte + // QueryOrder previews the DNS query families and their order, + // one of "A", "AAAA", "A,AAAA", "AAAA,A", or "none" when no + // query can be made. CreateOutbounds fills it in once the hint + // is final so the &{...} dump printed at profile load shows the + // plan right after the DNS URL. + QueryOrder string + Hint uint32 + MTU uint16 + TTL byte + MaxTTL byte Protocol byte Address string @@ -68,6 +74,12 @@ type Outbound struct { Timeout uint16 Fallback *Outbound + + // HasIPHint records whether the config explicitly listed + // ipv4/ipv6 in the hint string, as opposed to bits set later + // by device probing or the no-hint fallback. Used by NSLookup + // so an explicit hint overrides the DNS type option preference. + HasIPHint bool } type IPv4Range struct { @@ -132,6 +144,7 @@ const ( HINT_RAND = 0x1 << 25 HINT_TCPFRAG = 0x1 << 26 HINT_TLSFRAG = 0x1 << 27 + HINT_V4FIRST = 0x1 << 28 HINT_KEEPALIVE = 0x1 << 29 HINT_SYNX2 = 0x1 << 30 HINT_ZERO = 0x1 << 31 @@ -820,21 +833,31 @@ func CreateOutbounds(Outbounds []OutboundConfig) []string { var devices []string for _, config := range Outbounds { var Hint uint32 = HINT_NONE - for _, h := range strings.Split(config.Hint, ",") { + pos4, pos6 := -1, -1 + for i, h := range strings.Split(config.Hint, ",") { if h != "" { hint, ok := HintMap[h] if ok { Hint |= hint + if hint == HINT_IPV4 && pos4 < 0 { + pos4 = i + } else if hint == HINT_IPV6 && pos6 < 0 { + pos6 = i + } } else { logPrintln(1, "unsupported hint: "+h) } } } + if pos4 >= 0 && pos6 > pos4 { + Hint |= HINT_V4FIRST + } outbound := new(Outbound) outbound.Device = config.Device outbound.DNS = config.DNS outbound.Hint = Hint + outbound.HasIPHint = pos4 >= 0 || pos6 >= 0 outbound.MTU = uint16(config.MTU) outbound.TTL = byte(config.TTL) outbound.MaxTTL = byte(config.MaxTTL) @@ -900,10 +923,11 @@ func CreateOutbounds(Outbounds []OutboundConfig) []string { } } - if Hint&HINT_IPV4 == 0 && Hint&HINT_IPV6 == 0 { - outbound.Hint |= HINT_IPV4 + if outbound.Hint&HINT_IPV4 == 0 && outbound.Hint&HINT_IPV6 == 0 { + outbound.Hint |= HINT_IPV4 | HINT_IPV6 | HINT_V4FIRST } + outbound.QueryOrder = outbound.describeDNSQuery() } default_outbound, ok := OutboundsMap["default"] diff --git a/phantomtcp/proxy.go b/phantomtcp/proxy.go index e8df4da..c89b418 100755 --- a/phantomtcp/proxy.go +++ b/phantomtcp/proxy.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "log" - "math/rand" "net" "strconv" "strings" @@ -577,7 +576,7 @@ func (outbound *Outbound) ProxyHandshake(conn net.Conn, synpacket *ConnectionInf if outbound.DNS != "" { _, ips := outbound.NSLookup(host, 0) if len(ips) > 0 { - ip := ips[rand.Intn(len(ips))] + ip := ips[preferredIPIndex(ips)] ip4 := ip.To4() if ip4 != nil { copy(b[:], []byte{0x05, 0x01, 0x00, 0x01}) diff --git a/phantomtcp/tcp.go b/phantomtcp/tcp.go index 2062609..c7fe43e 100755 --- a/phantomtcp/tcp.go +++ b/phantomtcp/tcp.go @@ -46,7 +46,9 @@ func IsNormalError(err error) bool { if errErrno == syscall.ETIMEDOUT || errErrno == syscall.ECONNREFUSED || - errErrno == syscall.ECONNRESET { + errErrno == syscall.ECONNRESET || + errErrno == syscall.ENETUNREACH || + errErrno == syscall.EHOSTUNREACH { return true } default: @@ -57,6 +59,62 @@ func IsNormalError(err error) bool { return false } +// preferredTCPIndex returns an index for single-address picks: the pick +// is confined to the leading same-family block of the list, which is the +// preferred family as ordered by NSLookup. Pure lists keep the original +// random behavior. +func preferredTCPIndex(raddrs []*net.TCPAddr) int { + n := len(raddrs) + block := 1 + is4 := raddrs[0].IP.To4() != nil + for block < n && (raddrs[block].IP.To4() != nil) == is4 { + block++ + } + return mathrand.Intn(block) +} + +// preferredIPIndex is the []net.IP flavor of preferredTCPIndex. +func preferredIPIndex(addrs []net.IP) int { + n := len(addrs) + block := 1 + is4 := addrs[0].To4() != nil + for block < n && (addrs[block].To4() != nil) == is4 { + block++ + } + return mathrand.Intn(block) +} + +// preferredOrder returns the dial attempt order: it rotates through the +// leading same-family block first (the preferred family as ordered by +// NSLookup), then through the remaining block, with random start offsets +// to keep multi-record load balancing. +func preferredOrder(raddrs []*net.TCPAddr) []int { + n := len(raddrs) + is4 := raddrs[0].IP.To4() != nil + lead := 1 + for lead < n && (raddrs[lead].IP.To4() != nil) == is4 { + lead++ + } + order := make([]int, n) + if lead == n { + start := mathrand.Intn(n) + for i := 0; i < n; i++ { + order[i] = (start + i) % n + } + return order + } + startL := mathrand.Intn(lead) + for i := 0; i < lead; i++ { + order[i] = (startL + i) % lead + } + rest := n - lead + startR := mathrand.Intn(rest) + for i := 0; i < rest; i++ { + order[lead+i] = lead + (startR+i)%rest + } + return order +} + func GetLocalTCPAddr(name string, ipv6 bool) (*net.TCPAddr, error) { if name == "" { return nil, nil diff --git a/phantomtcp/tcp_root.go b/phantomtcp/tcp_root.go index b471657..e938596 100644 --- a/phantomtcp/tcp_root.go +++ b/phantomtcp/tcp_root.go @@ -69,7 +69,7 @@ func (outbound *Outbound) dial(host string, port int, b []byte, offset int, leng hint := outbound.Hint if hint&HINT_FAKE == 0 { - raddr := raddrs[mathrand.Intn(len(raddrs))] + raddr := raddrs[preferredTCPIndex(raddrs)] var laddr *net.TCPAddr = nil if device != "" { laddr, err = GetLocalTCPAddr(device, raddr.IP.To4() == nil) @@ -161,7 +161,7 @@ func (outbound *Outbound) dial(host string, port int, b []byte, offset int, leng } if PassiveMode { - raddr := raddrs[mathrand.Intn(len(raddrs))] + raddr := raddrs[preferredTCPIndex(raddrs)] var laddr *net.TCPAddr = nil if device != "" { diff --git a/phantomtcp/tcp_user.go b/phantomtcp/tcp_user.go index 23ed52a..23fc3c7 100644 --- a/phantomtcp/tcp_user.go +++ b/phantomtcp/tcp_user.go @@ -58,10 +58,10 @@ func (outbound *Outbound) dial(host string, port int, header []byte, offset int, var raddr *net.TCPAddr = nil var laddr *net.TCPAddr = nil - raddr_index := mathrand.Intn(len(raddrs)) + addr_order := preferredOrder(raddrs) raddrs_len := len(raddrs) for i := 0; i < raddrs_len; i++ { - raddr = raddrs[(i + raddr_index) % raddrs_len] + raddr = raddrs[addr_order[i]] if device != "" { if laddr, err = GetLocalTCPAddr(device, raddr.IP.To4() == nil); err != nil { return nil, nil, err diff --git a/phantomtcp/udp.go b/phantomtcp/udp.go index a127ccf..896a450 100644 --- a/phantomtcp/udp.go +++ b/phantomtcp/udp.go @@ -3,7 +3,6 @@ package phantomtcp import ( "encoding/binary" "errors" - "math/rand" "net" "sync" "time" @@ -159,7 +158,7 @@ func (outbound *Outbound) dialUDPProxy(host string, port int, deadline time.Time if err != nil { return nil, err } - raddr := raddrs[rand.Intn(len(raddrs))] + raddr := raddrs[preferredTCPIndex(raddrs)] proxy_err := errors.New("invalid proxy") var tcpConn net.Conn = nil @@ -176,7 +175,9 @@ func (outbound *Outbound) dialUDPProxy(host string, port int, deadline time.Time if err != nil { return nil, err } - laddr = &net.UDPAddr{IP: _laddr.IP, Port: 0} + if _laddr != nil { + laddr = &net.UDPAddr{IP: _laddr.IP, Port: 0} + } } return net.DialUDP("udp", laddr, &net.UDPAddr{IP: raddr.IP, Port: raddr.Port}) case SOCKS5: