ginetaddress: Scope ID parsing is not supported on win32

getaddrinfo doesn't parse it on Windows. This could be replaced by more manual parsing in the future.
This commit is contained in:
Patrick Griffis
2025-07-07 11:24:11 -05:00
parent b40194865a
commit 7e85ae9d5f
3 changed files with 10 additions and 2 deletions

View File

@@ -425,6 +425,10 @@ g_inet_address_init (GInetAddress *address)
* *
* Parses @string as an IP address and creates a new #GInetAddress. * Parses @string as an IP address and creates a new #GInetAddress.
* *
* If @address is an IPv6 address, it can also contain a scope ID
* (separated from the address by a `%`). Note that currently this
* behavior is platform specific. This may change in a future release.
*
* Returns: (nullable) (transfer full): a new #GInetAddress corresponding * Returns: (nullable) (transfer full): a new #GInetAddress corresponding
* to @string, or %NULL if @string could not be parsed. * to @string, or %NULL if @string could not be parsed.
* Free the returned object with g_object_unref(). * Free the returned object with g_object_unref().

View File

@@ -402,7 +402,8 @@ g_inet_socket_address_new (GInetAddress *address,
* Creates a new #GInetSocketAddress for @address and @port. * Creates a new #GInetSocketAddress for @address and @port.
* *
* If @address is an IPv6 address, it can also contain a scope ID * If @address is an IPv6 address, it can also contain a scope ID
* (separated from the address by a `%`). * (separated from the address by a `%`). Note that currently this
* behavior is platform specific. This may change in a future release.
* *
* Returns: (nullable) (transfer full): a new #GInetSocketAddress, * Returns: (nullable) (transfer full): a new #GInetSocketAddress,
* or %NULL if @address cannot be parsed. * or %NULL if @address cannot be parsed.

View File

@@ -53,9 +53,11 @@ test_parse (void)
addr = g_inet_address_new_from_string ("204.152.189.116"); addr = g_inet_address_new_from_string ("204.152.189.116");
g_assert (addr != NULL); g_assert (addr != NULL);
g_object_unref (addr); g_object_unref (addr);
#ifndef G_OS_WIN32
addr = g_inet_address_new_from_string ("::1%0"); addr = g_inet_address_new_from_string ("::1%0");
g_assert (addr != NULL); g_assert (addr != NULL);
g_object_unref (addr); g_object_unref (addr);
#endif
addr = g_inet_address_new_from_string ("::1::2"); addr = g_inet_address_new_from_string ("::1::2");
g_assert (addr == NULL); g_assert (addr == NULL);
@@ -209,11 +211,12 @@ test_socket_address (void)
g_object_unref (saddr); g_object_unref (saddr);
addr = g_inet_address_new_from_string ("::1%25"); addr = g_inet_address_new_from_string ("::1");
saddr = G_INET_SOCKET_ADDRESS (g_object_new (G_TYPE_INET_SOCKET_ADDRESS, saddr = G_INET_SOCKET_ADDRESS (g_object_new (G_TYPE_INET_SOCKET_ADDRESS,
"address", addr, "address", addr,
"port", 308, "port", 308,
"flowinfo", 10, "flowinfo", 10,
"scope-id", 25,
NULL)); NULL));
g_object_unref (addr); g_object_unref (addr);