func (pp *proxyParser) parseProxyV1Proto(b []byte) error {
out:
	for cr := false; true; {
		one := []byte{0}
		n, err := pp.r.Read(one)
		if err != nil {
			return err
		}
		if n > 0 {
			c := one[0]
			switch {
			case !cr && c == '\r':
				cr = true
			case cr && c == '\n':
				break out
			case c != '\r' && c != '\n':
				if len(b) >= 107-6 {
					return fmt.Errorf("proxyv1: proxy line longer than 107 bytes")
				}
				b = append(b, c)
			default:
				return fmt.Errorf("proxy1: bad proxy line")
			}
		}
	}
	parts := strings.Split(string(b), " ")
	if len(parts) == 1 && parts[0] == "UNKNOWN" {
		return nil
	} else if len(parts) != 5 {
		return fmt.Errorf("proxy1: bad proxy line: expecting 5 elements, got %d", len(parts))
	}
	parseIP := func(s string, ver int) (net.IP, error) {
		ip := net.ParseIP(s)
		if ip == nil {
			return nil, fmt.Errorf("proxy1: bad ip address: %s", s)
		}
		if !(ver == 4 && ip.To4() != nil) && !(ver == 6 && len(ip) == 16) {
			return nil, fmt.Errorf("proxy1: bad ipv%d addr: %s", ver, s)
		}
		return ip, nil
	}
	parsePort := func(s string) (int, error) {
		i, err := strconv.ParseUint(s, 10, 16)
		if err != nil {
			return 0, fmt.Errorf("proxy1: bad port %s: %v", s, err)
		}
		if i > 65535 {
			return 0, fmt.Errorf("proxy1: port out of range: %d", i)
		}
		return int(i), nil
	}
	fam := parts[0]
	var (
		af  int
		err error
	)
	switch fam {
	case "TCP4":
		af = 4
	case "TCP6":
		af = 6
	case "UNKNOWN":
		return nil
	}
	pp.SrcIP, err = parseIP(parts[1], af)
	if err != nil {
		return err
	}
	pp.DestIP, err = parseIP(parts[2], af)
	if err != nil {
		return err
	}
	pp.SrcPort, err = parsePort(parts[3])
	if err != nil {
		return err
	}
	pp.DestPort, err = parsePort(parts[4])
	if err != nil {
		return err
	}
	return nil
}
// parseProxyV1Proto parse PROXY v1 data
parseProxyV1Proto parse PROXY v1 data
// parseProxyV1Proto parse PROXY v1 data
func (pp *proxyParser) parseProxyV1Proto(b []byte) error {
out:
	for cr := false; true; {
		one := []byte{0}
		n, err := pp.r.Read(one)
		if err != nil {
			return err
		}
		if n > 0 {
			c := one[0]
			switch {
			case !cr && c == '\r':
				cr = true
			case cr && c == '\n':
				break out
			case c != '\r' && c != '\n':
				if len(b) >= 107-6 {
					return fmt.Errorf("proxyv1: proxy line longer than 107 bytes")
				}
				b = append(b, c)
			default:
				return fmt.Errorf("proxy1: bad proxy line")
			}
		}
	}
	parts := strings.Split(string(b), " ")
	if len(parts) == 1 && parts[0] == "UNKNOWN" {
		return nil
	} else if len(parts) != 5 {
		return fmt.Errorf("proxy1: bad proxy line: expecting 5 elements, got %d", len(parts))
	}
	parseIP := func(s string, ver int) (net.IP, error) {
		ip := net.ParseIP(s)
		if ip == nil {
			return nil, fmt.Errorf("proxy1: bad ip address: %s", s)
		}
		if !(ver == 4 && ip.To4() != nil) && !(ver == 6 && len(ip) == 16) {
			return nil, fmt.Errorf("proxy1: bad ipv%d addr: %s", ver, s)
		}
		return ip, nil
	}
	parsePort := func(s string) (int, error) {
		i, err := strconv.ParseUint(s, 10, 16)
		if err != nil {
			return 0, fmt.Errorf("proxy1: bad port %s: %v", s, err)
		}
		if i > 65535 {
			return 0, fmt.Errorf("proxy1: port out of range: %d", i)
		}
		return int(i), nil
	}
	fam := parts[0]
	var (
		af  int
		err error
	)
	switch fam {
	case "TCP4":
		af = 4
	case "TCP6":
		af = 6
	case "UNKNOWN":
		return nil
	}
	pp.SrcIP, err = parseIP(parts[1], af)
	if err != nil {
		return err
	}
	pp.DestIP, err = parseIP(parts[2], af)
	if err != nil {
		return err
	}
	pp.SrcPort, err = parsePort(parts[3])
	if err != nil {
		return err
	}
	pp.DestPort, err = parsePort(parts[4])
	if err != nil {
		return err
	}
	return nil
}
func ( pp * proxyParser ) parseProxyV1Proto ( b [ ] byte ) error { out : for cr := false ; true ; { one := [ ] byte { 0 } n , err := pp . r . Read ( one ) if err != nil { return err } if n > 0 { c := one [ 0 ] switch { case ! cr && c == '\r' : cr = true case cr && c == '\n' : break out case c != '\r' && c != '\n' : if len ( b ) >= 107 - 6 { return fmt . Errorf ( " " ) } b = append ( b , c ) default : return fmt . Errorf ( " " ) } } } parts := strings . Split ( string ( b ) , " " ) if len ( parts ) == 1 && parts [ 0 ] == " " { return nil } else if len ( parts ) != 5 { return fmt . Errorf ( " " , len ( parts ) ) } parseIP := func ( s string , ver int ) ( net . IP , error ) { ip := net . ParseIP ( s ) if ip == nil { return nil , fmt . Errorf ( " " , s ) } if ! ( ver == 4 && ip . To4 ( ) != nil ) && ! ( ver == 6 && len ( ip ) == 16 ) { return nil , fmt . Errorf ( " " , ver , s ) } return ip , nil } parsePort := func ( s string ) ( int , error ) { i , err := strconv . ParseUint ( s , 10 , 16 ) if err != nil { return 0 , fmt . Errorf ( " " , s , err ) } if i > 65535 { return 0 , fmt . Errorf ( " " , i ) } return int ( i ) , nil } fam := parts [ 0 ] var ( af int err error ) switch fam { case " " : af = 4 case " " : af = 6 case " " : return nil } pp . SrcIP , err = parseIP ( parts [ 1 ] , af ) if err != nil { return err } pp . DestIP , err = parseIP ( parts [ 2 ] , af ) if err != nil { return err } pp . SrcPort , err = parsePort ( parts [ 3 ] ) if err != nil { return err } pp . DestPort , err = parsePort ( parts [ 4 ] ) if err != nil { return err } return nil }
parseProxyV1Proto parse PROXY v1 data
parseProxyV1Proto parse PROXY v1 data