pcap: unify -i and --pcap parsing

pull/2006/head
Victor Julien 10 years ago
parent b50111a5a7
commit a3a7d9b299

@ -1148,63 +1148,60 @@ static int ParseCommandLinePcapLive(SCInstance *suri, const char *optarg)
{ {
memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev)); memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev));
if (optarg == NULL) { if (optarg != NULL) {
SCLogError(SC_ERR_INITIALIZATION, "no option argument (optarg) for -i"); /* warn user if af-packet, netmap or pf-ring are available */
return TM_ECODE_FAILED;
}
/* warn user if af-packet, netmap or pf-ring are available */
#if defined HAVE_AF_PACKET || HAVE_PFRING || HAVE_NETMAP #if defined HAVE_AF_PACKET || HAVE_PFRING || HAVE_NETMAP
int i = 0; int i = 0;
#ifdef HAVE_AF_PACKET #ifdef HAVE_AF_PACKET
i++; i++;
#endif #endif
#ifdef HAVE_PFRING #ifdef HAVE_PFRING
i++; i++;
#endif #endif
#ifdef HAVE_NETMAP #ifdef HAVE_NETMAP
i++; i++;
#endif #endif
SCLogWarning(SC_WARN_FASTER_CAPTURE_AVAILABLE, "faster capture " SCLogWarning(SC_WARN_FASTER_CAPTURE_AVAILABLE, "faster capture "
"option%s %s available:" "option%s %s available:"
#ifdef HAVE_AF_PACKET #ifdef HAVE_AF_PACKET
" AF_PACKET (--af-packet=%s)" " AF_PACKET (--af-packet=%s)"
#endif #endif
#ifdef HAVE_PFRING #ifdef HAVE_PFRING
" PF_RING (--pfring-int=%s)" " PF_RING (--pfring-int=%s)"
#endif #endif
#ifdef HAVE_NETMAP #ifdef HAVE_NETMAP
" NETMAP (--netmap=%s)" " NETMAP (--netmap=%s)"
#endif #endif
". Use --pcap=%s to suppress this warning", ". Use --pcap=%s to suppress this warning",
i == 1 ? "" : "s", i == 1 ? "is" : "are" i == 1 ? "" : "s", i == 1 ? "is" : "are"
#ifdef HAVE_AF_PACKET #ifdef HAVE_AF_PACKET
, optarg , optarg
#endif #endif
#ifdef HAVE_PFRING #ifdef HAVE_PFRING
, optarg , optarg
#endif #endif
#ifdef HAVE_NETMAP #ifdef HAVE_NETMAP
, optarg , optarg
#endif #endif
, optarg , optarg
); );
#endif #endif
/* some windows shells require escaping of the \ in \Device. Otherwise /* some windows shells require escaping of the \ in \Device. Otherwise
* the backslashes are stripped. We put them back here. */ * the backslashes are stripped. We put them back here. */
if (strlen(optarg) > 9 && strncmp(optarg, "DeviceNPF", 9) == 0) { if (strlen(optarg) > 9 && strncmp(optarg, "DeviceNPF", 9) == 0) {
snprintf(suri->pcap_dev, sizeof(suri->pcap_dev), "\\Device\\NPF%s", optarg+9); snprintf(suri->pcap_dev, sizeof(suri->pcap_dev), "\\Device\\NPF%s", optarg+9);
} else { } else {
strlcpy(suri->pcap_dev, optarg, ((strlen(optarg) < sizeof(suri->pcap_dev)) ? (strlen(optarg)+1) : (sizeof(suri->pcap_dev)))); strlcpy(suri->pcap_dev, optarg, ((strlen(optarg) < sizeof(suri->pcap_dev)) ? (strlen(optarg)+1) : (sizeof(suri->pcap_dev))));
PcapTranslateIPToDevice(suri->pcap_dev, sizeof(suri->pcap_dev)); PcapTranslateIPToDevice(suri->pcap_dev, sizeof(suri->pcap_dev));
} }
if (strcmp(suri->pcap_dev, optarg) != 0) { if (strcmp(suri->pcap_dev, optarg) != 0) {
SCLogInfo("translated %s to pcap device %s", optarg, suri->pcap_dev); SCLogInfo("translated %s to pcap device %s", optarg, suri->pcap_dev);
} else if (strlen(suri->pcap_dev) > 0 && isdigit((unsigned char)suri->pcap_dev[0])) { } else if (strlen(suri->pcap_dev) > 0 && isdigit((unsigned char)suri->pcap_dev[0])) {
SCLogError(SC_ERR_PCAP_TRANSLATE, "failed to find a pcap device for IP %s", optarg); SCLogError(SC_ERR_PCAP_TRANSLATE, "failed to find a pcap device for IP %s", optarg);
return TM_ECODE_FAILED; return TM_ECODE_FAILED;
}
} }
if (suri->run_mode == RUNMODE_UNKNOWN) { if (suri->run_mode == RUNMODE_UNKNOWN) {
@ -1420,29 +1417,7 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
return TM_ECODE_FAILED; return TM_ECODE_FAILED;
#endif /* HAVE_NFLOG */ #endif /* HAVE_NFLOG */
} else if (strcmp((long_opts[option_index]).name , "pcap") == 0) { } else if (strcmp((long_opts[option_index]).name , "pcap") == 0) {
if (suri->run_mode == RUNMODE_UNKNOWN) { if (ParseCommandLinePcapLive(suri, optarg) != TM_ECODE_OK) {
suri->run_mode = RUNMODE_PCAP_DEV;
if (optarg) {
LiveRegisterDevice(optarg);
memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev));
strlcpy(suri->pcap_dev, optarg,
((strlen(optarg) < sizeof(suri->pcap_dev)) ?
(strlen(optarg) + 1) : sizeof(suri->pcap_dev)));
}
} else if (suri->run_mode == RUNMODE_PCAP_DEV) {
#ifdef OS_WIN32
SCLogError(SC_ERR_PCAP_MULTI_DEV_NO_SUPPORT, "pcap multi dev "
"support is not (yet) supported on Windows.");
return TM_ECODE_FAILED;
#else
SCLogWarning(SC_WARN_PCAP_MULTI_DEV_EXPERIMENTAL, "using "
"multiple pcap devices to get packets is experimental.");
LiveRegisterDevice(optarg);
#endif
} else {
SCLogError(SC_ERR_MULTIPLE_RUN_MODE, "more than one run mode "
"has been specified");
usage(argv[0]);
return TM_ECODE_FAILED; return TM_ECODE_FAILED;
} }
#ifdef AFLFUZZ_APPLAYER #ifdef AFLFUZZ_APPLAYER

Loading…
Cancel
Save