gsocketaddress: Set scope-id and flowinfo of ginetaddress

This commit is contained in:
Patrick Griffis
2025-07-02 09:30:05 -05:00
parent 73d0627bda
commit d03f495b31
2 changed files with 17 additions and 11 deletions

View File

@@ -97,12 +97,12 @@ g_inet_socket_address_get_property (GObject *object,
case PROP_FLOWINFO:
g_return_if_fail (g_inet_address_get_family (address->priv->address) == G_SOCKET_FAMILY_IPV6);
g_value_set_uint (value, address->priv->flowinfo);
g_value_set_uint (value, g_inet_socket_address_get_flowinfo (address));
break;
case PROP_SCOPE_ID:
g_return_if_fail (g_inet_address_get_family (address->priv->address) == G_SOCKET_FAMILY_IPV6);
g_value_set_uint (value, address->priv->scope_id);
g_value_set_uint (value, g_inet_socket_address_get_scope_id (address));
break;
default:
@@ -220,8 +220,8 @@ g_inet_socket_address_to_native (GSocketAddress *address,
memset (sock, 0, sizeof (*sock));
sock->sin6_family = AF_INET6;
sock->sin6_port = g_htons (addr->priv->port);
sock->sin6_flowinfo = addr->priv->flowinfo;
sock->sin6_scope_id = addr->priv->scope_id;
sock->sin6_flowinfo = g_inet_socket_address_get_flowinfo (addr);
sock->sin6_scope_id = g_inet_socket_address_get_scope_id (addr);
memcpy (&(sock->sin6_addr.s6_addr), g_inet_address_to_bytes (addr->priv->address), sizeof (sock->sin6_addr));
return TRUE;
}
@@ -282,6 +282,8 @@ g_inet_socket_address_class_init (GInetSocketAddressClass *klass)
*
* The `sin6_flowinfo` field, for IPv6 addresses.
*
* If unset this property is inherited from [property@Gio.InetSocketAddress:address].
*
* Since: 2.32
*/
g_object_class_install_property (gobject_class, PROP_FLOWINFO,
@@ -298,6 +300,8 @@ g_inet_socket_address_class_init (GInetSocketAddressClass *klass)
*
* The `sin6_scope_id` field, for IPv6 addresses.
*
* If unset this property is inherited from [property@Gio.InetSocketAddress:address].
*
* Since: 2.32
*/
g_object_class_install_property (gobject_class, PROP_SCOPE_ID,
@@ -511,6 +515,8 @@ g_inet_socket_address_get_port (GInetSocketAddress *address)
* Gets the `sin6_flowinfo` field from @address,
* which must be an IPv6 address.
*
* If not overridden this value will be inherited from [property@Gio.InetSocketAddress:address].
*
* Returns: the flowinfo field
*
* Since: 2.32
@@ -521,7 +527,7 @@ g_inet_socket_address_get_flowinfo (GInetSocketAddress *address)
g_return_val_if_fail (G_IS_INET_SOCKET_ADDRESS (address), 0);
g_return_val_if_fail (g_inet_address_get_family (address->priv->address) == G_SOCKET_FAMILY_IPV6, 0);
return address->priv->flowinfo;
return address->priv->flowinfo ? address->priv->flowinfo : g_inet_address_get_flowinfo (address->priv->address);
}
/**
@@ -531,6 +537,8 @@ g_inet_socket_address_get_flowinfo (GInetSocketAddress *address)
* Gets the `sin6_scope_id` field from @address,
* which must be an IPv6 address.
*
* If not overridden this value will be inherited from [property@Gio.InetSocketAddress:address].
*
* Returns: the scope id field
*
* Since: 2.32
@@ -541,5 +549,5 @@ g_inet_socket_address_get_scope_id (GInetSocketAddress *address)
g_return_val_if_fail (G_IS_INET_SOCKET_ADDRESS (address), 0);
g_return_val_if_fail (g_inet_address_get_family (address->priv->address) == G_SOCKET_FAMILY_IPV6, 0);
return address->priv->scope_id;
return address->priv->scope_id ? address->priv->scope_id : g_inet_address_get_scope_id (address->priv->address);
}

View File

@@ -252,15 +252,13 @@ g_socket_address_new_from_native (gpointer native,
iaddr = g_inet_address_new_from_bytes ((guint8 *) &(sin_addr.sin_addr), G_SOCKET_FAMILY_IPV4);
}
else
{
iaddr = g_inet_address_new_from_bytes ((guint8 *) &(addr->sin6_addr), G_SOCKET_FAMILY_IPV6);
}
{
iaddr = g_inet_address_new_from_bytes_with_ipv6_info ((guint8 *) &(addr->sin6_addr), G_SOCKET_FAMILY_IPV6, addr->sin6_flowinfo, addr->sin6_scope_id);
}
sockaddr = g_object_new (G_TYPE_INET_SOCKET_ADDRESS,
"address", iaddr,
"port", g_ntohs (addr->sin6_port),
"flowinfo", addr->sin6_flowinfo,
"scope_id", addr->sin6_scope_id,
NULL);
g_object_unref (iaddr);
return sockaddr;