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);
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");
}
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;
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) */
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;
break;
case 'e':
- ++eflag;
+ ++gndo->ndo_eflag;
break;
case 'E':
break;
case 'f':
- ++fflag;
+ ++gndo->ndo_fflag;
break;
case 'F':
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));
}
break;
case 'H':
- ++Hflag;
+ ++gndo->ndo_Hflag;
break;
case 'i':
#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;
break;
case 'K':
- ++Kflag;
+ ++gndo->ndo_Kflag;
break;
case 'm':
#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
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':
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':
show_devices_and_exit();
#endif
- switch (tflag) {
+ switch (gndo->ndo_tflag) {
case 0: /* Default */
case 4: /* Default + Date*/
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)
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",
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));
(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);
}
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);
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);
*/
capng_update(
CAPNG_DROP,
- (Cflag || Gflag ? 0 : CAPNG_PERMITTED)
+ (gndo->ndo_Cflag || gndo->ndo_Gflag ? 0 : CAPNG_PERMITTED)
| CAPNG_EFFECTIVE,
CAP_DAC_OVERRIDE
);
#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),
pcap_userdata = (u_char *)p;
}
#ifdef HAVE_PCAP_DUMP_FLUSH
- if (Uflag)
+ if (gndo->ndo_Uflag)
pcap_dump_flush(p);
#endif
} else {
(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
* 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);
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);
}
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));
* 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;
/* 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.
*/
* 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 */
}
* 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);
* 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;
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);
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
pcap_dump(user, h, sp);
#ifdef HAVE_PCAP_DUMP_FLUSH
- if (Uflag)
+ if (gndo->ndo_Uflag)
pcap_dump_flush((pcap_dumper_t *)user);
#endif