- }
-
- /* Notify all registered modules that have had any of their preferences
- changed either from one of the preferences file or from the command
- line that their preferences have changed.
- Initialize preferences before display filters, otherwise modules
- like MATE won't work. */
- prefs_apply_all();
-
- /* Initialize our display fields */
- for (fc = 0; fc < disp_fields->len; fc++) {
- protocolinfo_init(g_ptr_array_index(disp_fields, fc));
- }
- g_ptr_array_free(disp_fields, TRUE);
- printf("\n");
- fflush(stdout);
-
- /* If no capture filter or read filter has been specified, and there are
- still command-line arguments, treat them as the tokens of a capture
- filter (if no "-r" flag was specified) or a read filter (if a "-r"
- flag was specified. */
- if (optind < argc) {
- if (pipe_name != NULL) {
- if (n_rfilters != 0) {
- cmdarg_err("Read filters were specified both with \"-R\" "
- "and with additional command-line arguments");
- exit(1);
- }
- rfilters[n_rfilters] = get_args_as_string(argc, argv, optind);
+
+#ifdef _WIN32
+ /* Load Wpcap, if possible */
+ load_wpcap();
+#endif
+
+ cap_file_init(&cfile);
+
+ /* Print format defaults to this. */
+ print_format = PR_FMT_TEXT;
+
+ /* Initialize our encapsulation type */
+ encap = WTAP_ENCAP_UNKNOWN;
+
+ /* Now get our args */
+ /* XXX - We should probably have an option to dump libpcap link types */
+ while ((opt = getopt(argc, argv, optstring)) != -1) {
+ switch (opt) {
+ case 'd': /* Payload type */
+ if (!set_link_type(optarg)) {
+ cmdarg_err("Invalid link type or protocol \"%s\"", optarg);
+ exit(1);
+ }
+ break;
+ case 'F': /* Read field to display */
+ g_ptr_array_add(disp_fields, g_strdup(optarg));
+ break;
+ case 'h': /* Print help and exit */
+ print_usage(TRUE);
+ exit(0);
+ break;
+ case 'l': /* "Line-buffer" standard output */
+ /* This isn't line-buffering, strictly speaking, it's just
+ flushing the standard output after the information for
+ each packet is printed; however, that should be good
+ enough for all the purposes to which "-l" is put (and
+ is probably actually better for "-V", as it does fewer
+ writes).
+
+ See the comment in "process_packet()" for an explanation of
+ why we do that, and why we don't just use "setvbuf()" to
+ make the standard output line-buffered (short version: in
+ Windows, "line-buffered" is the same as "fully-buffered",
+ and the output buffer is only flushed when it fills up). */
+ line_buffered = TRUE;
+ break;
+ case 'n': /* No name resolution */
+ gbl_resolv_flags.mac_name = FALSE;
+ gbl_resolv_flags.network_name = FALSE;
+ gbl_resolv_flags.transport_name = FALSE;
+ gbl_resolv_flags.concurrent_dns = FALSE;
+ break;
+ case 'N': /* Select what types of addresses/port #s to resolve */
+ badopt = string_to_name_resolve(optarg, &gbl_resolv_flags);
+ if (badopt != '\0') {
+ cmdarg_err("-N specifies unknown resolving option '%c'; valid options are 'm', 'n', and 't'",
+ badopt);
+ exit(1);
+ }
+ break;
+ case 'o': /* Override preference from command line */
+ switch (prefs_set_pref(optarg)) {
+
+ case PREFS_SET_OK:
+ break;
+
+ case PREFS_SET_SYNTAX_ERR:
+ cmdarg_err("Invalid -o flag \"%s\"", optarg);
+ exit(1);
+ break;
+
+ case PREFS_SET_NO_SUCH_PREF:
+ case PREFS_SET_OBSOLETE:
+ cmdarg_err("-o flag \"%s\" specifies unknown preference", optarg);
+ exit(1);
+ break;
+ }
+ break;
+ case 'p': /* Expect pcap_pkthdr packet headers, which may have 64-bit timestamps */
+ want_pcap_pkthdr = TRUE;
+ break;
+ case 'r': /* Read capture file xxx */
+ pipe_name = g_strdup(optarg);
+ break;
+ case 'R': /* Read file filter */
+ if(n_rfilters < (int) sizeof(rfilters) / (int) sizeof(rfilters[0])) {
+ rfilters[n_rfilters++] = optarg;
+ }
+ else {
+ cmdarg_err("Too many display filters");
+ exit(1);
+ }
+ break;
+ case 's': /* Skip PCAP header */
+ skip_pcap_header = TRUE;
+ break;
+ case 'S': /* Print string representations */
+ if (!parse_field_string_format(optarg)) {
+ cmdarg_err("Invalid field string format");
+ exit(1);
+ }
+ break;
+ case 't': /* Time stamp type */
+ if (strcmp(optarg, "r") == 0)
+ timestamp_set_type(TS_RELATIVE);
+ else if (strcmp(optarg, "a") == 0)
+ timestamp_set_type(TS_ABSOLUTE);
+ else if (strcmp(optarg, "ad") == 0)
+ timestamp_set_type(TS_ABSOLUTE_WITH_YMD);
+ else if (strcmp(optarg, "adoy") == 0)
+ timestamp_set_type(TS_ABSOLUTE_WITH_YDOY);
+ else if (strcmp(optarg, "d") == 0)
+ timestamp_set_type(TS_DELTA);
+ else if (strcmp(optarg, "dd") == 0)
+ timestamp_set_type(TS_DELTA_DIS);
+ else if (strcmp(optarg, "e") == 0)
+ timestamp_set_type(TS_EPOCH);
+ else if (strcmp(optarg, "u") == 0)
+ timestamp_set_type(TS_UTC);
+ else if (strcmp(optarg, "ud") == 0)
+ timestamp_set_type(TS_UTC_WITH_YMD);
+ else if (strcmp(optarg, "udoy") == 0)
+ timestamp_set_type(TS_UTC_WITH_YDOY);
+ else {
+ cmdarg_err("Invalid time stamp type \"%s\"",
+ optarg);
+ cmdarg_err_cont(
+"It must be \"a\" for absolute, \"ad\" for absolute with YYYY-MM-DD date,");
+ cmdarg_err_cont(
+"\"adoy\" for absolute with YYYY/DOY date, \"d\" for delta,");
+ cmdarg_err_cont(
+"\"dd\" for delta displayed, \"e\" for epoch, \"r\" for relative,");
+ cmdarg_err_cont(
+"\"u\" for absolute UTC, \"ud\" for absolute UTC with YYYY-MM-DD date,");
+ cmdarg_err_cont(
+"or \"udoy\" for absolute UTC with YYYY/DOY date.");
+ exit(1);
+ }
+ break;
+ case 'v': /* Show version and exit */
+ {
+ show_version(comp_info_str, runtime_info_str);
+ g_string_free(comp_info_str, TRUE);
+ g_string_free(runtime_info_str, TRUE);
+ exit(0);
+ break;
+ }
+ default:
+ case '?': /* Bad flag - print usage message */
+ print_usage(TRUE);
+ exit(1);
+ break;
+ }