Skip to content

Commit

Permalink
fix(socks5): should not dial returned bind addr directly (#212)
Browse files Browse the repository at this point in the history
* fix(socks5): should not dial returned bind addr directly
When server returns an any ip (0.0.0.0 or [::0]), we should use conventional ip to replace the any ip given (0.0.0.0 or [::0]).
This behaviour adapts to most situations.

See v2fly/v2ray-core#523

* fix: splithostport
  • Loading branch information
mzz2017 authored Feb 7, 2021
1 parent a310635 commit d2268b6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions proxy/socks5/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,20 @@ func (s *Socks5) DialUDP(network, addr string) (pc net.PacketConn, writeTo net.A
return nil, nil, err
}

pc, nextHop, err := s.dialer.DialUDP(network, uAddr.String())
var uAddress string
h, p, _ := net.SplitHostPort(uAddr.String())
// if returned bind ip is unspecified
if ip := net.ParseIP(h); ip != nil && ip.IsUnspecified() {
// indicate using conventional addr
h, _, _ = net.SplitHostPort(s.addr)
uAddress = net.JoinHostPort(h, p)
} else {
uAddress = uAddr.String()
}

pc, nextHop, err := s.dialer.DialUDP(network, uAddress)
if err != nil {
log.F("[socks5] dialudp to %s error: %s", uAddr.String(), err)
log.F("[socks5] dialudp to %s error: %s", uAddress, err)
return nil, nil, err
}

Expand Down

0 comments on commit d2268b6

Please sign in to comment.