From 830da2488b09413751d3588a70d4cddf5d18cdd5 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 19 Apr 2015 13:54:37 -0700 Subject: [PATCH 01/11] Update project version to 3.3. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab62deb..a78a701 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ ENDIF(LIBTINS_BUILD_SHARED) # The version number. SET(LIBTINS_VERSION_MAJOR 3) -SET(LIBTINS_VERSION_MINOR 2) +SET(LIBTINS_VERSION_MINOR 3) SET(LIBTINS_VERSION "${LIBTINS_VERSION_MAJOR}.${LIBTINS_VERSION_MINOR}") # Required Packages From c5b9afaf83403381023407cd442d69f9bac822f1 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Thu, 23 Apr 2015 19:39:48 -0700 Subject: [PATCH 02/11] Add google test as git submodule. --- .gitmodules | 3 +++ CMakeLists.txt | 4 +++- googletest | 1 + tests/CMakeLists.txt | 11 ++++++++--- tests/src/CMakeLists.txt | 14 +++++++++++--- 5 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 .gitmodules create mode 160000 googletest diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7e14f2b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "googletest"] + path = googletest + url = https://github.com/smarr/googletest.git diff --git a/CMakeLists.txt b/CMakeLists.txt index a78a701..2b27793 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,9 +137,11 @@ install( ENABLE_TESTING() ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(src) -ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(examples) +ADD_SUBDIRECTORY(googletest) +ADD_SUBDIRECTORY(tests) + # Add all targets to the build-tree export set EXPORT( TARGETS tins diff --git a/googletest b/googletest new file mode 160000 index 0000000..2ccb249 --- /dev/null +++ b/googletest @@ -0,0 +1 @@ +Subproject commit 2ccb2496fef815a1c18fcbc79c178f6cb4b5f982 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9b20d87..930e530 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,12 @@ -FIND_PACKAGE(GTest) +IF(gtest_BINARY_DIR) + MESSAGE(STATUS "Using googletest submodule") + SET(GTEST_FOUND true) +ELSE() + FIND_PACKAGE(GTest) +ENDIF() IF(GTEST_FOUND) - INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) + INCLUDE_DIRECTORIES(${gtest_INCLUDE_DIRS}) ADD_SUBDIRECTORY(src) ELSE(GTEST_FOUND) - MESSAGE(WARNING "Google test not found. Disabling tests.") + MESSAGE(WARNING "Google test not found. Tests disabled.") ENDIF(GTEST_FOUND) diff --git a/tests/src/CMakeLists.txt b/tests/src/CMakeLists.txt index 5219800..6081d02 100644 --- a/tests/src/CMakeLists.txt +++ b/tests/src/CMakeLists.txt @@ -1,14 +1,22 @@ # Use libtins' include directories + test include directories -INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include/tins/ ../include/) +INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/include/tins/ + ../include/ + ${gtest_SOURCE_DIR}/include +) # Find pthread library FIND_PACKAGE(Threads REQUIRED) +LINK_DIRECTORIES( + ${gtest_BINARY_DIR} + +) # Link against GoogleTest, libtins and pthread. # Pthread is required by GoogleTest LINK_LIBRARIES( - ${GTEST_LIBRARIES} - ${GTEST_MAIN_LIBRARY} + gtest + gtest_main tins ${CMAKE_THREAD_LIBS_INIT} ) From 745ebfb9046de985e97190c3da56bb99eac6306c Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Thu, 23 Apr 2015 19:43:00 -0700 Subject: [PATCH 03/11] Only include googletest if the git submodule has been fetched. --- CMakeLists.txt | 5 ++++- tests/CMakeLists.txt | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b27793..b338895 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,7 +139,10 @@ ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(examples) -ADD_SUBDIRECTORY(googletest) +# Only include googletest if the git submodule has been fetched +IF(EXISTS "googletest/CMakeLists.txt") + ADD_SUBDIRECTORY(googletest) +ENDIF() ADD_SUBDIRECTORY(tests) # Add all targets to the build-tree export set diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 930e530..ec19944 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,5 @@ IF(gtest_BINARY_DIR) - MESSAGE(STATUS "Using googletest submodule") + MESSAGE(STATUS "Using googletest git submodule.") SET(GTEST_FOUND true) ELSE() FIND_PACKAGE(GTest) From 0dcbe6ffbefc4c6f56dfc89592381ffcc1ad5bec Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Thu, 23 Apr 2015 19:45:32 -0700 Subject: [PATCH 04/11] Prefix googletest directory with CMake source dir. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b338895..d9da1f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,7 +140,7 @@ ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(examples) # Only include googletest if the git submodule has been fetched -IF(EXISTS "googletest/CMakeLists.txt") +IF(EXISTS "${CMAKE_SOURCE_DIR}/googletest/CMakeLists.txt") ADD_SUBDIRECTORY(googletest) ENDIF() ADD_SUBDIRECTORY(tests) From 93ed4f537ec8313e3e80b9d5961f3dc9427b221f Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 25 Apr 2015 12:15:04 -0700 Subject: [PATCH 05/11] Fix TCP test on Windows. --- tests/src/tcp.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/src/tcp.cpp b/tests/src/tcp.cpp index fc29453..cd365d0 100644 --- a/tests/src/tcp.cpp +++ b/tests/src/tcp.cpp @@ -5,6 +5,7 @@ #include #include "tcp.h" #include "ip.h" +#include "ethernetII.h" #include "utils.h" using namespace std; @@ -24,11 +25,12 @@ const uint8_t TCPTest::expected_packet[] = { 18, 52, 3, 3, 122, 4, 2, 5, 10, 0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0 }; -// IP + TCP +// Ethernet + IP + TCP const uint8_t TCPTest::checksum_packet[] = { - 69, 0, 0, 40, 0, 0, 64, 0, 64, 6, 60, 206, 0, 0, 0, 0, 127, 0, 0, 1, - 5, 57, 199, 49, 0, 0, 0, 0, 255, 216, 70, 222, 80, 20, 0, 0, 158, 172, - 0, 0 + 10, 128, 57, 251, 101, 187, 76, 128, 147, 141, 144, 65, 8, 0, 69, 0, 0, + 60, 152, 189, 64, 0, 64, 6, 0, 19, 10, 0, 0, 54, 198, 41, 209, 140, 180, + 207, 1, 187, 114, 130, 185, 186, 0, 0, 0, 0, 160, 2, 114, 16, 44, 228, 0, + 0, 2, 4, 5, 180, 4, 2, 8, 10, 3, 81, 33, 7, 0, 0, 0, 0, 1, 3, 3, 7 }; const uint8_t TCPTest::partial_packet[] = { @@ -44,12 +46,12 @@ TEST_F(TCPTest, DefaultConstructor) { } TEST_F(TCPTest, ChecksumCheck) { - IP pkt1(checksum_packet, sizeof(checksum_packet)); + EthernetII pkt1(checksum_packet, sizeof(checksum_packet)); const TCP &tcp1 = pkt1.rfind_pdu(); uint16_t checksum = tcp1.checksum(); - IP::serialization_type buffer = pkt1.serialize(); - IP pkt2(&buffer[0], buffer.size()); + PDU::serialization_type buffer = pkt1.serialize(); + EthernetII pkt2(&buffer[0], buffer.size()); const TCP &tcp2 = pkt2.rfind_pdu(); EXPECT_EQ(checksum, tcp2.checksum()); EXPECT_EQ(tcp1.checksum(), tcp2.checksum()); From e64e0ce27bfadad922da8c8b8466666e00806405 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 25 Apr 2015 12:20:47 -0700 Subject: [PATCH 06/11] Fix IPv6Address::to_string on Windows. --- src/ipv6_address.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipv6_address.cpp b/src/ipv6_address.cpp index e4ab37a..b63915e 100644 --- a/src/ipv6_address.cpp +++ b/src/ipv6_address.cpp @@ -87,7 +87,7 @@ std::string IPv6Address::to_string() const { #ifdef WIN32 // mingw on linux somehow doesn't have InetNtop #ifdef _MSC_VER - if(InetNtopA(AF_INET6, (PVOID)address, buffer, sizeof(buffer)) != 0) + if(InetNtopA(AF_INET6, (PVOID)address, buffer, sizeof(buffer)) == 0) throw malformed_address(); #else ULONG sz = sizeof(buffer); From ae503523e44c6edab9957e48d8706240b8351048 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 25 Apr 2015 17:05:36 -0700 Subject: [PATCH 07/11] Fix tests that failed on Windows. --- tests/src/icmpv6.cpp | 5 ++--- tests/src/network_interface.cpp | 37 +++++++++++++++++++++++++++------ tests/src/udp.cpp | 16 +++++++------- tests/src/utils.cpp | 29 -------------------------- 4 files changed, 42 insertions(+), 45 deletions(-) diff --git a/tests/src/icmpv6.cpp b/tests/src/icmpv6.cpp index 369d24c..a193633 100644 --- a/tests/src/icmpv6.cpp +++ b/tests/src/icmpv6.cpp @@ -218,9 +218,8 @@ TEST_F(ICMPv6Test, PrefixInformation) { TEST_F(ICMPv6Test, RedirectHeader) { ICMPv6 icmp; - IP ip = IP("127.0.0.1") / TCP(22); - PDU::serialization_type buffer = ip.serialize(); - buffer.insert(buffer.begin(), 6, 0); + EthernetII eth = EthernetII() / IP("8.8.8.8", "192.168.0.100") / TCP(22, 26); + PDU::serialization_type buffer = eth.serialize(); icmp.redirect_header(buffer); EXPECT_EQ(buffer, icmp.redirect_header()); } diff --git a/tests/src/network_interface.cpp b/tests/src/network_interface.cpp index ba41788..ef48820 100644 --- a/tests/src/network_interface.cpp +++ b/tests/src/network_interface.cpp @@ -1,10 +1,12 @@ #include #include +#include #include "network_interface.h" #include "utils.h" #include "macros.h" using namespace Tins; +using namespace std; class NetworkInterfaceTest : public ::testing::Test { public: @@ -12,17 +14,14 @@ public: }; #ifdef BSD -const std::string NetworkInterfaceTest::iface_name("lo0"), - NetworkInterfaceTest::iface_addr(""); -#elif defined(WIN32) -// modify me on every windows environment :D -const std::string NetworkInterfaceTest::iface_name("{INSERT-SOME-INTERFACE-NAME}"), +const string NetworkInterfaceTest::iface_name("lo0"), NetworkInterfaceTest::iface_addr(""); #else -const std::string NetworkInterfaceTest::iface_name("lo"), +const string NetworkInterfaceTest::iface_name("lo"), NetworkInterfaceTest::iface_addr(""); #endif +#ifndef WIN32 TEST_F(NetworkInterfaceTest, ConstructorFromString) { // just test this doesn't throw NetworkInterface iface(iface_name); @@ -63,5 +62,31 @@ TEST_F(NetworkInterfaceTest, DistinctOperator) { NetworkInterface iface1(iface_name), iface2; EXPECT_NE(iface1, iface2); } +#endif // WIN32 +// This is a more generic test that can be run on all platforms. +// The above ones won't run on windows since there's no name for the loopback interface. +// So this does more or less the same as all of the above, but iterating over the +// actual interfaces available in the system. +TEST_F(NetworkInterfaceTest, IterateOverInterfaces) { + vector interfaces = NetworkInterface::all(); + set names; + set ids; + for (size_t i = 0; i < interfaces.size(); ++i) { + // Expect unique names an all interfaces + EXPECT_TRUE(names.insert(interfaces[i].name()).second); + // Expect unique ids an all interfaces + EXPECT_TRUE(ids.insert(interfaces[i].id()).second); + // Expect this interface to be equal to itself + EXPECT_EQ(interfaces[i], interfaces[i]); + // We expect to be able to construct the interface from a name + // and they should still be equal + NetworkInterface iface(interfaces[i].name()); + EXPECT_EQ(interfaces[i], iface); + // We expect this interface to be different from the others + for (size_t u = i + 1; u < interfaces.size(); ++u) { + EXPECT_NE(interfaces[i], interfaces[u]); + } + } +} diff --git a/tests/src/udp.cpp b/tests/src/udp.cpp index f831b0b..ca867ff 100644 --- a/tests/src/udp.cpp +++ b/tests/src/udp.cpp @@ -3,7 +3,7 @@ #include #include "udp.h" #include "ip.h" - +#include "ethernetII.h" using namespace std; using namespace Tins; @@ -21,9 +21,11 @@ const uint8_t UDPTest::expected_packet[] = { }; const uint8_t UDPTest::checksum_packet[] = { - 69, 0, 0, 48, 35, 109, 64, 0, 64, 17, 25, 78, 0, 0, 0, 0, 127, 0, 0, - 1, 5, 57, 155, 11, 0, 28, 84, 167, 97, 115, 100, 97, 115, 100, 115, - 97, 115, 100, 97, 115, 100, 115, 97, 100, 97, 115, 100, 10 + 10, 128, 57, 251, 101, 187, 76, 128, 147, 141, 144, 65, 8, 0, 69, 0, 0, + 70, 14, 223, 64, 0, 64, 17, 138, 252, 10, 0, 0, 54, 75, 75, 75, 75, 215, + 173, 0, 53, 0, 50, 206, 155, 118, 39, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 11, + 48, 45, 101, 100, 103, 101, 45, 99, 104, 97, 116, 8, 102, 97, 99, 101, + 98, 111, 111, 107, 3, 99, 111, 109, 0, 0, 1, 0, 1 }; @@ -44,12 +46,12 @@ TEST_F(UDPTest, DefaultConstructor) { } TEST_F(UDPTest, ChecksumCheck) { - IP pkt1(checksum_packet, sizeof(checksum_packet)); + EthernetII pkt1(checksum_packet, sizeof(checksum_packet)); const UDP &udp1 = pkt1.rfind_pdu(); uint16_t checksum = udp1.checksum(); - IP::serialization_type buffer = pkt1.serialize(); - IP pkt2(&buffer[0], buffer.size()); + PDU::serialization_type buffer = pkt1.serialize(); + EthernetII pkt2(&buffer[0], buffer.size()); const UDP &udp2 = pkt2.rfind_pdu(); EXPECT_EQ(checksum, udp2.checksum()); EXPECT_EQ(udp1.checksum(), udp2.checksum()); diff --git a/tests/src/utils.cpp b/tests/src/utils.cpp index c7cec16..ac0381f 100644 --- a/tests/src/utils.cpp +++ b/tests/src/utils.cpp @@ -67,36 +67,7 @@ const uint32_t UtilsTest::data_len = 500; TEST_F(UtilsTest, Crc32) { - uint32_t crc = Utils::crc32(data, data_len); EXPECT_EQ(crc, 0x78840f54U); - -} - -TEST_F(UtilsTest, ResolveDomain) { - IPv4Address localhost_ip("127.0.0.1"); - - EXPECT_EQ(Utils::resolve_domain("localhost"), localhost_ip); -} - -/* -TEST_F(UtilsTest, ResolveDomain6) { - IPv6Address localhost_ip("2606:2800:220:6d:26bf:1447:1097:aa7"); - - EXPECT_EQ(Utils::resolve_domain6("example.com"), localhost_ip); -} -*/ - -// FIXME -TEST_F(UtilsTest, Checksum) { - - /*uint16_t checksum = Utils::do_checksum(data, data + data_len); - - //EXPECT_EQ(checksum, 0x231a); - - uint8_t my_data[] = {0, 0, 0, 0}; - checksum = Utils::do_checksum(my_data, my_data + 4); - //EXPECT_EQ(checksum, 0xFFFF); -*/ } From 34bf1f23f74c843f3afc702b9994e7848703551a Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 25 Apr 2015 17:26:02 -0700 Subject: [PATCH 08/11] Improve tests CMake build files. --- CMakeLists.txt | 23 +++++++++++++---------- tests/CMakeLists.txt | 14 ++------------ tests/src/CMakeLists.txt | 3 ++- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d9da1f2..8823834 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,30 +120,33 @@ CONFIGURE_FILE( ) # Support for pkg-config -set(CMAKE_INSTALL_LIBDIR lib) -set(pkgconfig_prefix ${CMAKE_INSTALL_PREFIX}) -set(pkgconfig_exec_prefix ${CMAKE_INSTALL_PREFIX}) -set(pkgconfig_libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) -set(pkgconfig_version ${LIBTINS_VERSION}) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libtins.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/libtins.pc @ONLY) +SET(CMAKE_INSTALL_LIBDIR lib) +SET(pkgconfig_prefix ${CMAKE_INSTALL_PREFIX}) +SET(pkgconfig_exec_prefix ${CMAKE_INSTALL_PREFIX}) +SET(pkgconfig_libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) +SET(pkgconfig_version ${LIBTINS_VERSION}) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libtins.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/libtins.pc @ONLY) -install( +INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/libtins.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) -ENABLE_TESTING() ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(examples) # Only include googletest if the git submodule has been fetched IF(EXISTS "${CMAKE_SOURCE_DIR}/googletest/CMakeLists.txt") + MESSAGE(STATUS "Tests have been enabled") + ENABLE_TESTING() ADD_SUBDIRECTORY(googletest) + ADD_SUBDIRECTORY(tests) +ELSE() + MESSAGE(STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it") ENDIF() -ADD_SUBDIRECTORY(tests) # Add all targets to the build-tree export set EXPORT( diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ec19944..1cf6832 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,12 +1,2 @@ -IF(gtest_BINARY_DIR) - MESSAGE(STATUS "Using googletest git submodule.") - SET(GTEST_FOUND true) -ELSE() - FIND_PACKAGE(GTest) -ENDIF() -IF(GTEST_FOUND) - INCLUDE_DIRECTORIES(${gtest_INCLUDE_DIRS}) - ADD_SUBDIRECTORY(src) -ELSE(GTEST_FOUND) - MESSAGE(WARNING "Google test not found. Tests disabled.") -ENDIF(GTEST_FOUND) +INCLUDE_DIRECTORIES(${gtest_INCLUDE_DIRS}) +ADD_SUBDIRECTORY(src) \ No newline at end of file diff --git a/tests/src/CMakeLists.txt b/tests/src/CMakeLists.txt index 6081d02..7d282c4 100644 --- a/tests/src/CMakeLists.txt +++ b/tests/src/CMakeLists.txt @@ -3,6 +3,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/include/tins/ ../include/ ${gtest_SOURCE_DIR}/include + ${PCAP_INCLUDE_DIR} ) # Find pthread library @@ -10,7 +11,6 @@ FIND_PACKAGE(Threads REQUIRED) LINK_DIRECTORIES( ${gtest_BINARY_DIR} - ) # Link against GoogleTest, libtins and pthread. # Pthread is required by GoogleTest @@ -19,6 +19,7 @@ LINK_LIBRARIES( gtest_main tins ${CMAKE_THREAD_LIBS_INIT} + ${PCAP_LIBRARY} ) IF(LIBTINS_ENABLE_WPA2) From 5c8fdd2b6cd7b860c4236982a1145a7505fb710d Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 25 Apr 2015 17:44:56 -0700 Subject: [PATCH 09/11] Build googletest using /MD on Windows. --- CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8823834..03af4a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,11 @@ IF(WIN32) ADD_DEFINITIONS(-DNOMINMAX -DWIN32) ENDIF(WIN32) +# ******************* # Compilation options +# ******************* + +# C++11 support OPTION(LIBTINS_ENABLE_CXX11 "Compile libtins with c++11 features" OFF) IF(LIBTINS_ENABLE_CXX11) SET(HAVE_CXX11 ON) @@ -67,6 +71,7 @@ ELSE(LIBTINS_ENABLE_CXX11) "as it increases the library's performance") ENDIF(LIBTINS_ENABLE_CXX11) +# IEEE 802.11 and WPA2 decryption support OPTION(LIBTINS_ENABLE_DOT11 "Compile libtins with IEEE 802.11 support" ON) OPTION(LIBTINS_ENABLE_WPA2 "Compile libtins with WPA2 decryption features (requires OpenSSL)" ON) IF(LIBTINS_ENABLE_DOT11) @@ -81,6 +86,7 @@ IF(LIBTINS_ENABLE_DOT11) ENDIF(LIBTINS_ENABLE_WPA2) ENDIF(LIBTINS_ENABLE_DOT11) +# Use pcap_sendpacket to send l2 packets rather than raw sockets IF(WIN32) SET(USE_PCAP_SENDPACKET_DEFAULT ON) ELSE(WIN32) @@ -110,6 +116,7 @@ IF(DOXYGEN_FOUND) ) ENDIF(DOXYGEN_FOUND) +# The library output directory SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) @@ -134,13 +141,18 @@ INSTALL( DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) +# ****************** +# Add subdirectories +# ****************** ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(examples) # Only include googletest if the git submodule has been fetched IF(EXISTS "${CMAKE_SOURCE_DIR}/googletest/CMakeLists.txt") + # Enable tests and add the test directory MESSAGE(STATUS "Tests have been enabled") + SET(gtest_force_shared_crt true) ENABLE_TESTING() ADD_SUBDIRECTORY(googletest) ADD_SUBDIRECTORY(tests) @@ -148,6 +160,10 @@ ELSE() MESSAGE(STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it") ENDIF() +# ********************************** +# CMake project configuration export +# ********************************** + # Add all targets to the build-tree export set EXPORT( TARGETS tins From c108f6e4e6f20ad05b24b39b19e8a33ebda7471d Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 25 Apr 2015 18:44:38 -0700 Subject: [PATCH 10/11] Fix compilation warnings on Windows. --- CMakeLists.txt | 14 +++++++++++--- include/tins/utils.h | 1 - src/dhcpv6.cpp | 4 ++-- src/ip_reassembler.cpp | 2 +- src/offline_packet_filter.cpp | 6 +----- src/packet_sender.cpp | 2 +- src/radiotap.cpp | 2 +- src/tcp.cpp | 4 ++-- tests/src/dns.cpp | 3 +++ 9 files changed, 22 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03af4a9..4f00fae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,16 @@ ELSE(NOT CMAKE_BUILD_TYPE) MESSAGE(STATUS "Using specified '${CMAKE_BUILD_TYPE}' build type.") ENDIF(NOT CMAKE_BUILD_TYPE) -# Default compilation settings -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +# Compilation flags. +IF(MSVC) + # Don't always use Wall, since VC's /Wall is ridiculously verbose. + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3") + # Disable VC secure checks, since these are not really issues. + ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS=1") + ADD_DEFINITIONS("-D_SCL_SECURE_NO_WARNINGS=1") +ELSE() + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +ENDIF() # Build output checks OPTION(LIBTINS_BUILD_SHARED "Build libtins as a shared library." ON) @@ -152,7 +160,7 @@ ADD_SUBDIRECTORY(examples) IF(EXISTS "${CMAKE_SOURCE_DIR}/googletest/CMakeLists.txt") # Enable tests and add the test directory MESSAGE(STATUS "Tests have been enabled") - SET(gtest_force_shared_crt true) + SET(gtest_force_shared_crt ON CACHE BOOL "Always use /MD") ENABLE_TESTING() ADD_SUBDIRECTORY(googletest) ADD_SUBDIRECTORY(tests) diff --git a/include/tins/utils.h b/include/tins/utils.h index ad751bd..e6d45f7 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -381,7 +381,6 @@ template void Tins::Utils::route_entries(ForwardIterator output) { MIB_IPFORWARDTABLE *table; ULONG size = 0; - char iface_name[256]; GetIpForwardTable(0, &size, 0); std::vector buffer(size); table = (MIB_IPFORWARDTABLE*)&buffer[0]; diff --git a/src/dhcpv6.cpp b/src/dhcpv6.cpp index e5f8d47..3a2dda8 100644 --- a/src/dhcpv6.cpp +++ b/src/dhcpv6.cpp @@ -201,7 +201,7 @@ DHCPv6::status_code_type DHCPv6::status_code() const { } bool DHCPv6::has_rapid_commit() const { - return search_option(RAPID_COMMIT); + return static_cast(search_option(RAPID_COMMIT)); } DHCPv6::user_class_type DHCPv6::user_class() const { @@ -225,7 +225,7 @@ uint8_t DHCPv6::reconfigure_msg() const { } bool DHCPv6::has_reconfigure_accept() const { - return search_option(RECONF_ACCEPT); + return static_cast(search_option(RECONF_ACCEPT)); } DHCPv6::duid_type DHCPv6::client_id() const { diff --git a/src/ip_reassembler.cpp b/src/ip_reassembler.cpp index 195ba1c..dc0c663 100644 --- a/src/ip_reassembler.cpp +++ b/src/ip_reassembler.cpp @@ -87,7 +87,7 @@ uint16_t IPv4Stream::extract_offset(const IP *ip) { } bool IPv4Stream::extract_more_frag(const IP *ip) { - return ip->frag_off() & 0x2000; + return (ip->frag_off() & 0x2000) != 0; } } // namespace Internals diff --git a/src/offline_packet_filter.cpp b/src/offline_packet_filter.cpp index 2adf4ff..bcf689f 100644 --- a/src/offline_packet_filter.cpp +++ b/src/offline_packet_filter.cpp @@ -70,11 +70,7 @@ bool OfflinePacketFilter::matches_filter(const uint8_t* buffer, pcap_pkthdr header = {}; header.len = total_sz; header.caplen = total_sz; - return pcap_offline_filter( - &filter, - &header, - buffer - ); + return pcap_offline_filter(&filter, &header, buffer) != 0; } bool OfflinePacketFilter::matches_filter(PDU& pdu) const diff --git a/src/packet_sender.cpp b/src/packet_sender.cpp index 926027d..5710689 100644 --- a/src/packet_sender.cpp +++ b/src/packet_sender.cpp @@ -384,7 +384,7 @@ PDU *PacketSender::recv_match_loop(const std::vector& sockets, PDU &pdu, st #endif timeout.tv_sec = _timeout; - end_time.tv_sec = time(0) + _timeout; + end_time.tv_sec = static_cast(time(0) + _timeout); end_time.tv_usec = timeout.tv_usec = _timeout_usec; while(true) { FD_ZERO(&readfds); diff --git a/src/radiotap.cpp b/src/radiotap.cpp index 0da8490..29e010e 100644 --- a/src/radiotap.cpp +++ b/src/radiotap.cpp @@ -178,7 +178,7 @@ void RadioTap::init() { channel(Utils::channel_to_mhz(1), 0xa0); flags(FCS); tsft(0); - dbm_signal(0xce); + dbm_signal(static_cast(0xce)); rx_flags(0); antenna(0); } diff --git a/src/tcp.cpp b/src/tcp.cpp index 3a9065b..49dba48 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -147,7 +147,7 @@ void TCP::sack_permitted() { } bool TCP::has_sack_permitted() const { - return bool(search_option(SACK_OK)); + return static_cast(search_option(SACK_OK)); } void TCP::sack(const sack_type &edges) { @@ -286,7 +286,7 @@ void TCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *par buffer = write_option(*it, buffer); if(_options_size < _total_options_size) { - uint8_t padding = _options_size; + uint16_t padding = _options_size; while(padding < _total_options_size) { *(buffer++) = 1; padding++; diff --git a/tests/src/dns.cpp b/tests/src/dns.cpp index d1e75b7..9fb283d 100644 --- a/tests/src/dns.cpp +++ b/tests/src/dns.cpp @@ -4,6 +4,9 @@ #include "ipv6_address.h" #include "utils.h" +// Really nice and unique macro names, Windows :D +#undef IN + using namespace Tins; From 62260ab93b104c3d2e8be42bc33df11db2411ae7 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 25 Apr 2015 18:54:43 -0700 Subject: [PATCH 11/11] Fix more compilation warnings on Windows. --- include/tins/radiotap.h | 2 +- src/dhcpv6.cpp | 4 ++-- src/radiotap.cpp | 2 +- src/tcp.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/tins/radiotap.h b/include/tins/radiotap.h index 778f0d6..caf9ccd 100644 --- a/include/tins/radiotap.h +++ b/include/tins/radiotap.h @@ -45,7 +45,7 @@ namespace Tins { * By default, RadioTap PDUs set the necesary fields to send an 802.11 * PDU as its inner pdu, avoiding packet drops. As a consequence, * the FCS-at-end flag is on, the channel is set to 1, TSFT is set to 0, - * dbm_signal is set to 0xce, and the rx_flag and antenna fields to 0. + * dbm_signal is set to -50, and the rx_flag and antenna fields to 0. */ class RadioTap : public PDU { public: diff --git a/src/dhcpv6.cpp b/src/dhcpv6.cpp index 3a2dda8..e45d7ac 100644 --- a/src/dhcpv6.cpp +++ b/src/dhcpv6.cpp @@ -201,7 +201,7 @@ DHCPv6::status_code_type DHCPv6::status_code() const { } bool DHCPv6::has_rapid_commit() const { - return static_cast(search_option(RAPID_COMMIT)); + return search_option(RAPID_COMMIT) != NULL; } DHCPv6::user_class_type DHCPv6::user_class() const { @@ -225,7 +225,7 @@ uint8_t DHCPv6::reconfigure_msg() const { } bool DHCPv6::has_reconfigure_accept() const { - return static_cast(search_option(RECONF_ACCEPT)); + return search_option(RECONF_ACCEPT) != NULL; } DHCPv6::duid_type DHCPv6::client_id() const { diff --git a/src/radiotap.cpp b/src/radiotap.cpp index 29e010e..f7210ed 100644 --- a/src/radiotap.cpp +++ b/src/radiotap.cpp @@ -178,7 +178,7 @@ void RadioTap::init() { channel(Utils::channel_to_mhz(1), 0xa0); flags(FCS); tsft(0); - dbm_signal(static_cast(0xce)); + dbm_signal(-50); rx_flags(0); antenna(0); } diff --git a/src/tcp.cpp b/src/tcp.cpp index 49dba48..d3a50a9 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -147,7 +147,7 @@ void TCP::sack_permitted() { } bool TCP::has_sack_permitted() const { - return static_cast(search_option(SACK_OK)); + return search_option(SACK_OK) != NULL; } void TCP::sack(const sack_type &edges) {