Skip to content

Commit 0126026

Browse files
committedFeb 4, 2016
Made dialer configurable
1 parent b7e3cc6 commit 0126026

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
 

‎request.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,12 @@ func (s *Server) handleConnect(conn conn, req *Request) error {
153153
}
154154

155155
// Attempt to connect
156-
addr := net.TCPAddr{IP: req.realDestAddr.IP, Port: req.realDestAddr.Port}
157-
target, err := net.DialTCP("tcp", nil, &addr)
156+
addr := fmt.Sprintf("%v:%d", req.realDestAddr.IP, req.realDestAddr.Port)
157+
dial := s.config.Dial
158+
if dial == nil {
159+
dial = net.Dial
160+
}
161+
target, err := dial("tcp", addr)
158162
if err != nil {
159163
msg := err.Error()
160164
resp := hostUnreachable

‎socks5.go

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ type Config struct {
4343
// Logger can be used to provide a custom log target.
4444
// Defaults to stdout.
4545
Logger *log.Logger
46+
47+
// Optional function for dialing out
48+
Dial func(network, addr string) (net.Conn, error)
4649
}
4750

4851
// Server is reponsible for accepting connections and handling

0 commit comments

Comments
 (0)
Please sign in to comment.