Skip to content

Commit

Permalink
use outgoing interface's IP for UDP relay port
Browse files Browse the repository at this point in the history
  • Loading branch information
ge9 committed Jun 13, 2024
1 parent fd57e80 commit 00c36ab
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ func (h *socks5Handler) handleUDPRelay(conn net.Conn, req *gosocks5.Request) {
return
}

relay, err := net.ListenUDP("udp", nil)
relay, err := net.ListenUDP("udp", &net.UDPAddr{IP: conn.LocalAddr().(*net.TCPAddr).IP, Port: 0}) // use out-going interface's IP
if err != nil {
log.Logf("[socks5-udp] %s -> %s : %s", conn.RemoteAddr(), conn.LocalAddr(), err)
reply := gosocks5.NewReply(gosocks5.Failure, nil)
Expand All @@ -1138,7 +1138,6 @@ func (h *socks5Handler) handleUDPRelay(conn net.Conn, req *gosocks5.Request) {
defer relay.Close()

socksAddr := toSocksAddr(relay.LocalAddr())
socksAddr.Host, _, _ = net.SplitHostPort(conn.LocalAddr().String()) // replace the IP to the out-going interface's
reply := gosocks5.NewReply(gosocks5.Succeeded, socksAddr)
if err := reply.Write(conn); err != nil {
log.Logf("[socks5-udp] %s <- %s : %s", conn.RemoteAddr(), conn.LocalAddr(), err)
Expand Down

0 comments on commit 00c36ab

Please sign in to comment.