ip_block * convert_ip4_routes_block (const char *conn_name) { gchar **ipset; guint length; guint i; gchar *ip; ip_block *start = NULL, *current = NULL, *iblock = NULL; g_return_val_if_fail (conn_name != NULL, NULL); ipset = split_routes (ifnet_get_data (conn_name, "routes")); length = ipset ? g_strv_length (ipset) : 0; for (i = 0; i < length; i++) { ip = ipset[i]; if (find_default_gateway_str (ip) || strstr (ip, "::") || !find_gateway_str (ip)) continue; ip = strip_string (ip, '"'); iblock = create_ip4_block (ip); if (iblock == NULL) continue; iblock->next_hop = get_ip4_gateway (ip); if (start == NULL) start = current = iblock; else { current->next = iblock; current = iblock; } } g_strfreev (ipset); return start; }
ip6_block * convert_ip6_routes_block (const char *conn_name) { gchar **ipset; guint length; guint i; gchar *ip, *tmp_addr; ip6_block *start = NULL, *current = NULL, *iblock = NULL; struct in6_addr *tmp_ip6_addr; g_return_val_if_fail (conn_name != NULL, NULL); ipset = split_routes (ifnet_get_data (conn_name, "routes")); length = ipset ? g_strv_length (ipset) : 0; for (i = 0; i < length; i++) { ip = ipset[i]; ip = strip_string (ip, '"'); if (ip[0] == '\0') continue; if ((tmp_addr = find_default_gateway_str (ip)) != NULL) { if (!is_ip6_address (tmp_addr)) continue; else { tmp_ip6_addr = g_slice_new0 (struct in6_addr); if (inet_pton (AF_INET6, "::", tmp_ip6_addr)) { iblock = g_slice_new0 (ip6_block); iblock->ip = tmp_ip6_addr; iblock->prefix = 128; } else { g_slice_free (struct in6_addr, tmp_ip6_addr); continue; } } } else iblock = create_ip6_block (ip); if (iblock == NULL) continue; iblock->next_hop = get_ip6_next_hop (ip); if (iblock->next_hop == NULL) { destroy_ip6_block (iblock); continue; } if (start == NULL) start = current = iblock; else { current->next = iblock; current = iblock; } }