|
|
@ -71,10 +71,10 @@ type Socks5AuthenticationResponse struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewAuthenticationResponse(authMethod byte) *Socks5AuthenticationResponse {
|
|
|
|
func NewAuthenticationResponse(authMethod byte) *Socks5AuthenticationResponse {
|
|
|
|
response := new(Socks5AuthenticationResponse)
|
|
|
|
return &Socks5AuthenticationResponse{
|
|
|
|
response.version = socksVersion
|
|
|
|
version: socksVersion,
|
|
|
|
response.authMethod = authMethod
|
|
|
|
authMethod: authMethod,
|
|
|
|
return response
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func WriteAuthentication(writer io.Writer, r *Socks5AuthenticationResponse) error {
|
|
|
|
func WriteAuthentication(writer io.Writer, r *Socks5AuthenticationResponse) error {
|
|
|
@ -154,7 +154,7 @@ type Socks5Request struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func ReadRequest(reader io.Reader) (request *Socks5Request, err error) {
|
|
|
|
func ReadRequest(reader io.Reader) (request *Socks5Request, err error) {
|
|
|
|
request = new(Socks5Request)
|
|
|
|
|
|
|
|
buffer := make([]byte, 4)
|
|
|
|
buffer := make([]byte, 4)
|
|
|
|
nBytes, err := reader.Read(buffer)
|
|
|
|
nBytes, err := reader.Read(buffer)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -164,11 +164,12 @@ func ReadRequest(reader io.Reader) (request *Socks5Request, err error) {
|
|
|
|
err = fmt.Errorf("Unable to read request.")
|
|
|
|
err = fmt.Errorf("Unable to read request.")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
request = &Socks5Request{
|
|
|
|
request.Version = buffer[0]
|
|
|
|
Version: buffer[0],
|
|
|
|
request.Command = buffer[1]
|
|
|
|
Command: buffer[1],
|
|
|
|
// buffer[2] is a reserved field
|
|
|
|
// buffer[2] is a reserved field
|
|
|
|
request.AddrType = buffer[3]
|
|
|
|
AddrType: buffer[3],
|
|
|
|
|
|
|
|
}
|
|
|
|
switch request.AddrType {
|
|
|
|
switch request.AddrType {
|
|
|
|
case AddrTypeIPv4:
|
|
|
|
case AddrTypeIPv4:
|
|
|
|
nBytes, err = reader.Read(request.IPv4[:])
|
|
|
|
nBytes, err = reader.Read(request.IPv4[:])
|
|
|
@ -260,9 +261,9 @@ type Socks5Response struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewSocks5Response() *Socks5Response {
|
|
|
|
func NewSocks5Response() *Socks5Response {
|
|
|
|
response := new(Socks5Response)
|
|
|
|
return &Socks5Response{
|
|
|
|
response.Version = socksVersion
|
|
|
|
Version: socksVersion,
|
|
|
|
return response
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (r *Socks5Response) SetIPv4(ipv4 []byte) {
|
|
|
|
func (r *Socks5Response) SetIPv4(ipv4 []byte) {
|
|
|
|