mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Merge branch 'master' of github.com:mfontanini/libtins into develop
Conflicts: examples/dns_stats.cpp include/tins/sniffer.h src/sniffer.cpp
This commit is contained in:
@@ -94,9 +94,14 @@ int main(int argc, char* argv[]) {
|
||||
config.set_promisc_mode(true);
|
||||
config.set_filter("arp");
|
||||
|
||||
// Sniff on the provided interface in promiscuous mode
|
||||
Sniffer sniffer(argv[1], config);
|
||||
|
||||
// Only capture arp packets
|
||||
monitor.run(sniffer);
|
||||
try {
|
||||
// Sniff on the provided interface in promiscuous mode
|
||||
Sniffer sniffer(argv[1], config);
|
||||
|
||||
// Only capture arp packets
|
||||
monitor.run(sniffer);
|
||||
}
|
||||
catch (std::exception& ex) {
|
||||
std::cerr << "Error: " << ex.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ int main(int argc, char* argv[]) {
|
||||
auto info = monitor.stats().get_information();
|
||||
cout << "\rAverage " << info.average.count()
|
||||
<< "ms. Worst: " << info.worst.count() << "ms. Count: "
|
||||
<< info.count;
|
||||
<< info.count << " ";
|
||||
cout.flush();
|
||||
sleep_for(seconds(1));
|
||||
}
|
||||
|
||||
@@ -204,6 +204,14 @@ public:
|
||||
*/
|
||||
int get_fd();
|
||||
|
||||
/**
|
||||
* \brief Sets direction for the sniffer.
|
||||
*
|
||||
* This calls pcap_setdirection using the provided parameter.
|
||||
* \param d The direction for the sniffer.
|
||||
*/
|
||||
bool set_direction(pcap_direction_t d);
|
||||
|
||||
/**
|
||||
* \brief Sets the read timeout for this sniffer.
|
||||
*
|
||||
@@ -567,6 +575,12 @@ public:
|
||||
*/
|
||||
void set_timeout(unsigned timeout);
|
||||
|
||||
/**
|
||||
* Sets the direction option.
|
||||
* \param direction The direction to be set.
|
||||
*/
|
||||
void set_direction(pcap_direction_t direction);
|
||||
|
||||
/**
|
||||
* Sets the immediate mode option.
|
||||
* \param enabled The immediate mode option value.
|
||||
@@ -581,7 +595,8 @@ protected:
|
||||
PROMISCUOUS = 2,
|
||||
RFMON = 4,
|
||||
PACKET_FILTER = 8,
|
||||
IMMEDIATE_MODE = 16
|
||||
IMMEDIATE_MODE = 16,
|
||||
DIRECTION = 16
|
||||
};
|
||||
|
||||
void configure_sniffer_pre_activation(Sniffer& sniffer) const;
|
||||
@@ -597,6 +612,7 @@ protected:
|
||||
bool promisc_;
|
||||
bool rfmon_;
|
||||
bool immediate_mode_;
|
||||
pcap_direction_t direction_;
|
||||
};
|
||||
|
||||
template <typename Functor>
|
||||
|
||||
@@ -227,6 +227,11 @@ void BaseSniffer::set_timeout(int ms) {
|
||||
pcap_set_timeout(handle_, ms);
|
||||
}
|
||||
|
||||
bool BaseSniffer::set_direction(pcap_direction_t d) {
|
||||
bool result = pcap_setdirection(handle_, d) != -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
// ****************************** Sniffer ******************************
|
||||
|
||||
Sniffer::Sniffer(const string& device, const SnifferConfiguration& configuration) {
|
||||
@@ -438,6 +443,14 @@ void SnifferConfiguration::configure_sniffer_post_activation(Sniffer& sniffer) c
|
||||
throw invalid_pcap_filter(pcap_geterr(sniffer.get_pcap_handle()));
|
||||
}
|
||||
}
|
||||
// TODO: see how to actually do this on winpcap
|
||||
#ifndef _WIN32
|
||||
if ((flags_ & DIRECTION) != 0) {
|
||||
if (!sniffer.set_direction(direction_)) {
|
||||
throw pcap_error(pcap_geterr(sniffer.get_pcap_handle()));
|
||||
}
|
||||
}
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
||||
void SnifferConfiguration::set_snap_len(unsigned snap_len) {
|
||||
@@ -473,4 +486,9 @@ void SnifferConfiguration::set_immediate_mode(bool enabled) {
|
||||
immediate_mode_ = enabled;
|
||||
}
|
||||
|
||||
void SnifferConfiguration::set_direction(pcap_direction_t direction) {
|
||||
direction_ = direction;
|
||||
flags_ |= DIRECTION;
|
||||
}
|
||||
|
||||
} // Tins
|
||||
|
||||
Reference in New Issue
Block a user