Skip to content

Commit

Permalink
add fixed udp address
Browse files Browse the repository at this point in the history
  • Loading branch information
amircybersec committed Sep 20, 2024
1 parent 9c085c4 commit 3bf7af8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion x/examples/soax-relay/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
server:
listen_address: 127.0.0.1:1080
tcp_listen_address: 0.0.0.0:1080
udp_listen_address: 0.0.0.0:9000

soax:
package_id: 123456
Expand Down
13 changes: 9 additions & 4 deletions x/examples/soax-relay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ func udpAssociateHandler(ctx context.Context, writer io.Writer, request *socks5.
}
defer upstreamConn.Close()

// Create a local UDP listener for the client
clientListener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4zero, Port: 0})
// Start listening on the client UDP address
clientListenAddr, err := transport.MakeNetAddr("udp", config.Server.UDPListenAddress)
if err != nil {
return err
}
clientListener, err := net.ListenUDP("udp", clientListenAddr.(*net.UDPAddr))
if err != nil {
return err
}
Expand Down Expand Up @@ -218,7 +222,8 @@ func convertToNetAddr(ip netip.Addr, port uint16) *net.UDPAddr {

type Config struct {
Server struct {
ListenAddress string `mapstructure:"listen_address"`
TCPListenAddress string `mapstructure:"tcp_listen_address"`
UDPListenAddress string `mapstructure:"udp_listen_address"`
}
SOAX struct {
PackageID string `mapstructure:"package_id"`
Expand Down Expand Up @@ -297,7 +302,7 @@ func main() {
)

// Run SOCKS5 proxy on the specified address and port
if err := server.ListenAndServe("tcp", config.Server.ListenAddress); err != nil {
if err := server.ListenAndServe("tcp", config.Server.TCPListenAddress); err != nil {
panic(err)
}

Expand Down

0 comments on commit 3bf7af8

Please sign in to comment.