1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Modified some examples fixed some doxygen documentation.

This commit is contained in:
Matias Fontanini
2013-10-06 23:00:20 -03:00
parent 58e2c93e30
commit 01b2a9c7b2
17 changed files with 74 additions and 83 deletions

View File

@@ -54,7 +54,7 @@ typedef std::pair<Sniffer*, std::string> sniffer_data;
* the scanned port's status.
*/
bool handler(PDU &pdu) {
TCP &tcp = pdu.rfind_pdu<TCP>();
const TCP &tcp = pdu.rfind_pdu<TCP>();
// Ok, it's a TCP PDU. Is RST flag on? Then port is closed.
if(tcp.get_flag(TCP::RST)) {
// This indicates we should stop sniffing.
@@ -63,7 +63,7 @@ bool handler(PDU &pdu) {
cout << "Port: " << setw(5) << tcp.sport() << " closed\n";
}
// Is SYN flag on? Then port is open!
else if(tcp.get_flag(TCP::SYN) && tcp.get_flag(TCP::ACK))
else if(tcp.flags() == (TCP::SYN | TCP::ACK))
cout << "Port: " << setw(5) << tcp.sport() << " open\n";
return true;
}
@@ -79,7 +79,7 @@ void send_syns(const NetworkInterface &iface, IPv4Address dest_ip, const vector<
TCP &tcp = ip.rfind_pdu<TCP>();
// Set the SYN flag on.
tcp.set_flag(TCP::SYN, 1);
// Just some arbitrary port.
// Just some random port.
tcp.sport(1337);
cout << "Sending SYNs..." << endl;
for(vector<string>::const_iterator it = ips.begin(); it != ips.end(); ++it) {

View File

@@ -54,7 +54,11 @@ public:
PacketSender sender;
// Create our handler
auto handler = make_sniffer_handler(this, &Traceroute::sniff_callback);
auto handler = std::bind(
&Traceroute::sniff_callback,
this,
std::placeholders::_1
);
// We're running
running = true;
// Start the sniff thread
@@ -98,10 +102,10 @@ private:
}
bool sniff_callback(PDU &pdu) {
IP &ip = pdu.rfind_pdu<IP>();
const IP &ip = pdu.rfind_pdu<IP>();
ttl_map::const_iterator iter;
// Fetch the IP PDU attached to the ICMP response
IP inner_ip = pdu.rfind_pdu<RawPDU>().to<IP>();
const IP inner_ip = pdu.rfind_pdu<RawPDU>().to<IP>();
// Critical section
{
std::lock_guard<std::mutex> _(lock);