-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocks.go
98 lines (84 loc) · 2.41 KB
/
socks.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"strconv"
)
type SocksVersion byte
const (
_ SocksVersion = iota
VersionSocks4 = 4
VersionSocks5 = 5
)
type SocksCommand byte
const (
_ SocksCommand = iota
SocksCommandConnectTCP = 1
SocksCommandConnectUDP = 3
)
type Socks4Status byte
const (
_ Socks4Status = iota
Socks4StatusRequestGranted = 0x5a
Socks4StatusConnectionForbidden = 0x5b
Socks4StatusIdentdRequired = 0x5c
Socks4StatusIdentdFailed = 0x5d
)
func (s Socks4Status) String() string {
switch s {
case Socks4StatusRequestGranted:
return "request granted"
case Socks4StatusConnectionForbidden:
return "connection forbidden"
case Socks4StatusIdentdRequired:
return "identd required"
case Socks4StatusIdentdFailed:
return "identd failed"
}
return "socks4 status: errno 0x" + strconv.FormatInt(int64(s), 16)
}
type Socks5AddressType byte
const (
_ Socks5AddressType = iota
Socks5IPv4Address = 1
Socks5DomainName = 3
Socks5IPv6Address = 4
)
const (
Socks5AuthMethodNone byte = 0
Socks5AuthMethodGSSAPI byte = 1
Socks5AuthMethodPassword byte = 2
)
type Socks5Status byte
const (
Socks5StatusRequestGranted Socks5Status = iota
Socks5StatusGeneralFailure
Socks5StatusConnectionNotAllowedByRuleset
Socks5StatusNetworkUnreachable
Socks5StatusHostUnreachable
Socks5StatusConnectionRefusedByDestinationHost
Socks5StatusTTLExpired
Socks5StatusCommandNotSupported
Socks5StatusAddressTypeNotSupported
)
func (s Socks5Status) String() string {
switch s {
case Socks5StatusRequestGranted:
return "request granted"
case Socks5StatusGeneralFailure:
return "general failure"
case Socks5StatusConnectionNotAllowedByRuleset:
return "connection not allowed by ruleset"
case Socks5StatusNetworkUnreachable:
return "network unreachable"
case Socks5StatusHostUnreachable:
return "host unreachable"
case Socks5StatusConnectionRefusedByDestinationHost:
return "connection refused by destination host"
case Socks5StatusTTLExpired:
return "TTL expired"
case Socks5StatusCommandNotSupported:
return "command not supported"
case Socks5StatusAddressTypeNotSupported:
return "address type not supported"
}
return "socks5 status: errno 0x" + strconv.FormatInt(int64(s), 16)
}