[vlc-devel] [PATCH] demux: adaptive: fix http request with IPv6 reference

Rémi Denis-Courmont remi at remlab.net
Sun Dec 20 08:13:50 UTC 2020


	Nihao,

Comments inline...

Le lauantaina 19. joulukuuta 2020, 11.53.48 EET Xie Zhigang a écrit :
> +bool isIPv6() const;
> +{
> + return ipv6;
> +}
> +
> +static int is_ipv6_addr (const char * host)
> +{
> + const char * p;
> + unsigned colons = 0, nums = 0, decs = 0, dots = 0;
> + if (!host)
> + {
> + return 0;
> + }
> + for (p = host; *p; p++)
> + {
> + char c = *p;
> + if (c == ':')
> + {
> + colons ++;
> + if (nums > 4)
> + {
> + return 0;
> + }
> + nums = 0;
> + decs = 0;
> + }
> + else if (('0' <= c && c <= '9') || ('A' <= c && c <= 'F') || ('a' <= c &&
> c <= 'f')) + {
> + if ('0' <= c && c <= '9')
> + {
> + decs ++;
> + }
> + nums ++;
> + }
> + else if (c == '.')
> + {
> + dots ++;
> + if (nums != decs)
> + {
> + return 0;
> + }
> + if (nums == 0 || 3 < nums)
> + {
> + return 0;
> + }
> + }
> + else
> + {
> + return 0;
> + }
> + }
> + return 2 <= colons && colons <= 7 && (dots == 0 || dots == 3);
> +}
> +

This does not need so much complexity. If you really want to check for IPv6, 
there's inet_pton(), but you could just check if the string contains as colon.

Also please try to stick to the same indentation style as the rest of the 
code.

>  void ConnectionParams::parse()
>  {
>      vlc_url_t url_components;

-- 
雷米‧德尼-库尔蒙
http://www.remlab.net/





More information about the vlc-devel mailing list