mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 07:26:15 +01:00
hostutils: accept zoneid in IPv6 addresses
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
50343afb6e
commit
03550ec097
@ -685,6 +685,8 @@ g_hostname_is_ascii_encoded (const gchar *hostname)
|
||||
* Tests if @hostname is the string form of an IPv4 or IPv6 address.
|
||||
* (Eg, "192.168.0.1".)
|
||||
*
|
||||
* Since 2.66, IPv6 addresses with a zone-id are accepted (RFC6874).
|
||||
*
|
||||
* Returns: %TRUE if @hostname is an IP address
|
||||
*
|
||||
* Since: 2.22
|
||||
@ -716,7 +718,7 @@ g_hostname_is_ip_address (const gchar *hostname)
|
||||
|
||||
nsegments = 0;
|
||||
skipped = FALSE;
|
||||
while (*p && nsegments < 8)
|
||||
while (*p && *p != '%' && nsegments < 8)
|
||||
{
|
||||
/* Each segment after the first must be preceded by a ':'.
|
||||
* (We also handle half of the "string starts with ::" case
|
||||
@ -760,7 +762,7 @@ g_hostname_is_ip_address (const gchar *hostname)
|
||||
p = end;
|
||||
}
|
||||
|
||||
return !*p && (nsegments == 8 || skipped);
|
||||
return (!*p || (p[0] == '%' && p[1])) && (nsegments == 8 || skipped);
|
||||
}
|
||||
|
||||
parse_ipv4:
|
||||
|
@ -207,6 +207,11 @@ static const struct {
|
||||
{ "0123::123.45.67.89", TRUE },
|
||||
{ "::123.45.67.89", TRUE },
|
||||
|
||||
/* accept zone-id from rfc6874 */
|
||||
{ "0123:4567:89AB:cdef:3210:7654:ba98:FeDc%zoneid0", TRUE },
|
||||
{ "fe80::dead:beef%zonÉid0%weird", TRUE },
|
||||
{ "fe80::dead:beef%", FALSE },
|
||||
|
||||
/* Contain non-hex chars */
|
||||
{ "012x:4567:89AB:cdef:3210:7654:ba98:FeDc", FALSE },
|
||||
{ "0123:45x7:89AB:cdef:3210:7654:ba98:FeDc", FALSE },
|
||||
@ -261,7 +266,6 @@ static const struct {
|
||||
{ "0123:4567:89AB:cdef:123.45.67.89", FALSE },
|
||||
{ "0123:4567:89AB:cdef:3210:123.45.67.89:FeDc", FALSE },
|
||||
|
||||
|
||||
/* IPv4 tests */
|
||||
|
||||
{ "123.45.67.89", TRUE },
|
||||
|
Loading…
Reference in New Issue
Block a user