diff options
author | Guy Harris <guy@alum.mit.edu> | 2010-05-07 19:24:32 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2010-05-07 19:24:32 +0000 |
commit | 077ff72ac19c4c48a47f914615f3ddc50b086c72 (patch) | |
tree | 2489e60d99c5ab28316218fa2841a88a89fe8a18 /capture_opts.c | |
parent | 66f101f10fd9f48d543060f16f8f66de2de62a67 (diff) |
As with the list of data link types, so with the list of interfaces; move
the code to print the machine-readable format into dumpcap, and have the
code in capture_opts.c just print the human-readable format.
svn path=/trunk/; revision=32714
Diffstat (limited to 'capture_opts.c')
-rw-r--r-- | capture_opts.c | 88 |
1 files changed, 8 insertions, 80 deletions
diff --git a/capture_opts.c b/capture_opts.c index f69f791f08..54c328d070 100644 --- a/capture_opts.c +++ b/capture_opts.c @@ -591,35 +591,13 @@ capture_opts_print_link_layer_types(GList *lt_list) } } -/* Return an ASCII-formatted list of interfaces. */ -#define ADDRSTRLEN 46 /* Covers IPv4 & IPv6 */ -int -capture_opts_list_interfaces(gboolean machine_readable) +/* Print an ASCII-formatted list of interfaces. */ +void +capture_opts_print_interfaces(GList *if_list) { - GList *if_list; + int i; GList *if_entry; if_info_t *if_info; - int err; - gchar *err_str; - int i; - GSList *addr; - if_addr_t *if_addr; - char addr_str[ADDRSTRLEN]; - - if_list = capture_interface_list(&err, &err_str); - if (if_list == NULL) { - switch (err) { - case CANT_GET_INTERFACE_LIST: - cmdarg_err("%s", err_str); - g_free(err_str); - break; - - case NO_INTERFACES_FOUND: - cmdarg_err("There are no interfaces on which a capture can be done"); - break; - } - return err; - } i = 1; /* Interface id number */ for (if_entry = g_list_first(if_list); if_entry != NULL; @@ -627,61 +605,11 @@ capture_opts_list_interfaces(gboolean machine_readable) if_info = (if_info_t *)if_entry->data; printf("%d. %s", i++, if_info->name); - if (!machine_readable) { - /* Add the description if it exists */ - if (if_info->description != NULL) - printf(" (%s)", if_info->description); - } else { - /* - * Add the contents of the if_entry struct in a parseable format. - * Each if_entry element is tab-separated. Addresses are comma- - * separated. - */ - /* XXX - Make sure our description doesn't contain a tab */ - if (if_info->description != NULL) - printf("\t%s\t", if_info->description); - else - printf("\t\t"); - - for(addr = g_slist_nth(if_info->addrs, 0); addr != NULL; - addr = g_slist_next(addr)) { - if (addr != g_slist_nth(if_info->addrs, 0)) - printf(","); - - if_addr = (if_addr_t *)addr->data; - switch(if_addr->ifat_type) { - case IF_AT_IPv4: - if (inet_ntop(AF_INET, &if_addr->addr.ip4_addr, addr_str, - ADDRSTRLEN)) { - printf("%s", addr_str); - } else { - printf("<unknown IPv4>"); - } - break; - case IF_AT_IPv6: - if (inet_ntop(AF_INET6, &if_addr->addr.ip6_addr, - addr_str, ADDRSTRLEN)) { - printf("%s", addr_str); - } else { - printf("<unknown IPv6>"); - } - break; - default: - printf("<type unknown %u>", if_addr->ifat_type); - } - } - - if (if_info->loopback) - printf("\tloopback"); - else - printf("\tnetwork"); - - } - printf("\n"); + /* Print the description if it exists */ + if (if_info->description != NULL) + printf(" (%s)", if_info->description); + printf("\n"); } - free_interface_list(if_list); - - return 0; } |