in src/controller/parameters.cpp [288:342]
const Parameters::CaptureParams Parameters::capture_params() const
{
Parameters::CaptureParams params;
params.interface = impl->get(CLI::ArgInterface);
params.filter = impl->get(CLI::ArgFilter);
params.snaplen = impl->get(CLI::ArgSnaplen).to_int();
params.timeout_ms = impl->get(CLI::ArgTimeout).to_int();
params.buffer_size = impl->get(CLI::ArgBSize).to_int() * 1024 * 1024; // MBytes
params.promisc = impl->get(CLI::ArgPromisc).to_bool();
// check interface
if(impl->is_default(CLI::ArgInterface))
{
params.interface = NST::filtration::pcap::NetworkInterfaces::default_device();
}
// check capture buffer size
if(params.buffer_size < 1024 * 1024) // less than 1 MBytes
{
throw cmdline::CLIError{std::string{"Invalid value of kernel buffer size: "} + impl->get(CLI::ArgBSize).to_cstr()};
}
// check max length of raw captured UDP packet
if(params.snaplen < 1 || params.snaplen > 65535)
{
throw cmdline::CLIError{std::string{"Invalid value of max length of raw captured UDP packet: "} + impl->get(CLI::ArgSnaplen).to_cstr()};
}
// check the read timeout that will be used on a capture
if(params.timeout_ms < 1)
{
throw cmdline::CLIError{std::string{"Invalid value of read timeout that will be used on a capture: "} + impl->get(CLI::ArgTimeout).to_cstr()};
}
// check and set capture direction
const auto& direction = impl->get(CLI::ArgDirection);
if(direction.is("in"))
{
params.direction = decltype(params.direction)::IN;
}
else if(direction.is("out"))
{
params.direction = decltype(params.direction)::OUT;
}
else if(direction.is("inout"))
{
params.direction = decltype(params.direction)::INOUT;
}
else
{
throw cmdline::CLIError{std::string{"Unknown capturing direction: "} + direction.to_cstr()};
}
return params;
}