Skip to content

Commit

Permalink
Use correct address for packets from localRelayConn
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyxdd committed Apr 22, 2021
1 parent 51abb06 commit 3b6a2bc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/socks5/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,13 @@ func (s *Server) udpServer(clientConn *net.UDPConn, localRelayConn *net.UDPConn,
go func() {
buf := make([]byte, udpBufferSize)
for {
n, _, err := localRelayConn.ReadFrom(buf)
n, from, err := localRelayConn.ReadFrom(buf)
if n > 0 {
d := socks5.NewDatagram(socks5.ATYPIPv4,
[]byte{0x00, 0x00, 0x00, 0x00}, []byte{0x00, 0x00}, buf[:n])
atyp, addr, port, err := socks5.ParseAddress(from.String())
if err != nil {
continue
}
d := socks5.NewDatagram(atyp, addr, port, buf[:n])
_, _ = clientConn.WriteToUDP(d.Bytes(), clientAddr)
}
if err != nil {
Expand Down

0 comments on commit 3b6a2bc

Please sign in to comment.