1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-18 01:46:06 -04:00
v2fly/proxy/socks/protocol/socks4.go

40 lines
742 B
Go
Raw Normal View History

package protocol
import (
2015-10-13 07:55:06 -04:00
"errors"
"io"
2015-10-13 07:55:06 -04:00
2016-08-20 14:55:45 -04:00
v2net "v2ray.com/core/common/net"
)
2015-10-13 07:55:06 -04:00
var (
Socks4Downgrade = errors.New("Downgraded to Socks 4.")
)
type Socks4AuthenticationRequest struct {
Version byte
Command byte
2015-12-02 15:44:01 -05:00
Port v2net.Port
IP [4]byte
}
2015-09-25 11:59:45 -04:00
type Socks4AuthenticationResponse struct {
result byte
port uint16
ip []byte
}
2015-12-02 15:44:01 -05:00
func NewSocks4AuthenticationResponse(result byte, port v2net.Port, ip []byte) *Socks4AuthenticationResponse {
2015-09-25 11:59:45 -04:00
return &Socks4AuthenticationResponse{
result: result,
2015-12-02 15:44:01 -05:00
port: port.Value(),
2015-09-25 11:59:45 -04:00
ip: ip,
}
}
func (r *Socks4AuthenticationResponse) Write(writer io.Writer) {
writer.Write([]byte{
byte(0x00), r.result, byte(r.port >> 8), byte(r.port),
r.ip[0], r.ip[1], r.ip[2], r.ip[3]})
2015-09-25 11:59:45 -04:00
}