From c108f6e4e6f20ad05b24b39b19e8a33ebda7471d Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 25 Apr 2015 18:44:38 -0700 Subject: [PATCH] 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;