本文整理汇总了C++中SnifferConfiguration::configure_sniffer_pre_activation方法的典型用法代码示例。如果您正苦于以下问题:C++ SnifferConfiguration::configure_sniffer_pre_activation方法的具体用法?C++ SnifferConfiguration::configure_sniffer_pre_activation怎么用?C++ SnifferConfiguration::configure_sniffer_pre_activation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SnifferConfiguration
的用法示例。
在下文中一共展示了SnifferConfiguration::configure_sniffer_pre_activation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
Sniffer::Sniffer(const string& device,
promisc_type promisc,
const string& filter,
bool rfmon) {
SnifferConfiguration configuration;
configuration.set_promisc_mode(promisc == PROMISC);
configuration.set_filter(filter);
configuration.set_rfmon(rfmon);
char error[PCAP_ERRBUF_SIZE];
pcap_t* phandle = pcap_create(TINS_PREFIX_INTERFACE(device).c_str(), error);
if (!phandle) {
throw runtime_error(error);
}
set_pcap_handle(phandle);
// Set the netmask if we are able to find it.
bpf_u_int32 ip, if_mask;
if (pcap_lookupnet(TINS_PREFIX_INTERFACE(device).c_str(), &ip, &if_mask, error) == 0) {
set_if_mask(if_mask);
}
// Configure the sniffer's attributes prior to activation.
configuration.configure_sniffer_pre_activation(*this);
// Finally, activate the pcap. In case of error throw runtime_error
if (pcap_activate(get_pcap_handle()) < 0) {
throw pcap_error(pcap_geterr(get_pcap_handle()));
}
// Configure the sniffer's attributes after activation.
configuration.configure_sniffer_post_activation(*this);
}
示例2: runtime_error
FileSniffer::FileSniffer(const string &file_name, const SnifferConfiguration& configuration) {
char error[PCAP_ERRBUF_SIZE];
pcap_t *phandle = pcap_open_offline(file_name.c_str(), error);
if(!phandle) {
throw std::runtime_error(error);
}
set_pcap_handle(phandle);
// Configure the sniffer
configuration.configure_sniffer_pre_activation(*this);
}
示例3: pcap_error
FileSniffer::FileSniffer(const string& file_name, const string& filter) {
SnifferConfiguration config;
config.set_filter(filter);
char error[PCAP_ERRBUF_SIZE];
pcap_t* phandle = pcap_open_offline(file_name.c_str(), error);
if (!phandle) {
throw pcap_error(error);
}
set_pcap_handle(phandle);
// Configure the sniffer
config.configure_sniffer_pre_activation(*this);
}