func (pp *proxyParser) parseProxyV2Proto(b []byte) error {
	{
		ver_cmd := uint8(b[0])
		ver := ver_cmd & 0xf0
		if ver != 0x20 {
			return fmt.Errorf("proxy2: bad version: %02x", ver_cmd)
		}
		switch ver_cmd & 0xf {
		case COMMAND_LOCAL:
			pp.Command = "LOCAL"
		case COMMAND_PROXY:
			pp.Command = "PROXY"
		default:
			return fmt.Errorf("proxy2: bad command: %02x", ver_cmd)
		}
	}
	readFunc := func(r io.Reader, size int) ([]byte, error) {
		if size < 0 {
			return nil, fmt.Errorf("negative size read")
		}
		buf := make([]byte, size)
		_, err := io.ReadFull(r, buf)
		if err != nil {
			return nil, err
		}
		return buf, nil
	}
	length := int(binary.BigEndian.Uint16(b[2:]))
	fam := uint8(b[1])
	af := (fam & 0xf0) >> 4
	switch af {
	case AF_UNSPEC, AF_UNIX:
		_, err := readFunc(pp.r, length)
		return err
	case AF_INET:
		buf, err := readFunc(pp.r, 8)
		if err != nil {
			return err
		}
		length -= 8
		pp.SrcIP = net.IP(buf[:4])
		pp.DestIP = net.IP(buf[4:])
	case AF_INET6:
		buf, err := readFunc(pp.r, 32)
		if err != nil {
			return err
		}
		length -= 32
		pp.SrcIP = net.IP(buf[:16])
		pp.DestIP = net.IP(buf[16:])
	default:
		return fmt.Errorf("proxy2: unknown address family: %02x", fam)
	}

	switch l4 := af & 0xf; l4 {
	case L4_UNSPEC:
		_, err := readFunc(pp.r, length)
		return err
	case L4_STREAM, L4_DGRAM:
		buf, err := readFunc(pp.r, 4)
		if err != nil {
			return err
		}
		length -= 4
		pp.SrcPort = int(binary.BigEndian.Uint16(buf[:2]))
		pp.DestPort = int(binary.BigEndian.Uint16(buf[2:]))
	default:
		return fmt.Errorf("proxy2: unknown transport protocol: %02x", fam)
	}
	_, err := readFunc(pp.r, length)
	return err
}
// parseProxyV1Proto parse PROXY v2 data
parseProxyV1Proto parse PROXY v2 data
// parseProxyV1Proto parse PROXY v2 data
func (pp *proxyParser) parseProxyV2Proto(b []byte) error {
	{
		ver_cmd := uint8(b[0])
		ver := ver_cmd & 0xf0
		if ver != 0x20 {
			return fmt.Errorf("proxy2: bad version: %02x", ver_cmd)
		}
		switch ver_cmd & 0xf {
		case COMMAND_LOCAL:
			pp.Command = "LOCAL"
		case COMMAND_PROXY:
			pp.Command = "PROXY"
		default:
			return fmt.Errorf("proxy2: bad command: %02x", ver_cmd)
		}
	}
	readFunc := func(r io.Reader, size int) ([]byte, error) {
		if size < 0 {
			return nil, fmt.Errorf("negative size read")
		}
		buf := make([]byte, size)
		_, err := io.ReadFull(r, buf)
		if err != nil {
			return nil, err
		}
		return buf, nil
	}
	length := int(binary.BigEndian.Uint16(b[2:]))
	fam := uint8(b[1])
	af := (fam & 0xf0) >> 4
	switch af {
	case AF_UNSPEC, AF_UNIX:
		_, err := readFunc(pp.r, length)
		return err
	case AF_INET:
		buf, err := readFunc(pp.r, 8)
		if err != nil {
			return err
		}
		length -= 8
		pp.SrcIP = net.IP(buf[:4])
		pp.DestIP = net.IP(buf[4:])
	case AF_INET6:
		buf, err := readFunc(pp.r, 32)
		if err != nil {
			return err
		}
		length -= 32
		pp.SrcIP = net.IP(buf[:16])
		pp.DestIP = net.IP(buf[16:])
	default:
		return fmt.Errorf("proxy2: unknown address family: %02x", fam)
	}
	switch l4 := af & 0xf; l4 {
	case L4_UNSPEC:
		_, err := readFunc(pp.r, length)
		return err
	case L4_STREAM, L4_DGRAM:
		buf, err := readFunc(pp.r, 4)
		if err != nil {
			return err
		}
		length -= 4
		pp.SrcPort = int(binary.BigEndian.Uint16(buf[:2]))
		pp.DestPort = int(binary.BigEndian.Uint16(buf[2:]))
	default:
		return fmt.Errorf("proxy2: unknown transport protocol: %02x", fam)
	}
	_, err := readFunc(pp.r, length)
	return err
}
func ( pp * proxyParser ) parseProxyV2Proto ( b [ ] byte ) error { { ver_cmd := uint8 ( b [ 0 ] ) ver := ver_cmd & 0xf0 if ver != 0x20 { return fmt . Errorf ( " " , ver_cmd ) } switch ver_cmd & 0xf { case COMMAND_LOCAL : pp . Command = " " case COMMAND_PROXY : pp . Command = " " default : return fmt . Errorf ( " " , ver_cmd ) } } readFunc := func ( r io . Reader , size int ) ( [ ] byte , error ) { if size < 0 { return nil , fmt . Errorf ( " " ) } buf := make ( [ ] byte , size ) _ , err := io . ReadFull ( r , buf ) if err != nil { return nil , err } return buf , nil } length := int ( binary . BigEndian . Uint16 ( b [ 2 : ] ) ) fam := uint8 ( b [ 1 ] ) af := ( fam & 0xf0 ) >> 4 switch af { case AF_UNSPEC , AF_UNIX : _ , err := readFunc ( pp . r , length ) return err case AF_INET : buf , err := readFunc ( pp . r , 8 ) if err != nil { return err } length -= 8 pp . SrcIP = net . IP ( buf [ : 4 ] ) pp . DestIP = net . IP ( buf [ 4 : ] ) case AF_INET6 : buf , err := readFunc ( pp . r , 32 ) if err != nil { return err } length -= 32 pp . SrcIP = net . IP ( buf [ : 16 ] ) pp . DestIP = net . IP ( buf [ 16 : ] ) default : return fmt . Errorf ( " " , fam ) } switch l4 := af & 0xf ; l4 { case L4_UNSPEC : _ , err := readFunc ( pp . r , length ) return err case L4_STREAM , L4_DGRAM : buf , err := readFunc ( pp . r , 4 ) if err != nil { return err } length -= 4 pp . SrcPort = int ( binary . BigEndian . Uint16 ( buf [ : 2 ] ) ) pp . DestPort = int ( binary . BigEndian . Uint16 ( buf [ 2 : ] ) ) default : return fmt . Errorf ( " " , fam ) } _ , err := readFunc ( pp . r , length ) return err }
parseProxyV1Proto parse PROXY v2 data
parseProxyV1Proto parse PROXY v2 data