gboolean print_ip6_config (NMIP6Config *cfg6, NmCli *nmc, const char *group_prefix) { GSList *list, *iter; const GPtrArray *ptr_array; char **addr_arr = NULL; char **route_arr = NULL; char **dns_arr = NULL; char **domain_arr = NULL; int i = 0; guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; if (cfg6 == NULL) return FALSE; nmc->allowed_fields = nmc_fields_ip6_config; nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES; nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_IP6_CONFIG_ALL, nmc->allowed_fields, NULL); print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */ /* addresses */ list = (GSList *) nm_ip6_config_get_addresses (cfg6); addr_arr = g_new (char *, g_slist_length (list) + 1); for (iter = list; iter; iter = g_slist_next (iter)) { NMIP6Address *addr = (NMIP6Address *) iter->data; guint32 prefix; char *ip_str, *gw_str; ip_str = nmc_ip6_address_as_string (nm_ip6_address_get_address (addr), NULL); prefix = nm_ip6_address_get_prefix (addr); gw_str = nmc_ip6_address_as_string (nm_ip6_address_get_gateway (addr), NULL); addr_arr[i++] = g_strdup_printf ("ip = %s/%u, gw = %s", ip_str, prefix, gw_str); g_free (ip_str); g_free (gw_str); } addr_arr[i] = NULL; /* routes */ list = (GSList *) nm_ip6_config_get_routes (cfg6); route_arr = g_new (char *, g_slist_length (list) + 1); i = 0; for (iter = list; iter; iter = g_slist_next (iter)) { NMIP6Route *route = (NMIP6Route *) iter->data; guint32 prefix, metric; char *dest_str, *nexthop_str; dest_str = nmc_ip6_address_as_string (nm_ip6_route_get_dest (route), NULL); nexthop_str = nmc_ip6_address_as_string (nm_ip6_route_get_next_hop (route), NULL); prefix = nm_ip6_route_get_prefix (route); metric = nm_ip6_route_get_metric (route); route_arr[i++] = g_strdup_printf ("dst = %s/%u, nh = %s, mt = %u", dest_str, prefix, nexthop_str, metric); g_free (dest_str); g_free (nexthop_str); } route_arr[i] = NULL; /* DNS */ list = (GSList *) nm_ip6_config_get_nameservers (cfg6); dns_arr = g_new (char *, g_slist_length (list) + 1); i = 0; for (iter = list; iter; iter = g_slist_next (iter)) dns_arr[i++] = nmc_ip6_address_as_string (iter->data, NULL); dns_arr[i] = NULL; /* domains */ ptr_array = nm_ip6_config_get_domains (cfg6); if (ptr_array) { domain_arr = g_new (char *, ptr_array->len + 1); for (i = 0; i < ptr_array->len; i++) domain_arr[i] = g_ptr_array_index (ptr_array, i); domain_arr[i] = NULL; } set_val_str (nmc->allowed_fields, 0, group_prefix); set_val_arr (nmc->allowed_fields, 1, (const char **) addr_arr); set_val_arr (nmc->allowed_fields, 2, (const char **) route_arr); set_val_arr (nmc->allowed_fields, 3, (const char **) dns_arr); set_val_arr (nmc->allowed_fields, 4, (const char **) domain_arr); nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX; print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ g_strfreev (addr_arr); g_strfreev (route_arr); g_strfreev (dns_arr); g_free (domain_arr); return TRUE; }
gboolean print_ip6_config (NMIP6Config *cfg6, NmCli *nmc, const char *group_prefix, const char *one_field) { GSList *list, *iter; const GPtrArray *ptr_array; char **addr_arr = NULL; char **route_arr = NULL; char **dns_arr = NULL; char **domain_arr = NULL; int i = 0; NmcOutputField *tmpl, *arr; size_t tmpl_len; if (cfg6 == NULL) return FALSE; tmpl = nmc_fields_ip6_config; tmpl_len = sizeof (nmc_fields_ip6_config); nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP6_CONFIG_ALL, tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (nmc->output_data, arr); /* addresses */ list = (GSList *) nm_ip6_config_get_addresses (cfg6); addr_arr = g_new (char *, g_slist_length (list) + 1); for (iter = list; iter; iter = g_slist_next (iter)) { NMIP6Address *addr = (NMIP6Address *) iter->data; guint32 prefix; char *ip_str, *gw_str; ip_str = nmc_ip6_address_as_string (nm_ip6_address_get_address (addr), NULL); prefix = nm_ip6_address_get_prefix (addr); gw_str = nmc_ip6_address_as_string (nm_ip6_address_get_gateway (addr), NULL); addr_arr[i++] = g_strdup_printf ("ip = %s/%u, gw = %s", ip_str, prefix, gw_str); g_free (ip_str); g_free (gw_str); } addr_arr[i] = NULL; /* routes */ list = (GSList *) nm_ip6_config_get_routes (cfg6); route_arr = g_new (char *, g_slist_length (list) + 1); i = 0; for (iter = list; iter; iter = g_slist_next (iter)) { NMIP6Route *route = (NMIP6Route *) iter->data; guint32 prefix, metric; char *dest_str, *nexthop_str; dest_str = nmc_ip6_address_as_string (nm_ip6_route_get_dest (route), NULL); nexthop_str = nmc_ip6_address_as_string (nm_ip6_route_get_next_hop (route), NULL); prefix = nm_ip6_route_get_prefix (route); metric = nm_ip6_route_get_metric (route); route_arr[i++] = g_strdup_printf ("dst = %s/%u, nh = %s, mt = %u", dest_str, prefix, nexthop_str, metric); g_free (dest_str); g_free (nexthop_str); } route_arr[i] = NULL; /* DNS */ list = (GSList *) nm_ip6_config_get_nameservers (cfg6); dns_arr = g_new (char *, g_slist_length (list) + 1); i = 0; for (iter = list; iter; iter = g_slist_next (iter)) dns_arr[i++] = nmc_ip6_address_as_string (iter->data, NULL); dns_arr[i] = NULL; /* domains */ ptr_array = nm_ip6_config_get_domains (cfg6); if (ptr_array) { domain_arr = g_new (char *, ptr_array->len + 1); for (i = 0; i < ptr_array->len; i++) domain_arr[i] = g_strdup (g_ptr_array_index (ptr_array, i)); domain_arr[i] = NULL; } arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); set_val_strc (arr, 0, group_prefix); set_val_arr (arr, 1, addr_arr); set_val_arr (arr, 2, route_arr); set_val_arr (arr, 3, dns_arr); set_val_arr (arr, 4, domain_arr); g_ptr_array_add (nmc->output_data, arr); print_data (nmc); /* Print all data */ /* Remove any previous data */ nmc_empty_output_fields (nmc); return TRUE; }