socks4.go 729 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package protocol
  2. import (
  3. "errors"
  4. "github.com/v2ray/v2ray-core/common/alloc"
  5. )
  6. var (
  7. Socks4Downgrade = errors.New("Downgraded to Socks 4.")
  8. )
  9. type Socks4AuthenticationRequest struct {
  10. Version byte
  11. Command byte
  12. Port uint16
  13. IP [4]byte
  14. }
  15. type Socks4AuthenticationResponse struct {
  16. result byte
  17. port uint16
  18. ip []byte
  19. }
  20. func NewSocks4AuthenticationResponse(result byte, port uint16, ip []byte) *Socks4AuthenticationResponse {
  21. return &Socks4AuthenticationResponse{
  22. result: result,
  23. port: port,
  24. ip: ip,
  25. }
  26. }
  27. func (r *Socks4AuthenticationResponse) Write(buffer *alloc.Buffer) {
  28. buffer.AppendBytes(
  29. byte(0x00), r.result, byte(r.port>>8), byte(r.port),
  30. r.ip[0], r.ip[1], r.ip[2], r.ip[3])
  31. }