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
This commit is contained in:
parent
66f101f10f
commit
077ff72ac1
|
@ -591,35 +591,13 @@ capture_opts_print_link_layer_types(GList *lt_list)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return an ASCII-formatted list of interfaces. */
|
/* Print an ASCII-formatted list of interfaces. */
|
||||||
#define ADDRSTRLEN 46 /* Covers IPv4 & IPv6 */
|
void
|
||||||
int
|
capture_opts_print_interfaces(GList *if_list)
|
||||||
capture_opts_list_interfaces(gboolean machine_readable)
|
|
||||||
{
|
{
|
||||||
GList *if_list;
|
int i;
|
||||||
GList *if_entry;
|
GList *if_entry;
|
||||||
if_info_t *if_info;
|
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 */
|
i = 1; /* Interface id number */
|
||||||
for (if_entry = g_list_first(if_list); if_entry != NULL;
|
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;
|
if_info = (if_info_t *)if_entry->data;
|
||||||
printf("%d. %s", i++, if_info->name);
|
printf("%d. %s", i++, if_info->name);
|
||||||
|
|
||||||
if (!machine_readable) {
|
/* Print the description if it exists */
|
||||||
/* Add the description if it exists */
|
if (if_info->description != NULL)
|
||||||
if (if_info->description != NULL)
|
printf(" (%s)", if_info->description);
|
||||||
printf(" (%s)", if_info->description);
|
printf("\n");
|
||||||
} 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");
|
|
||||||
}
|
}
|
||||||
free_interface_list(if_list);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -179,9 +179,9 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio
|
||||||
extern void
|
extern void
|
||||||
capture_opts_print_link_layer_types(GList *lt_list);
|
capture_opts_print_link_layer_types(GList *lt_list);
|
||||||
|
|
||||||
/* list interfaces */
|
/* print list of interfaces */
|
||||||
extern int
|
extern void
|
||||||
capture_opts_list_interfaces(gboolean machine_readable);
|
capture_opts_print_interfaces(GList *if_list);
|
||||||
|
|
||||||
/* trim the snaplen entry */
|
/* trim the snaplen entry */
|
||||||
extern void
|
extern void
|
||||||
|
|
97
dumpcap.c
97
dumpcap.c
|
@ -48,6 +48,10 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_ARPA_INET_H
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__) && defined(__LP64__)
|
#if defined(__APPLE__) && defined(__LP64__)
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -577,6 +581,71 @@ get_pcap_linktype_list(const char *devname, char **err_str)
|
||||||
return linktype_list;
|
return linktype_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ADDRSTRLEN 46 /* Covers IPv4 & IPv6 */
|
||||||
|
static void
|
||||||
|
print_machine_readable_interfaces(GList *if_list)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
GList *if_entry;
|
||||||
|
if_info_t *if_info;
|
||||||
|
GSList *addr;
|
||||||
|
if_addr_t *if_addr;
|
||||||
|
char addr_str[ADDRSTRLEN];
|
||||||
|
|
||||||
|
i = 1; /* Interface id number */
|
||||||
|
for (if_entry = g_list_first(if_list); if_entry != NULL;
|
||||||
|
if_entry = g_list_next(if_entry)) {
|
||||||
|
if_info = (if_info_t *)if_entry->data;
|
||||||
|
printf("%d. %s", i++, if_info->name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If you change the machine-readable output format of this function,
|
* If you change the machine-readable output format of this function,
|
||||||
* you MUST update capture_sync.c:sync_linktype_list_open() accordingly!
|
* you MUST update capture_sync.c:sync_linktype_list_open() accordingly!
|
||||||
|
@ -3270,8 +3339,32 @@ main(int argc, char *argv[])
|
||||||
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Interface: %s\n", global_capture_opts.iface);
|
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Interface: %s\n", global_capture_opts.iface);
|
||||||
|
|
||||||
if (list_interfaces) {
|
if (list_interfaces) {
|
||||||
status = capture_opts_list_interfaces(machine_readable);
|
/* Get the list of interfaces */
|
||||||
exit_main(status);
|
GList *if_list;
|
||||||
|
int err;
|
||||||
|
gchar *err_str;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
exit_main(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (machine_readable) /* tab-separated values to stdout */
|
||||||
|
print_machine_readable_interfaces(if_list);
|
||||||
|
else
|
||||||
|
capture_opts_print_interfaces(if_list);
|
||||||
|
free_interface_list(if_list);
|
||||||
|
exit_main(0);
|
||||||
} else if (list_link_layer_types) {
|
} else if (list_link_layer_types) {
|
||||||
/* Get the list of link-layer types for the capture device. */
|
/* Get the list of link-layer types for the capture device. */
|
||||||
GList *lt_list;
|
GList *lt_list;
|
||||||
|
|
19
gtk/main.c
19
gtk/main.c
|
@ -2015,6 +2015,8 @@ main(int argc, char *argv[])
|
||||||
#ifdef HAVE_LIBPCAP
|
#ifdef HAVE_LIBPCAP
|
||||||
gboolean start_capture = FALSE;
|
gboolean start_capture = FALSE;
|
||||||
gboolean list_link_layer_types = FALSE;
|
gboolean list_link_layer_types = FALSE;
|
||||||
|
GList *if_list;
|
||||||
|
gchar *err_str;
|
||||||
#else
|
#else
|
||||||
gboolean capture_option_specified = FALSE;
|
gboolean capture_option_specified = FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
@ -2451,7 +2453,22 @@ main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
case 'D': /* Print a list of capture devices and exit */
|
case 'D': /* Print a list of capture devices and exit */
|
||||||
#ifdef HAVE_LIBPCAP
|
#ifdef HAVE_LIBPCAP
|
||||||
capture_opts_list_interfaces(FALSE);
|
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;
|
||||||
|
}
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
capture_opts_print_interfaces(if_list);
|
||||||
|
free_interface_list(if_list);
|
||||||
exit(0);
|
exit(0);
|
||||||
#else
|
#else
|
||||||
capture_option_specified = TRUE;
|
capture_option_specified = TRUE;
|
||||||
|
|
21
tshark.c
21
tshark.c
|
@ -757,6 +757,8 @@ main(int argc, char *argv[])
|
||||||
gboolean list_link_layer_types = FALSE;
|
gboolean list_link_layer_types = FALSE;
|
||||||
gboolean start_capture = FALSE;
|
gboolean start_capture = FALSE;
|
||||||
int status;
|
int status;
|
||||||
|
GList *if_list;
|
||||||
|
gchar *err_str;
|
||||||
#else
|
#else
|
||||||
gboolean capture_option_specified = FALSE;
|
gboolean capture_option_specified = FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1046,8 +1048,23 @@ main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
case 'D': /* Print a list of capture devices and exit */
|
case 'D': /* Print a list of capture devices and exit */
|
||||||
#ifdef HAVE_LIBPCAP
|
#ifdef HAVE_LIBPCAP
|
||||||
status = capture_opts_list_interfaces(FALSE);
|
if_list = capture_interface_list(&err, &err_str);
|
||||||
exit(status);
|
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;
|
||||||
|
}
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
capture_opts_print_interfaces(if_list);
|
||||||
|
free_interface_list(if_list);
|
||||||
|
exit(0);
|
||||||
#else
|
#else
|
||||||
capture_option_specified = TRUE;
|
capture_option_specified = TRUE;
|
||||||
arg_error = TRUE;
|
arg_error = TRUE;
|
||||||
|
|
Loading…
Reference in New Issue