diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..64c2171 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,21 @@ +# The environment variable PCAPDIR allows to specficy where to find +# libpcap in non standard location. + +cmake_minimum_required (VERSION 2.8) +project (kdd99extractor CXX C) + +# Distributed CMake Find modules +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") + +# libpcap / WinPcap +find_package(PCAP) +include_directories(BEFORE ${PCAP_INCLUDE_DIR}) + +set(LIBS ${PCAP_LIBRARIES}) + +message(STATUS "ENV{PCAPDIR}=$ENV{PCAPDIR}") +message(STATUS "PCAP_FOUND=${PCAP_FOUND}") +message(STATUS "PCAP_LIBRARIES=${PCAP_LIBRARIES}") +message(STATUS "PCAP_INCLUDE_DIR=${PCAP_INCLUDE_DIR}") + +add_subdirectory(src) diff --git a/cmake/FindPCAP.cmake b/cmake/FindPCAP.cmake new file mode 100644 index 0000000..13114a8 --- /dev/null +++ b/cmake/FindPCAP.cmake @@ -0,0 +1,95 @@ +# This file is slightly modified version of FindPcap.cmake in wireshark project +# https://github.com/zonque/wireshark/blob/master/cmake/modules/FindPCAP.cmake +# +# - Find pcap and winpcap +# Find the native PCAP includes and library +# +# The environment variable PCAPDIR allows to specficy where to find +# libpcap in non standard location. +# +# PCAP_INCLUDE_DIRS - where to find pcap.h, etc. +# PCAP_LIBRARIES - List of libraries when using pcap. +# PCAP_FOUND - True if pcap found. + +# The 64-bit wpcap.lib is under /x64 +set ( _PLATFORM_SUBDIR "" ) +if( WIN32 AND CMAKE_CL_64 ) + set ( _PLATFORM_SUBDIR "/x64" ) +endif() + +find_path( PCAP_INCLUDE_DIR + NAMES + pcap/pcap.h + pcap.h + HINTS + "$ENV{PCAPDIR}/include" +) + +find_library( PCAP_LIBRARY + NAMES + pcap + wpcap + HINTS + "$ENV{PCAPDIR}/lib${_PLATFORM_SUBDIR}" +) + + +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( PCAP DEFAULT_MSG PCAP_INCLUDE_DIR PCAP_LIBRARY ) + +if( PCAP_FOUND ) + set( PCAP_INCLUDE_DIRS ${PCAP_INCLUDE_DIR} ) + set( PCAP_LIBRARIES ${PCAP_LIBRARY} ) + if( WIN32 ) + set( PCAP_LIBRARIES ${PCAP_LIBRARIES} "Ws2_32") + endif() +else() + set( PCAP_INCLUDE_DIRS ) + set( PCAP_LIBRARIES ) +endif() + +#Functions +include( CMakePushCheckState ) +include( CheckFunctionExists ) +include( CheckVariableExists ) + +cmake_push_check_state() +set( CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS} ) +set( CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES} ) + +check_function_exists( "pcap_open_dead" HAVE_PCAP_OPEN_DEAD ) +check_function_exists( "pcap_freecode" HAVE_PCAP_FREECODE ) +# +# Note: for pcap_breakloop() and pcap_findalldevs(), the autoconf script +# checks for more than just whether the function exists, it also checks +# for whether pcap.h declares it; Mac OS X software/security updates can +# update libpcap without updating the headers. +# +check_function_exists( "pcap_breakloop" HAVE_PCAP_BREAKLOOP ) +# FIXME: The code (at least) in dumpcap assumes that PCAP_CREATE is not +# available on Windows +if( NOT WIN32 ) + check_function_exists( "pcap_create" HAVE_PCAP_CREATE ) +endif() +check_function_exists( "pcap_datalink_name_to_val" HAVE_PCAP_DATALINK_NAME_TO_VAL ) +check_function_exists( "pcap_datalink_val_to_description" HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION ) +check_function_exists( "pcap_datalink_val_to_name" HAVE_PCAP_DATALINK_VAL_TO_NAME ) +check_function_exists( "pcap_findalldevs" HAVE_PCAP_FINDALLDEVS ) +check_function_exists( "pcap_free_datalinks" HAVE_PCAP_FREE_DATALINKS ) +check_function_exists( "pcap_get_selectable_fd" HAVE_PCAP_GET_SELECTABLE_FD ) +check_function_exists( "pcap_lib_version" HAVE_PCAP_LIB_VERSION ) +check_function_exists( "pcap_list_datalinks" HAVE_PCAP_LIST_DATALINKS ) +check_function_exists( "pcap_set_datalink" HAVE_PCAP_SET_DATALINK ) +check_function_exists( "bpf_image" HAVE_BPF_IMAGE ) +check_function_exists( "pcap_setsampling" HAVE_PCAP_SETSAMPLING ) +check_function_exists( "pcap_set_tstamp_precision" HAVE_PCAP_SET_TSTAMP_PRECISION ) +# Remote pcap checks +check_function_exists( "pcap_open" HAVE_PCAP_OPEN ) +if( HAVE_PCAP_OPEN ) + set( HAVE_PCAP_REMOTE 1 ) + set( HAVE_REMOTE 1 ) +endif() + +cmake_pop_check_state() + +mark_as_advanced( PCAP_LIBRARIES PCAP_INCLUDE_DIRS ) diff --git a/Feature extractor/Config.cpp b/src/Config.cpp similarity index 100% rename from Feature extractor/Config.cpp rename to src/Config.cpp diff --git a/Feature extractor/Config.h b/src/Config.h similarity index 100% rename from Feature extractor/Config.h rename to src/Config.h diff --git a/Feature extractor/Conversation.cpp b/src/Conversation.cpp similarity index 100% rename from Feature extractor/Conversation.cpp rename to src/Conversation.cpp diff --git a/Feature extractor/Conversation.h b/src/Conversation.h similarity index 100% rename from Feature extractor/Conversation.h rename to src/Conversation.h diff --git a/Feature extractor/ConversationFeatures.cpp b/src/ConversationFeatures.cpp similarity index 100% rename from Feature extractor/ConversationFeatures.cpp rename to src/ConversationFeatures.cpp diff --git a/Feature extractor/ConversationFeatures.h b/src/ConversationFeatures.h similarity index 100% rename from Feature extractor/ConversationFeatures.h rename to src/ConversationFeatures.h diff --git a/Feature extractor/ConversationReconstructor.cpp b/src/ConversationReconstructor.cpp similarity index 100% rename from Feature extractor/ConversationReconstructor.cpp rename to src/ConversationReconstructor.cpp diff --git a/Feature extractor/ConversationReconstructor.h b/src/ConversationReconstructor.h similarity index 100% rename from Feature extractor/ConversationReconstructor.h rename to src/ConversationReconstructor.h diff --git a/Feature extractor/FeatureUpdater.h b/src/FeatureUpdater.h similarity index 100% rename from Feature extractor/FeatureUpdater.h rename to src/FeatureUpdater.h diff --git a/Feature extractor/FeatureUpdaterCount.cpp b/src/FeatureUpdaterCount.cpp similarity index 100% rename from Feature extractor/FeatureUpdaterCount.cpp rename to src/FeatureUpdaterCount.cpp diff --git a/Feature extractor/FeatureUpdaterCount.h b/src/FeatureUpdaterCount.h similarity index 100% rename from Feature extractor/FeatureUpdaterCount.h rename to src/FeatureUpdaterCount.h diff --git a/Feature extractor/FeatureUpdaterTime.cpp b/src/FeatureUpdaterTime.cpp similarity index 100% rename from Feature extractor/FeatureUpdaterTime.cpp rename to src/FeatureUpdaterTime.cpp diff --git a/Feature extractor/FeatureUpdaterTime.h b/src/FeatureUpdaterTime.h similarity index 100% rename from Feature extractor/FeatureUpdaterTime.h rename to src/FeatureUpdaterTime.h diff --git a/Feature extractor/FiveTuple.cpp b/src/FiveTuple.cpp similarity index 100% rename from Feature extractor/FiveTuple.cpp rename to src/FiveTuple.cpp diff --git a/Feature extractor/FiveTuple.h b/src/FiveTuple.h similarity index 100% rename from Feature extractor/FiveTuple.h rename to src/FiveTuple.h diff --git a/Feature extractor/IcmpConversation.cpp b/src/IcmpConversation.cpp similarity index 100% rename from Feature extractor/IcmpConversation.cpp rename to src/IcmpConversation.cpp diff --git a/Feature extractor/IcmpConversation.h b/src/IcmpConversation.h similarity index 100% rename from Feature extractor/IcmpConversation.h rename to src/IcmpConversation.h diff --git a/Feature extractor/IntervalKeeper.cpp b/src/IntervalKeeper.cpp similarity index 100% rename from Feature extractor/IntervalKeeper.cpp rename to src/IntervalKeeper.cpp diff --git a/Feature extractor/IntervalKeeper.h b/src/IntervalKeeper.h similarity index 100% rename from Feature extractor/IntervalKeeper.h rename to src/IntervalKeeper.h diff --git a/Feature extractor/IpDatagram.cpp b/src/IpDatagram.cpp similarity index 100% rename from Feature extractor/IpDatagram.cpp rename to src/IpDatagram.cpp diff --git a/Feature extractor/IpDatagram.h b/src/IpDatagram.h similarity index 100% rename from Feature extractor/IpDatagram.h rename to src/IpDatagram.h diff --git a/Feature extractor/IpFragment.cpp b/src/IpFragment.cpp similarity index 100% rename from Feature extractor/IpFragment.cpp rename to src/IpFragment.cpp diff --git a/Feature extractor/IpFragment.h b/src/IpFragment.h similarity index 100% rename from Feature extractor/IpFragment.h rename to src/IpFragment.h diff --git a/Feature extractor/IpReassembler.cpp b/src/IpReassembler.cpp similarity index 100% rename from Feature extractor/IpReassembler.cpp rename to src/IpReassembler.cpp diff --git a/Feature extractor/IpReassembler.h b/src/IpReassembler.h similarity index 100% rename from Feature extractor/IpReassembler.h rename to src/IpReassembler.h diff --git a/Feature extractor/IpReassemblyBuffer.cpp b/src/IpReassemblyBuffer.cpp similarity index 100% rename from Feature extractor/IpReassemblyBuffer.cpp rename to src/IpReassemblyBuffer.cpp diff --git a/Feature extractor/IpReassemblyBuffer.h b/src/IpReassemblyBuffer.h similarity index 100% rename from Feature extractor/IpReassemblyBuffer.h rename to src/IpReassemblyBuffer.h diff --git a/Feature extractor/IpReassemblyBufferHoleList.cpp b/src/IpReassemblyBufferHoleList.cpp similarity index 100% rename from Feature extractor/IpReassemblyBufferHoleList.cpp rename to src/IpReassemblyBufferHoleList.cpp diff --git a/Feature extractor/IpReassemblyBufferHoleList.h b/src/IpReassemblyBufferHoleList.h similarity index 100% rename from Feature extractor/IpReassemblyBufferHoleList.h rename to src/IpReassemblyBufferHoleList.h diff --git a/Feature extractor/Packet.cpp b/src/Packet.cpp similarity index 100% rename from Feature extractor/Packet.cpp rename to src/Packet.cpp diff --git a/Feature extractor/Packet.h b/src/Packet.h similarity index 100% rename from Feature extractor/Packet.h rename to src/Packet.h diff --git a/Feature extractor/ReferenceCounter.cpp b/src/ReferenceCounter.cpp similarity index 100% rename from Feature extractor/ReferenceCounter.cpp rename to src/ReferenceCounter.cpp diff --git a/Feature extractor/ReferenceCounter.h b/src/ReferenceCounter.h similarity index 100% rename from Feature extractor/ReferenceCounter.h rename to src/ReferenceCounter.h diff --git a/Feature extractor/Sniffer.cpp b/src/Sniffer.cpp similarity index 100% rename from Feature extractor/Sniffer.cpp rename to src/Sniffer.cpp diff --git a/Feature extractor/Sniffer.h b/src/Sniffer.h similarity index 100% rename from Feature extractor/Sniffer.h rename to src/Sniffer.h diff --git a/Feature extractor/StatsCollector.h b/src/StatsCollector.h similarity index 100% rename from Feature extractor/StatsCollector.h rename to src/StatsCollector.h diff --git a/Feature extractor/StatsEngine.cpp b/src/StatsEngine.cpp similarity index 100% rename from Feature extractor/StatsEngine.cpp rename to src/StatsEngine.cpp diff --git a/Feature extractor/StatsEngine.h b/src/StatsEngine.h similarity index 100% rename from Feature extractor/StatsEngine.h rename to src/StatsEngine.h diff --git a/Feature extractor/StatsPerHost.cpp b/src/StatsPerHost.cpp similarity index 100% rename from Feature extractor/StatsPerHost.cpp rename to src/StatsPerHost.cpp diff --git a/Feature extractor/StatsPerHost.h b/src/StatsPerHost.h similarity index 100% rename from Feature extractor/StatsPerHost.h rename to src/StatsPerHost.h diff --git a/Feature extractor/StatsPerService.cpp b/src/StatsPerService.cpp similarity index 100% rename from Feature extractor/StatsPerService.cpp rename to src/StatsPerService.cpp diff --git a/Feature extractor/StatsPerService.h b/src/StatsPerService.h similarity index 100% rename from Feature extractor/StatsPerService.h rename to src/StatsPerService.h diff --git a/Feature extractor/StatsPerServiceWithSrcPort.cpp b/src/StatsPerServiceWithSrcPort.cpp similarity index 100% rename from Feature extractor/StatsPerServiceWithSrcPort.cpp rename to src/StatsPerServiceWithSrcPort.cpp diff --git a/Feature extractor/StatsPerServiceWithSrcPort.h b/src/StatsPerServiceWithSrcPort.h similarity index 100% rename from Feature extractor/StatsPerServiceWithSrcPort.h rename to src/StatsPerServiceWithSrcPort.h diff --git a/Feature extractor/StatsWindow.cpp b/src/StatsWindow.cpp similarity index 100% rename from Feature extractor/StatsWindow.cpp rename to src/StatsWindow.cpp diff --git a/Feature extractor/StatsWindow.h b/src/StatsWindow.h similarity index 100% rename from Feature extractor/StatsWindow.h rename to src/StatsWindow.h diff --git a/Feature extractor/StatsWindowCount.cpp b/src/StatsWindowCount.cpp similarity index 100% rename from Feature extractor/StatsWindowCount.cpp rename to src/StatsWindowCount.cpp diff --git a/Feature extractor/StatsWindowCount.h b/src/StatsWindowCount.h similarity index 100% rename from Feature extractor/StatsWindowCount.h rename to src/StatsWindowCount.h diff --git a/Feature extractor/StatsWindowTime.cpp b/src/StatsWindowTime.cpp similarity index 100% rename from Feature extractor/StatsWindowTime.cpp rename to src/StatsWindowTime.cpp diff --git a/Feature extractor/StatsWindowTime.h b/src/StatsWindowTime.h similarity index 100% rename from Feature extractor/StatsWindowTime.h rename to src/StatsWindowTime.h diff --git a/Feature extractor/TcpConnection.cpp b/src/TcpConnection.cpp similarity index 100% rename from Feature extractor/TcpConnection.cpp rename to src/TcpConnection.cpp diff --git a/Feature extractor/TcpConnection.h b/src/TcpConnection.h similarity index 100% rename from Feature extractor/TcpConnection.h rename to src/TcpConnection.h diff --git a/Feature extractor/Timestamp.cpp b/src/Timestamp.cpp similarity index 96% rename from Feature extractor/Timestamp.cpp rename to src/Timestamp.cpp index e180ba9..9a397d9 100644 --- a/Feature extractor/Timestamp.cpp +++ b/src/Timestamp.cpp @@ -14,8 +14,8 @@ namespace FeatureExtractor { } Timestamp::Timestamp(int64_t usecs) { - ts.tv_sec = usecs / 1000000; - ts.tv_usec = usecs % 1000000; + ts.tv_sec = (long) (usecs / 1000000); + ts.tv_usec = (long) (usecs % 1000000); } Timestamp::~Timestamp() diff --git a/Feature extractor/Timestamp.h b/src/Timestamp.h similarity index 100% rename from Feature extractor/Timestamp.h rename to src/Timestamp.h diff --git a/Feature extractor/UdpConversation.cpp b/src/UdpConversation.cpp similarity index 100% rename from Feature extractor/UdpConversation.cpp rename to src/UdpConversation.cpp diff --git a/Feature extractor/UdpConversation.h b/src/UdpConversation.h similarity index 100% rename from Feature extractor/UdpConversation.h rename to src/UdpConversation.h diff --git a/Feature extractor/main.cpp b/src/main.cpp similarity index 100% rename from Feature extractor/main.cpp rename to src/main.cpp diff --git a/Feature extractor/net.cpp b/src/net.cpp similarity index 100% rename from Feature extractor/net.cpp rename to src/net.cpp diff --git a/Feature extractor/net.h b/src/net.h similarity index 100% rename from Feature extractor/net.h rename to src/net.h