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

Fix example compilation on Windows.

Fixes #75.
This commit is contained in:
Matias Fontanini
2015-06-02 21:52:40 -07:00
parent 0f3441ccf6
commit 43217549eb
4 changed files with 41 additions and 22 deletions

View File

@@ -3,7 +3,10 @@ FIND_PACKAGE(Threads QUIET)
IF(libtins_FOUND)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
INCLUDE_DIRECTORIES(${LIBTINS_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(
${LIBTINS_INCLUDE_DIRS}
${PCAP_INCLUDE_DIR}
)
LINK_LIBRARIES(${LIBTINS_LIBRARIES})
IF(HAVE_CXX11)
@@ -32,7 +35,6 @@ IF(libtins_FOUND)
ADD_EXECUTABLE(arpmonitor EXCLUDE_FROM_ALL arpmonitor.cpp)
ADD_EXECUTABLE(dns_queries EXCLUDE_FROM_ALL dns_queries.cpp)
ADD_EXECUTABLE(dns_spoof EXCLUDE_FROM_ALL dns_spoof.cpp)
ADD_EXECUTABLE(dns_stats EXCLUDE_FROM_ALL dns_stats.cpp)
ADD_EXECUTABLE(wps_detect EXCLUDE_FROM_ALL wps_detect.cpp)
ENDIF(HAVE_CXX11)
@@ -41,14 +43,19 @@ IF(libtins_FOUND)
if(THREADS_FOUND)
IF(HAVE_CXX11)
ADD_EXECUTABLE(traceroute EXCLUDE_FROM_ALL traceroute.cpp)
ADD_EXECUTABLE(dns_stats EXCLUDE_FROM_ALL dns_stats.cpp)
TARGET_LINK_LIBRARIES(traceroute ${CMAKE_THREAD_LIBS_INIT})
TARGET_LINK_LIBRARIES(dns_stats ${CMAKE_THREAD_LIBS_INIT})
ENDIF(HAVE_CXX11)
ADD_EXECUTABLE(portscan EXCLUDE_FROM_ALL portscan.cpp)
TARGET_LINK_LIBRARIES(portscan ${CMAKE_THREAD_LIBS_INIT})
ELSE(THREADS_FOUND)
IF(WIN32)
MESSAGE(WARNING "Disabling portscan example since it doesn't compile on Windows.")
ELSE()
ADD_EXECUTABLE(portscan EXCLUDE_FROM_ALL portscan.cpp)
TARGET_LINK_LIBRARIES(portscan ${CMAKE_THREAD_LIBS_INIT})
ENDIF()
ELSE()
MESSAGE(WARNING "Disabling portscan and traceroute examples since pthreads library was not found.")
ENDIF(THREADS_FOUND)
ENDIF()
ELSE(libtins_FOUND)
MESSAGE(
WARNING

View File

@@ -32,7 +32,12 @@
#include <string>
#include <stdexcept>
#include <cstdlib>
#include <unistd.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <unistd.h>
#endif // _WIN32
#include <tins/arp.h>
#include <tins/network_interface.h>
#include <tins/utils.h>
@@ -78,7 +83,11 @@ void do_arp_spoofing(NetworkInterface iface, IPv4Address gw, IPv4Address victim,
// Just send them once every 5 seconds.
sender.send(to_gw, iface);
sender.send(to_victim, iface);
sleep(5);
#ifdef _WIN32
Sleep(5);
#else
sleep(5);
#endif
}
}

View File

@@ -96,8 +96,8 @@ public:
}
private:
using packet_info = std::tuple<IPv4Address, IPv4Address, uint16_t>;
using clock_type = std::chrono::steady_clock;
using time_point_type = std::chrono::time_point<clock_type>;
using clock_type = std::chrono::system_clock;
using time_point_type = clock_type::time_point;
bool callback(const PDU& pdu);
static packet_info make_packet_info(const PDU& pdu, const DNS& dns);
@@ -161,15 +161,20 @@ auto dns_monitor::make_packet_info(const PDU& pdu, const DNS& dns) -> packet_inf
}
int main(int argc, char *argv[]) {
if(argc != 2) {
std::cout << "Usage: " << *argv << " <interface>\n";
return 1;
std::string iface;
if (argc == 2) {
// Use the provided interface
iface = argv[1];
}
else {
// Use the default interface
iface = NetworkInterface::default_interface().name();
}
try {
SnifferConfiguration config;
config.set_promisc_mode(true);
config.set_filter("udp and dst port 53");
Sniffer sniffer(argv[1], config);
config.set_filter("udp and port 53");
Sniffer sniffer(iface, config);
dns_monitor monitor;
std::thread thread(
[&]() {

View File

@@ -46,10 +46,9 @@ public:
: iface(interface), addr(address) { }
result_type trace() {
// ICMPs that aren't sent from us.
SnifferConfiguration config;
config.set_snap_len(500);
config.set_promisc_mode(false);
// ICMPs that aren't sent from us.
config.set_filter(
"ip proto \\icmp and not src host " + iface.addresses().ip_addr.to_string());
Sniffer sniffer(iface.name(), config);
@@ -65,10 +64,9 @@ public:
running = true;
// Start the sniff thread
std::thread sniff_thread(
&Sniffer::sniff_loop<decltype(handler)>,
&sniffer,
handler,
0
[&]() {
sniffer.sniff_loop(handler);
}
);
send_packets(sender);
sniff_thread.join();