diff options
-rw-r--r-- | capture.h | 2 | ||||
-rw-r--r-- | capture_opts.c | 56 | ||||
-rw-r--r-- | gtk/main.c | 4 | ||||
-rw-r--r-- | tethereal.c | 46 |
4 files changed, 33 insertions, 75 deletions
@@ -93,7 +93,7 @@ extern void capture_opts_init(capture_options *capture_opts, void *cfile); extern void -capture_opt_add(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture); +capture_opts_add_opt(capture_options *capture_opts, const char *appname, int opt, const char *optarg, gboolean *start_capture); /** * Open a specified file, or create a temporary file, and start a capture diff --git a/capture_opts.c b/capture_opts.c index 39350851b9..884599c6ec 100644 --- a/capture_opts.c +++ b/capture_opts.c @@ -81,25 +81,25 @@ capture_opts_init(capture_options *capture_opts, void *cfile) } static int -get_natural_int(const char *string, const char *name) +get_natural_int(const char *appname, const char *string, const char *name) { long number; char *p; number = strtol(string, &p, 10); if (p == string || *p != '\0') { - fprintf(stderr, "ethereal: The specified %s \"%s\" isn't a decimal number\n", - name, string); + fprintf(stderr, "%s: The specified %s \"%s\" isn't a decimal number\n", + appname, name, string); exit(1); } if (number < 0) { - fprintf(stderr, "ethereal: The specified %s \"%s\" is a negative number\n", - name, string); + fprintf(stderr, "%s: The specified %s \"%s\" is a negative number\n", + appname, name, string); exit(1); } if (number > INT_MAX) { - fprintf(stderr, "ethereal: The specified %s \"%s\" is too large (greater than %d)\n", - name, string, INT_MAX); + fprintf(stderr, "%s: The specified %s \"%s\" is too large (greater than %d)\n", + appname, name, string, INT_MAX); exit(1); } return number; @@ -107,15 +107,15 @@ get_natural_int(const char *string, const char *name) static int -get_positive_int(const char *string, const char *name) +get_positive_int(const char *appname, const char *string, const char *name) { long number; - number = get_natural_int(string, name); + number = get_natural_int(appname, string, name); if (number == 0) { - fprintf(stderr, "ethereal: The specified %s is zero\n", - name); + fprintf(stderr, "%s: The specified %s is zero\n", + appname, name); exit(1); } @@ -130,7 +130,7 @@ get_positive_int(const char *string, const char *name) * in some fashion. */ static gboolean -set_autostop_criterion(capture_options *capture_opts, const char *autostoparg) +set_autostop_criterion(capture_options *capture_opts, const char *appname, const char *autostoparg) { gchar *p, *colonp; @@ -159,14 +159,14 @@ set_autostop_criterion(capture_options *capture_opts, const char *autostoparg) } if (strcmp(autostoparg,"duration") == 0) { capture_opts->has_autostop_duration = TRUE; - capture_opts->autostop_duration = get_positive_int(p,"autostop duration"); + capture_opts->autostop_duration = get_positive_int(appname, p,"autostop duration"); } else if (strcmp(autostoparg,"filesize") == 0) { capture_opts->has_autostop_filesize = TRUE; - capture_opts->autostop_filesize = get_positive_int(p,"autostop filesize"); + capture_opts->autostop_filesize = get_positive_int(appname, p,"autostop filesize"); } else if (strcmp(autostoparg,"files") == 0) { capture_opts->multi_files_on = TRUE; capture_opts->has_autostop_files = TRUE; - capture_opts->autostop_files = get_positive_int(p,"autostop files"); + capture_opts->autostop_files = get_positive_int(appname, p,"autostop files"); } else { return FALSE; } @@ -181,7 +181,7 @@ set_autostop_criterion(capture_options *capture_opts, const char *autostoparg) * in some fashion. */ static gboolean -get_ring_arguments(capture_options *capture_opts, const char *arg) +get_ring_arguments(capture_options *capture_opts, const char *appname, const char *arg) { gchar *p = NULL, *colonp; @@ -193,7 +193,7 @@ get_ring_arguments(capture_options *capture_opts, const char *arg) } capture_opts->ring_num_files = - get_natural_int(arg, "number of ring buffer files"); + get_natural_int(appname, arg, "number of ring buffer files"); if (colonp == NULL) return TRUE; @@ -216,7 +216,7 @@ get_ring_arguments(capture_options *capture_opts, const char *arg) } capture_opts->has_file_duration = TRUE; - capture_opts->file_duration = get_positive_int(p, + capture_opts->file_duration = get_positive_int(appname, p, "ring buffer duration"); *colonp = ':'; /* put the colon back */ @@ -225,7 +225,7 @@ get_ring_arguments(capture_options *capture_opts, const char *arg) void -capture_opt_add(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture) +capture_opts_add_opt(capture_options *capture_opts, const char *appname, int opt, const char *optarg, gboolean *start_capture) { #ifdef _WIN32 int i; @@ -233,22 +233,22 @@ capture_opt_add(capture_options *capture_opts, int opt, const char *optarg, gboo switch(opt) { case 'a': /* autostop criteria */ - if (set_autostop_criterion(capture_opts, optarg) == FALSE) { - fprintf(stderr, "ethereal: Invalid or unknown -a flag \"%s\"\n", optarg); + if (set_autostop_criterion(capture_opts, appname, optarg) == FALSE) { + fprintf(stderr, "%s: Invalid or unknown -a flag \"%s\"\n", appname, optarg); exit(1); } break; case 'b': /* Ringbuffer option */ capture_opts->multi_files_on = TRUE; capture_opts->has_ring_num_files = TRUE; - if (get_ring_arguments(capture_opts, optarg) == FALSE) { - fprintf(stderr, "ethereal: Invalid or unknown -b arg \"%s\"\n", optarg); + if (get_ring_arguments(capture_opts, appname, optarg) == FALSE) { + fprintf(stderr, "%s: Invalid or unknown -b arg \"%s\"\n", appname, optarg); exit(1); } break; case 'c': /* Capture xxx packets */ capture_opts->has_autostop_packets = TRUE; - capture_opts->autostop_packets = get_positive_int(optarg, "packet count"); + capture_opts->autostop_packets = get_positive_int(appname, optarg, "packet count"); break; case 'f': /* capture filter */ if (capture_opts->cfilter) @@ -274,7 +274,7 @@ capture_opt_add(capture_options *capture_opts, int opt, const char *optarg, gboo break; case 's': /* Set the snapshot (capture) length */ capture_opts->has_snaplen = TRUE; - capture_opts->snaplen = get_positive_int(optarg, "snapshot length"); + capture_opts->snaplen = get_positive_int(appname, optarg, "snapshot length"); break; case 'S': /* "Sync" mode: used for following file ala tail -f */ capture_opts->sync_mode = TRUE; @@ -289,8 +289,8 @@ capture_opt_add(capture_options *capture_opts, int opt, const char *optarg, gboo #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL capture_opts->linktype = pcap_datalink_name_to_val(optarg); if (capture_opts->linktype == -1) { - fprintf(stderr, "ethereal: The specified data link type \"%s\" isn't valid\n", - optarg); + fprintf(stderr, "%s: The specified data link type \"%s\" isn't valid\n", + appname, optarg); exit(1); } #else /* HAVE_PCAP_DATALINK_NAME_TO_VAL */ @@ -304,7 +304,7 @@ capture_opt_add(capture_options *capture_opts, int opt, const char *optarg, gboo /* associate stdout with pipe */ i = atoi(optarg); if (dup2(i, 1) < 0) { - fprintf(stderr, "Unable to dup pipe handle\n"); + fprintf(stderr, "%s: Unable to dup pipe handle\n", appname); exit(1); } break; diff --git a/gtk/main.c b/gtk/main.c index abb88f89a1..b9b199b393 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1877,7 +1877,7 @@ main(int argc, char *argv[]) case 'Z': /* Write to pipe FD XXX */ #endif /* _WIN32 */ #ifdef HAVE_LIBPCAP - capture_opt_add(capture_opts, opt, optarg, &start_capture); + capture_opts_add_opt(capture_opts, "ethereal", opt, optarg, &start_capture); #else capture_option_specified = TRUE; arg_error = TRUE; @@ -1888,7 +1888,7 @@ main(int argc, char *argv[]) * the error flags for the user in the non-libpcap case. */ case 'W': /* Write to capture file FD xxx */ - capture_opt_add(capture_opts, opt, optarg, &start_capture); + capture_opts_add_opt(capture_opts, "ethereal", opt, optarg, &start_capture); break; #endif diff --git a/tethereal.c b/tethereal.c index bdee92e93c..824c68880a 100644 --- a/tethereal.c +++ b/tethereal.c @@ -169,51 +169,8 @@ typedef struct _loop_data { static loop_data ld; #ifdef HAVE_LIBPCAP -#if 0 -typedef struct { - gchar *cfilter; /* Capture filter string */ - gchar *iface; /* the network interface to capture from */ - int snaplen; /* Maximum captured packet length */ - int promisc_mode; /* Capture in promiscuous mode */ - int autostop_packets; /* Maximum packet count */ - gboolean has_autostop_duration; /* TRUE if maximum capture duration - is specified */ - gint32 autostop_duration; /* Maximum capture duration */ - gboolean has_autostop_filesize; /* TRUE if maximum capture file size - is specified */ - gint32 autostop_filesize; /* Maximum capture file size */ - gboolean multi_files_on; /* TRUE if ring buffer in use */ - guint32 ring_num_files; /* Number of ring buffer files */ - gboolean has_file_duration; /* TRUE if ring duration specified */ - gint32 file_duration; /* Switch file after n seconds */ - int linktype; /* Data link type to use, or -1 for - "use default" */ -} capture_options; - -static capture_options capture_opts = { - "", /* No capture filter string specified */ - NULL, /* Default is "pick the first interface" */ - WTAP_MAX_PACKET_SIZE, /* snapshot length - default is - infinite, in effect */ - TRUE, /* promiscuous mode is the default */ - 0, /* max packet count - default is 0, - meaning infinite */ - FALSE, /* maximum capture duration not - specified by default */ - 0, /* maximum capture duration */ - FALSE, /* maximum capture file size not - specified by default */ - 0, /* maximum capture file size */ - FALSE, /* ring buffer off by default */ - RINGBUFFER_MIN_NUM_FILES, /* default number of ring buffer files */ - FALSE, /* Switch ring file after some */ - 0, /* specified time is off by default */ - -1 /* Default to not change link type */ -}; -#endif /* 0 */ static capture_options capture_opts; -static gboolean list_link_layer_types; #ifdef SIGINFO static gboolean infodelay; /* if TRUE, don't print capture info in SIGINFO handler */ @@ -704,6 +661,7 @@ main(int argc, char *argv[]) char *p; gchar err_str[PCAP_ERRBUF_SIZE]; gchar *cant_get_if_list_errstr; + gboolean list_link_layer_types; #else gboolean capture_option_specified = FALSE; #endif @@ -846,7 +804,7 @@ main(int argc, char *argv[]) case 's': /* Set the snapshot (capture) length */ case 'y': /* Set the pcap data link type */ #ifdef HAVE_LIBPCAP - capture_opt_add(&capture_opts, opt, optarg, &start_capture); + capture_opts_add_opt(&capture_opts, "tethereal", opt, optarg, &start_capture); #else capture_option_specified = TRUE; arg_error = TRUE; |