github.com/database64128/shadowsocks-go@v1.10.2-0.20240315062903-143a773533f1/socks5/packet.go (about)

     1  package socks5
     2  
     3  import "errors"
     4  
     5  var ErrFragmentationNotSupported = errors.New("packet fragmentation is not supported")
     6  
     7  // WritePacketHeader writes RSV and FRAG to the beginning of b.
     8  // The length of b must be at least 3 bytes.
     9  func WritePacketHeader(b []byte) {
    10  	b[0] = 0 // RSV
    11  	b[1] = 0 // RSV
    12  	b[2] = 0 // FRAG
    13  }
    14  
    15  // ValidatePacketHeader validates RSV and FRAG at the beginning of b.
    16  // The length of b must be at least 3 bytes.
    17  func ValidatePacketHeader(b []byte) error {
    18  	if b[2] != 0 {
    19  		return ErrFragmentationNotSupported
    20  	}
    21  	return nil
    22  }