fprintf(output, " -y <link type> link layer type (def: first appropriate)\n");
fprintf(output, " -D print list of interfaces and exit\n");
fprintf(output, " -L print list of link-layer types of iface and exit\n");
+ fprintf(output, " -M for -D and -L, produce machine-readable output\n");
fprintf(output, "\n");
fprintf(output, "Stop conditions:\n");
fprintf(output, " -c <packet count> stop after n packets (def: infinite)\n");
va_list ap;
if(capture_child) {
- /* XXX - convert to g_log */
+ /* Print a bare error */
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
} else {
va_start(ap, fmt);
fprintf(stderr, "dumpcap: ");
gboolean stats_known;
struct pcap_stat stats;
GLogLevelFlags log_flags;
+ gboolean list_interfaces = FALSE;
gboolean list_link_layer_types = FALSE;
+ gboolean machine_readable = FALSE;
int status;
-#define OPTSTRING_INIT "a:b:c:Df:hi:Lps:vw:y:Z"
+#define OPTSTRING_INIT "a:b:c:Df:hi:LMps:vw:y:Z"
#ifdef _WIN32
#define OPTSTRING_WIN32 "B:"
/* the default_log_handler will use stdout, which makes trouble in */
/* capture child mode, as it uses stdout for it's sync_pipe */
/* so do the filtering in the console_log_handler and not here */
- log_flags =
+ log_flags =
G_LOG_LEVEL_ERROR|
G_LOG_LEVEL_CRITICAL|
G_LOG_LEVEL_WARNING|
log_flags,
console_log_handler, NULL /* user_data */);
- /* Set the initial values in the capture_opts. This might be overwritten
+ /* Set the initial values in the capture_opts. This might be overwritten
by the command line parameters. */
capture_opts_init(capture_opts, NULL);
/* Assemble the run-time version information string */
runtime_info_str = g_string_new("Running ");
- get_runtime_version_info(runtime_info_str, NULL);
+ get_runtime_version_info(runtime_info_str, NULL);
show_version(comp_info_str, runtime_info_str);
g_string_free(comp_info_str, TRUE);
g_string_free(runtime_info_str, TRUE);
/*** all non capture option specific ***/
case 'D': /* Print a list of capture devices and exit */
- status = capture_opts_list_interfaces();
- exit_main(status);
+ list_interfaces = TRUE;
break;
case 'L': /* Print list of link-layer types and exit */
list_link_layer_types = TRUE;
break;
+ case 'M': /* For -D and -L, print machine-readable output */
+ machine_readable = TRUE;
+ break;
default:
case '?': /* Bad flag - print usage message */
cmdarg_err("Invalid Option: %s", argv[optind-1]);
exit_main(1);
}
- if (list_link_layer_types) {
+ if (list_interfaces && list_link_layer_types) {
+ cmdarg_err("Only one of -D or -L may be supplied.");
+ exit_main(1);
+ } else if (list_link_layer_types) {
/* We're supposed to list the link-layer types for an interface;
did the user also specify a capture file to be read? */
/* No - did they specify a ring buffer option? */
/* get_interface_descriptive_name() is not available! */
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Interface: %s\n", capture_opts->iface);
- if (list_link_layer_types) {
- status = capture_opts_list_link_layer_types(capture_opts);
+ if (list_interfaces) {
+ status = capture_opts_list_interfaces(machine_readable);
+ exit_main(status);
+ } else if (list_link_layer_types) {
+ status = capture_opts_list_link_layer_types(capture_opts, machine_readable);
exit_main(status);
}
/* create a "timestamp" */
time(&curr);
- today = localtime(&curr);
+ today = localtime(&curr);
switch(log_level & G_LOG_LEVEL_MASK) {
case G_LOG_LEVEL_ERROR:
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Capture filter error: %s", errmsg);
pipe_write_block(1, SP_BAD_FILTER, errmsg);
} else {
- fprintf(stderr,
+ fprintf(stderr,
"Invalid capture filter: \"%s\"!\n"
"\n"
"That string isn't a valid capture filter (%s).\n"
report_capture_error(const char *error_msg, const char *secondary_error_msg)
{
if(capture_child) {
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
"Primary Error: %s", error_msg);
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
"Secondary Error: %s", secondary_error_msg);
sync_pipe_errmsg_to_parent(error_msg, secondary_error_msg);
} else {