forked from onrik/SOCKSProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
32 lines (28 loc) · 678 Bytes
/
client.go
File metadata and controls
32 lines (28 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package proxy
import (
"fmt"
"net"
"net/url"
"strings"
)
type Client interface {
Dial(network, address string) (net.Conn, error)
}
func NewClient(proxy *url.URL, conf *SOCKSConf) (client Client, err error) {
switch strings.ToUpper(proxy.Scheme) {
case "SOCKS4", "SOCKS4A":
client = &socks4Client{proxy, conf}
case "SOCKS5", "SOCKS5+TLS":
client = &socks5Client{proxy, conf, conf.TLSConfig}
default:
err = fmt.Errorf("%s not supported", proxy.Scheme)
}
return
}
func splitHostPort(addr string) (host, port []byte, err error) {
hostName, hostPort, err := net.SplitHostPort(addr)
if err != nil {
return
}
return []byte(hostName), toPort(hostPort), err
}