socks4.go 1013 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package protocol
  2. import (
  3. "github.com/v2ray/v2ray-core/common/alloc"
  4. "github.com/v2ray/v2ray-core/common/errors"
  5. )
  6. type SocksVersion4Error struct {
  7. errors.ErrorCode
  8. }
  9. var socksVersion4ErrorInstance = SocksVersion4Error{ErrorCode: 1000}
  10. func NewSocksVersion4Error() SocksVersion4Error {
  11. return socksVersion4ErrorInstance
  12. }
  13. func (err SocksVersion4Error) Error() string {
  14. return err.Prefix() + "Request is socks version 4."
  15. }
  16. type Socks4AuthenticationRequest struct {
  17. Version byte
  18. Command byte
  19. Port uint16
  20. IP [4]byte
  21. }
  22. type Socks4AuthenticationResponse struct {
  23. result byte
  24. port uint16
  25. ip []byte
  26. }
  27. func NewSocks4AuthenticationResponse(result byte, port uint16, ip []byte) *Socks4AuthenticationResponse {
  28. return &Socks4AuthenticationResponse{
  29. result: result,
  30. port: port,
  31. ip: ip,
  32. }
  33. }
  34. func (r *Socks4AuthenticationResponse) Write(buffer *alloc.Buffer) {
  35. buffer.AppendBytes(
  36. byte(0x00), r.result, byte(r.port>>8), byte(r.port),
  37. r.ip[0], r.ip[1], r.ip[2], r.ip[3])
  38. }