void nm_ip4_config_add_address (NMIP4Config *config, NMIP4Address *address) { NMIP4ConfigPrivate *priv; GSList *iter; g_return_if_fail (NM_IS_IP4_CONFIG (config)); g_return_if_fail (address != NULL); priv = NM_IP4_CONFIG_GET_PRIVATE (config); for (iter = priv->addresses; iter; iter = g_slist_next (iter)) { if (nm_ip4_address_compare ((NMIP4Address *) iter->data, address)) return; } priv->addresses = g_slist_append (priv->addresses, nm_ip4_address_dup (address)); }
/** * nm_setting_ip4_config_add_address: * @setting: the #NMSettingIP4Config * @address: the new address to add * * Adds a new IPv4 address and associated information to the setting. The * given address is duplicated internally and is not changed by this function. * * Returns: %TRUE if the address was added; %FALSE if the address was already * known. **/ gboolean nm_setting_ip4_config_add_address (NMSettingIP4Config *setting, NMIP4Address *address) { NMSettingIP4ConfigPrivate *priv; NMIP4Address *copy; GSList *iter; g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE); g_return_val_if_fail (address != NULL, FALSE); priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting); for (iter = priv->addresses; iter; iter = g_slist_next (iter)) { if (nm_ip4_address_compare ((NMIP4Address *) iter->data, address)) return FALSE; } copy = nm_ip4_address_dup (address); g_return_val_if_fail (copy != NULL, FALSE); priv->addresses = g_slist_append (priv->addresses, copy); return TRUE; }
static gboolean addr_slist_compare (GSList *a, GSList *b) { GSList *iter_a, *iter_b; gboolean found = FALSE; for (iter_a = a; iter_a; iter_a = g_slist_next (iter_a)) { NMIP4Address *addr_a = (NMIP4Address *) iter_a->data; for (iter_b = b, found = FALSE; iter_b; iter_b = g_slist_next (iter_b)) { NMIP4Address *addr_b = (NMIP4Address *) iter_b->data; if (nm_ip4_address_compare (addr_a, addr_b)) { found = TRUE; break; } } if (!found) return FALSE; } return TRUE; }