1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-12 15:27:16 -05:00
v2fly/proxy/socks/protocol/socks4.go

48 lines
1013 B
Go
Raw Normal View History

package protocol
import (
2015-10-08 17:06:12 -04:00
"github.com/v2ray/v2ray-core/common/alloc"
"github.com/v2ray/v2ray-core/common/errors"
)
type SocksVersion4Error struct {
errors.ErrorCode
}
var socksVersion4ErrorInstance = SocksVersion4Error{ErrorCode: 1000}
func NewSocksVersion4Error() SocksVersion4Error {
return socksVersion4ErrorInstance
}
func (err SocksVersion4Error) Error() string {
return err.Prefix() + "Request is socks version 4."
}
type Socks4AuthenticationRequest struct {
Version byte
Command byte
Port uint16
IP [4]byte
}
2015-09-25 11:59:45 -04:00
type Socks4AuthenticationResponse struct {
result byte
port uint16
ip []byte
}
func NewSocks4AuthenticationResponse(result byte, port uint16, ip []byte) *Socks4AuthenticationResponse {
return &Socks4AuthenticationResponse{
result: result,
port: port,
ip: ip,
}
}
2015-10-08 17:06:12 -04:00
func (r *Socks4AuthenticationResponse) Write(buffer *alloc.Buffer) {
buffer.AppendBytes(
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
}