diff options
Diffstat (limited to 'tcpdump.c')
-rw-r--r-- | tcpdump.c | 206 |
1 files changed, 103 insertions, 103 deletions
@@ -507,7 +507,7 @@ show_dlts_and_exit(const char *device, pcap_t *pd) if (supports_monitor_mode) (void) fprintf(stderr, "Data link types for %s %s (use option -y to set):\n", device, - Iflag ? "when in monitor mode" : "when not in monitor mode"); + gndo->ndo_Iflag ? "when in monitor mode" : "when not in monitor mode"); else (void) fprintf(stderr, "Data link types for %s (use option -y to set):\n", device); @@ -790,11 +790,11 @@ MakeFilename(char *buffer, char *orig_name, int cnt, int max_chars) error("Makefilename: malloc"); /* Process with strftime if Gflag is set. */ - if (Gflag != 0) { + if (gndo->ndo_Gflag != 0) { struct tm *local_tm; /* Convert Gflag_time to a usable format */ - if ((local_tm = localtime(&Gflag_time)) == NULL) { + if ((local_tm = localtime(&gndo->ndo_Gflag_time)) == NULL) { error("MakeTimedFilename: localtime"); } @@ -1001,7 +1001,7 @@ main(int argc, char **argv) if(wsockinit() != 0) return 1; #endif /* WIN32 */ - jflag=-1; /* not set */ + gndo->ndo_jflag=-1; /* not set */ gndo->ndo_Oflag=1; gndo->ndo_Rflag=1; gndo->ndo_dlt=-1; @@ -1048,17 +1048,17 @@ main(int argc, char **argv) break; case 'A': - ++Aflag; + ++gndo->ndo_Aflag; break; case 'b': - ++bflag; + ++gndo->ndo_bflag; break; #if defined(HAVE_PCAP_CREATE) || defined(WIN32) case 'B': - Bflag = atoi(optarg)*1024; - if (Bflag <= 0) + gndo->ndo_Bflag = atoi(optarg)*1024; + if (gndo->ndo_Bflag <= 0) error("invalid packet buffer size %s", optarg); break; #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */ @@ -1070,8 +1070,8 @@ main(int argc, char **argv) break; case 'C': - Cflag = atoi(optarg) * 1000000; - if (Cflag < 0) + gndo->ndo_Cflag = atoi(optarg) * 1000000; + if (gndo->ndo_Cflag < 0) error("invalid file size %s", optarg); break; @@ -1088,7 +1088,7 @@ main(int argc, char **argv) break; case 'e': - ++eflag; + ++gndo->ndo_eflag; break; case 'E': @@ -1099,7 +1099,7 @@ main(int argc, char **argv) break; case 'f': - ++fflag; + ++gndo->ndo_fflag; break; case 'F': @@ -1107,15 +1107,15 @@ main(int argc, char **argv) break; case 'G': - Gflag = atoi(optarg); - if (Gflag < 0) + gndo->ndo_Gflag = atoi(optarg); + if (gndo->ndo_Gflag < 0) error("invalid number of seconds %s", optarg); /* We will create one file initially. */ - Gflag_count = 0; + gndo->ndo_Gflag_count = 0; /* Grab the current time for rotation use. */ - if ((Gflag_time = time(NULL)) == (time_t)-1) { + if ((gndo->ndo_Gflag_time = time(NULL)) == (time_t)-1) { error("main: can't get current time: %s", pcap_strerror(errno)); } @@ -1127,7 +1127,7 @@ main(int argc, char **argv) break; case 'H': - ++Hflag; + ++gndo->ndo_Hflag; break; case 'i': @@ -1174,14 +1174,14 @@ main(int argc, char **argv) #ifdef HAVE_PCAP_CREATE case 'I': - ++Iflag; + ++gndo->ndo_Iflag; break; #endif /* HAVE_PCAP_CREATE */ #ifdef HAVE_PCAP_SET_TSTAMP_TYPE case 'j': - jflag = pcap_tstamp_type_name_to_val(optarg); - if (jflag < 0) + gndo->ndo_jflag = pcap_tstamp_type_name_to_val(optarg); + if (gndo->ndo_jflag < 0) error("invalid time stamp type %s", optarg); break; @@ -1212,7 +1212,7 @@ main(int argc, char **argv) break; case 'K': - ++Kflag; + ++gndo->ndo_Kflag; break; case 'm': @@ -1233,28 +1233,28 @@ main(int argc, char **argv) #ifndef HAVE_LIBCRYPTO warning("crypto code not compiled in"); #endif - sigsecret = optarg; + gndo->ndo_sigsecret = optarg; break; case 'n': - ++nflag; + ++gndo->ndo_nflag; break; case 'N': - ++Nflag; + ++gndo->ndo_Nflag; break; case 'O': - Oflag = 0; + gndo->ndo_Oflag = 0; break; case 'p': - ++pflag; + ++gndo->ndo_pflag; break; case 'q': - ++qflag; - ++suppress_default_print; + ++gndo->ndo_qflag; + ++gndo->ndo_suppress_default_print; break; #ifdef HAVE_PCAP_SETDIRECTION @@ -1275,75 +1275,75 @@ main(int argc, char **argv) break; case 'R': - Rflag = 0; + gndo->ndo_Rflag = 0; break; case 's': - snaplen = strtol(optarg, &end, 0); + gndo->ndo_snaplen = strtol(optarg, &end, 0); if (optarg == end || *end != '\0' - || snaplen < 0 || snaplen > MAXIMUM_SNAPLEN) + || gndo->ndo_snaplen < 0 || gndo->ndo_snaplen > MAXIMUM_SNAPLEN) error("invalid snaplen %s", optarg); - else if (snaplen == 0) - snaplen = MAXIMUM_SNAPLEN; + else if (gndo->ndo_snaplen == 0) + gndo->ndo_snaplen = MAXIMUM_SNAPLEN; break; case 'S': - ++Sflag; + ++gndo->ndo_Sflag; break; case 't': - ++tflag; + ++gndo->ndo_tflag; break; case 'T': if (strcasecmp(optarg, "vat") == 0) - packettype = PT_VAT; + gndo->ndo_packettype = PT_VAT; else if (strcasecmp(optarg, "wb") == 0) - packettype = PT_WB; + gndo->ndo_packettype = PT_WB; else if (strcasecmp(optarg, "rpc") == 0) - packettype = PT_RPC; + gndo->ndo_packettype = PT_RPC; else if (strcasecmp(optarg, "rtp") == 0) - packettype = PT_RTP; + gndo->ndo_packettype = PT_RTP; else if (strcasecmp(optarg, "rtcp") == 0) - packettype = PT_RTCP; + gndo->ndo_packettype = PT_RTCP; else if (strcasecmp(optarg, "snmp") == 0) - packettype = PT_SNMP; + gndo->ndo_packettype = PT_SNMP; else if (strcasecmp(optarg, "cnfp") == 0) - packettype = PT_CNFP; + gndo->ndo_packettype = PT_CNFP; else if (strcasecmp(optarg, "tftp") == 0) - packettype = PT_TFTP; + gndo->ndo_packettype = PT_TFTP; else if (strcasecmp(optarg, "aodv") == 0) - packettype = PT_AODV; + gndo->ndo_packettype = PT_AODV; else if (strcasecmp(optarg, "carp") == 0) - packettype = PT_CARP; + gndo->ndo_packettype = PT_CARP; else if (strcasecmp(optarg, "radius") == 0) - packettype = PT_RADIUS; + gndo->ndo_packettype = PT_RADIUS; else if (strcasecmp(optarg, "zmtp1") == 0) - packettype = PT_ZMTP1; + gndo->ndo_packettype = PT_ZMTP1; else if (strcasecmp(optarg, "vxlan") == 0) - packettype = PT_VXLAN; + gndo->ndo_packettype = PT_VXLAN; else if (strcasecmp(optarg, "pgm") == 0) - packettype = PT_PGM; + gndo->ndo_packettype = PT_PGM; else if (strcasecmp(optarg, "pgm_zmtp1") == 0) - packettype = PT_PGM_ZMTP1; + gndo->ndo_packettype = PT_PGM_ZMTP1; else if (strcasecmp(optarg, "lmp") == 0) - packettype = PT_LMP; + gndo->ndo_packettype = PT_LMP; else error("unknown packet type `%s'", optarg); break; case 'u': - ++uflag; + ++gndo->ndo_uflag; break; #ifdef HAVE_PCAP_DUMP_FLUSH case 'U': - ++Uflag; + ++gndo->ndo_Uflag; break; #endif case 'v': - ++vflag; + ++gndo->ndo_vflag; break; case 'V': @@ -1355,20 +1355,20 @@ main(int argc, char **argv) break; case 'W': - Wflag = atoi(optarg); - if (Wflag < 0) + gndo->ndo_Wflag = atoi(optarg); + if (gndo->ndo_Wflag < 0) error("invalid number of output files %s", optarg); - WflagChars = getWflagChars(Wflag); + gndo->ndo_WflagChars = getWflagChars(gndo->ndo_Wflag); break; case 'x': - ++xflag; - ++suppress_default_print; + ++gndo->ndo_xflag; + ++gndo->ndo_suppress_default_print; break; case 'X': - ++Xflag; - ++suppress_default_print; + ++gndo->ndo_Xflag; + ++gndo->ndo_suppress_default_print; break; case 'y': @@ -1435,7 +1435,7 @@ main(int argc, char **argv) show_devices_and_exit(); #endif - switch (tflag) { + switch (gndo->ndo_tflag) { case 0: /* Default */ case 4: /* Default + Date*/ @@ -1453,7 +1453,7 @@ main(int argc, char **argv) break; } - if (fflag != 0 && (VFileName != NULL || RFileName != NULL)) + if (gndo->ndo_fflag != 0 && (VFileName != NULL || RFileName != NULL)) error("-f can not be used with -V or -r"); if (VFileName != NULL && RFileName != NULL) @@ -1611,15 +1611,15 @@ main(int argc, char **argv) supports_monitor_mode = 1; else supports_monitor_mode = 0; - status = pcap_set_snaplen(pd, snaplen); + status = pcap_set_snaplen(pd, gndo->ndo_snaplen); if (status != 0) error("%s: Can't set snapshot length: %s", device, pcap_statustostr(status)); - status = pcap_set_promisc(pd, !pflag); + status = pcap_set_promisc(pd, !gndo->ndo_pflag); if (status != 0) error("%s: Can't set promiscuous mode: %s", device, pcap_statustostr(status)); - if (Iflag) { + if (gndo->ndo_Iflag) { status = pcap_set_rfmon(pd, 1); if (status != 0) error("%s: Can't set monitor mode: %s", @@ -1629,15 +1629,15 @@ main(int argc, char **argv) if (status != 0) error("%s: pcap_set_timeout failed: %s", device, pcap_statustostr(status)); - if (Bflag != 0) { - status = pcap_set_buffer_size(pd, Bflag); + if (gndo->ndo_Bflag != 0) { + status = pcap_set_buffer_size(pd, gndo->ndo_Bflag); if (status != 0) error("%s: Can't set buffer size: %s", device, pcap_statustostr(status)); } #ifdef HAVE_PCAP_SET_TSTAMP_TYPE - if (jflag != -1) { - status = pcap_set_tstamp_type(pd, jflag); + if (gndo->ndo_jflag != -1) { + status = pcap_set_tstamp_type(pd, gndo->ndo_jflag); if (status < 0) error("%s: Can't set time stamp type: %s", device, pcap_statustostr(status)); @@ -1726,11 +1726,11 @@ main(int argc, char **argv) (void)fflush(stderr); } i = pcap_snapshot(pd); - if (snaplen < i) { - warning("snaplen raised from %d to %d", snaplen, i); - snaplen = i; + if (gndo->ndo_snaplen < i) { + warning("snaplen raised from %d to %d", gndo->ndo_snaplen, i); + gndo->ndo_snaplen = i; } - if(fflag != 0) { + if(gndo->ndo_fflag != 0) { if (pcap_lookupnet(device, &localnet, &netmask, ebuf) < 0) { warning("foreign (-f) flag used but: %s", ebuf); } @@ -1742,7 +1742,7 @@ main(int argc, char **argv) else cmdbuf = copy_argv(&argv[optind]); - if (pcap_compile(pd, &fcode, cmdbuf, Oflag, netmask) < 0) + if (pcap_compile(pd, &fcode, cmdbuf, gndo->ndo_Oflag, netmask) < 0) error("%s", pcap_geterr(pd)); if (dflag) { bpf_dump(&fcode, dflag); @@ -1840,8 +1840,8 @@ main(int argc, char **argv) error("malloc of dumpinfo.CurrentFileName"); /* We do not need numbering for dumpfiles if Cflag isn't set. */ - if (Cflag != 0) - MakeFilename(dumpinfo.CurrentFileName, WFileName, 0, WflagChars); + if (gndo->ndo_Cflag != 0) + MakeFilename(dumpinfo.CurrentFileName, WFileName, 0, gndo->ndo_WflagChars); else MakeFilename(dumpinfo.CurrentFileName, WFileName, 0, 0); @@ -1853,7 +1853,7 @@ main(int argc, char **argv) */ capng_update( CAPNG_DROP, - (Cflag || Gflag ? 0 : CAPNG_PERMITTED) + (gndo->ndo_Cflag || gndo->ndo_Gflag ? 0 : CAPNG_PERMITTED) | CAPNG_EFFECTIVE, CAP_DAC_OVERRIDE ); @@ -1864,7 +1864,7 @@ main(int argc, char **argv) #ifdef HAVE_CAPSICUM set_dumper_capsicum_rights(p); #endif - if (Cflag != 0 || Gflag != 0) { + if (gndo->ndo_Cflag != 0 || gndo->ndo_Gflag != 0) { #ifdef HAVE_CAPSICUM dumpinfo.WFileName = strdup(basename(WFileName)); dumpinfo.dirfd = open(dirname(WFileName), @@ -1895,7 +1895,7 @@ main(int argc, char **argv) pcap_userdata = (u_char *)p; } #ifdef HAVE_PCAP_DUMP_FLUSH - if (Uflag) + if (gndo->ndo_Uflag) pcap_dump_flush(p); #endif } else { @@ -1914,7 +1914,7 @@ main(int argc, char **argv) (void)setsignal(SIGNAL_REQ_INFO, requestinfo); #endif - if (vflag > 0 && WFileName) { + if (gndo->ndo_vflag > 0 && WFileName) { /* * When capturing to a file, "-v" means tcpdump should, * every 10 secodns, "v"erbosely report the number of @@ -1937,7 +1937,7 @@ main(int argc, char **argv) * to a file from the -V file). Print a message to * the standard error on UN*X. */ - if (!vflag && !WFileName) { + if (!gndo->ndo_vflag && !WFileName) { (void)fprintf(stderr, "%s: verbose output suppressed, use -v or -vv for full protocol decode\n", program_name); @@ -1947,11 +1947,11 @@ main(int argc, char **argv) dlt_name = pcap_datalink_val_to_name(dlt); if (dlt_name == NULL) { (void)fprintf(stderr, "listening on %s, link-type %u, capture size %u bytes\n", - device, dlt, snaplen); + device, dlt, gndo->ndo_snaplen); } else { (void)fprintf(stderr, "listening on %s, link-type %s (%s), capture size %u bytes\n", device, dlt_name, - pcap_datalink_val_to_description(dlt), snaplen); + pcap_datalink_val_to_description(dlt), gndo->ndo_snaplen); } (void)fflush(stderr); } @@ -2033,7 +2033,7 @@ main(int argc, char **argv) RFileName, dlt_name, pcap_datalink_val_to_description(new_dlt)); } - if (pcap_compile(pd, &fcode, cmdbuf, Oflag, netmask) < 0) + if (pcap_compile(pd, &fcode, cmdbuf, gndo->ndo_Oflag, netmask) < 0) error("%s", pcap_geterr(pd)); if (pcap_setfilter(pd, &fcode) < 0) error("%s", pcap_geterr(pd)); @@ -2202,7 +2202,7 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s * first thereby cancelling the Cflag boundary (since the file should * be 0). */ - if (Gflag != 0) { + if (gndo->ndo_Gflag != 0) { /* Check if it is time to rotate */ time_t t; @@ -2214,16 +2214,16 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s /* If the time is greater than the specified window, rotate */ - if (t - Gflag_time >= Gflag) { + if (t - gndo->ndo_Gflag_time >= gndo->ndo_Gflag) { #ifdef HAVE_CAPSICUM FILE *fp; int fd; #endif /* Update the Gflag_time */ - Gflag_time = t; + gndo->ndo_Gflag_time = t; /* Update Gflag_count */ - Gflag_count++; + gndo->ndo_Gflag_count++; /* * Close the current file and open a new one. */ @@ -2239,9 +2239,9 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s * Check to see if we've exceeded the Wflag (when * not using Cflag). */ - if (Cflag == 0 && Wflag > 0 && Gflag_count >= Wflag) { + if (gndo->ndo_Cflag == 0 && gndo->ndo_Wflag > 0 && gndo->ndo_Gflag_count >= gndo->ndo_Wflag) { (void)fprintf(stderr, "Maximum file limit reached: %d\n", - Wflag); + gndo->ndo_Wflag); exit(0); /* NOTREACHED */ } @@ -2256,16 +2256,16 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s * so multiple files would end with 1,2,3 in the filename. * The counting is handled with the -C flow after this. */ - Cflag_count = 0; + gndo->ndo_Cflag_count = 0; /* * This is always the first file in the Cflag * rotation: e.g. 0 * We also don't need numbering if Cflag is not set. */ - if (Cflag != 0) + if (gndo->ndo_Cflag != 0) MakeFilename(dump_info->CurrentFileName, dump_info->WFileName, 0, - WflagChars); + gndo->ndo_WflagChars); else MakeFilename(dump_info->CurrentFileName, dump_info->WFileName, 0, 0); @@ -2307,12 +2307,12 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s * larger than Cflag - the last packet written to the * file could put it over Cflag. */ - if (Cflag != 0) { + if (gndo->ndo_Cflag != 0) { long size = pcap_dump_ftell(dump_info->p); if (size == -1) error("ftell fails on output file"); - if (size > Cflag) { + if (size > gndo->ndo_Cflag) { #ifdef HAVE_CAPSICUM FILE *fp; int fd; @@ -2330,17 +2330,17 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s if (zflag != NULL) compress_savefile(dump_info->CurrentFileName); - Cflag_count++; - if (Wflag > 0) { - if (Cflag_count >= Wflag) - Cflag_count = 0; + gndo->ndo_Cflag_count++; + if (gndo->ndo_Wflag > 0) { + if (gndo->ndo_Cflag_count >= gndo->ndo_Wflag) + gndo->ndo_Cflag_count = 0; } if (dump_info->CurrentFileName != NULL) free(dump_info->CurrentFileName); dump_info->CurrentFileName = (char *)malloc(PATH_MAX + 1); if (dump_info->CurrentFileName == NULL) error("dump_packet_and_trunc: malloc"); - MakeFilename(dump_info->CurrentFileName, dump_info->WFileName, Cflag_count, WflagChars); + MakeFilename(dump_info->CurrentFileName, dump_info->WFileName, gndo->ndo_Cflag_count, gndo->ndo_WflagChars); #ifdef HAVE_LIBCAP_NG capng_update(CAPNG_ADD, CAPNG_EFFECTIVE, CAP_DAC_OVERRIDE); capng_apply(CAPNG_SELECT_BOTH); @@ -2375,7 +2375,7 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s pcap_dump((u_char *)dump_info->p, h, sp); #ifdef HAVE_PCAP_DUMP_FLUSH - if (Uflag) + if (gndo->ndo_Uflag) pcap_dump_flush(dump_info->p); #endif @@ -2393,7 +2393,7 @@ dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) pcap_dump(user, h, sp); #ifdef HAVE_PCAP_DUMP_FLUSH - if (Uflag) + if (gndo->ndo_Uflag) pcap_dump_flush((pcap_dumper_t *)user); #endif |