mirror of
https://github.com/mfontanini/libtins
synced 2026-01-22 18:25:57 +01:00
Add FileSniffer constructor with FILE pointer as pcap source (#499)
This commit is contained in:
@@ -406,10 +406,17 @@ private:
|
||||
*/
|
||||
class TINS_API FileSniffer : public BaseSniffer {
|
||||
public:
|
||||
/**
|
||||
* \brief Constructs an instance of FileSniffer.
|
||||
* \param fp The pcap file which will be parsed.
|
||||
* \param configuration A SnifferConfiguration to be used on the file.
|
||||
*/
|
||||
FileSniffer(FILE *fp, const SnifferConfiguration& configuration);
|
||||
|
||||
/**
|
||||
* \brief Constructs an instance of FileSniffer.
|
||||
* \param file_name The pcap file which will be parsed.
|
||||
* \param filter A capture filter to be used on the file.(optional);
|
||||
* \param configuration A SnifferConfiguration to be used on the file.
|
||||
*/
|
||||
FileSniffer(const std::string& file_name, const SnifferConfiguration& configuration);
|
||||
|
||||
@@ -418,9 +425,18 @@ public:
|
||||
*
|
||||
* \brief Constructs an instance of FileSniffer.
|
||||
* \param file_name The pcap file which will be parsed.
|
||||
* \param filter A capture filter to be used on the file.(optional);
|
||||
* \param filter A capture filter to be used on the file. (optional)
|
||||
*/
|
||||
FileSniffer(const std::string& file_name, const std::string& filter = "");
|
||||
|
||||
/**
|
||||
* \deprecated Use the constructor that takes a SnifferConfiguration instead.
|
||||
*
|
||||
* \brief Constructs an instance of FileSniffer.
|
||||
* \param fp The pcap file which will be parsed.
|
||||
* \param filter A capture filter to be used on the file. (optional)
|
||||
*/
|
||||
FileSniffer(FILE *fp, const std::string& filter = "");
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -391,6 +391,20 @@ void Sniffer::set_rfmon(bool rfmon_enabled) {
|
||||
|
||||
// **************************** FileSniffer ****************************
|
||||
|
||||
FileSniffer::FileSniffer(FILE *fp,
|
||||
const SnifferConfiguration& configuration) {
|
||||
char error[PCAP_ERRBUF_SIZE];
|
||||
pcap_t* phandle = pcap_fopen_offline(fp, error);
|
||||
if (!phandle) {
|
||||
throw pcap_error(error);
|
||||
}
|
||||
set_pcap_handle(phandle);
|
||||
|
||||
// Configure the sniffer
|
||||
configuration.configure_sniffer_pre_activation(*this);
|
||||
|
||||
}
|
||||
|
||||
FileSniffer::FileSniffer(const string& file_name,
|
||||
const SnifferConfiguration& configuration) {
|
||||
char error[PCAP_ERRBUF_SIZE];
|
||||
@@ -420,6 +434,22 @@ FileSniffer::FileSniffer(const string& file_name, const string& filter) {
|
||||
config.configure_sniffer_pre_activation(*this);
|
||||
}
|
||||
|
||||
FileSniffer::FileSniffer(FILE *fp, const string& filter) {
|
||||
SnifferConfiguration config;
|
||||
config.set_filter(filter);
|
||||
|
||||
char error[PCAP_ERRBUF_SIZE];
|
||||
pcap_t* phandle = pcap_fopen_offline(fp, error);
|
||||
if (!phandle) {
|
||||
throw pcap_error(error);
|
||||
}
|
||||
set_pcap_handle(phandle);
|
||||
|
||||
// Configure the sniffer
|
||||
config.configure_sniffer_pre_activation(*this);
|
||||
}
|
||||
|
||||
|
||||
// ************************ SnifferConfiguration ************************
|
||||
|
||||
const unsigned SnifferConfiguration::DEFAULT_SNAP_LEN = 65535;
|
||||
|
||||
Reference in New Issue
Block a user