From 2fca31ccc14c0655a21bdc9058096107cd38a42c Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Mon, 9 Aug 2021 16:14:37 +0200 Subject: Fixed Mingw64 build. * adapted to SonarCloud-CI workflow * removed broken and incomplete Windows example (tested on VS2017/VS2019) * removed unnecessary include (e.g. pthread.h for the library which does not make use of it) Signed-off-by: Toni Uhlig --- example/Makefile.in | 33 +- example/Win32/pcapExample.sln | 20 - example/Win32/pcapExample.suo | Bin 306688 -> 0 bytes example/Win32/pcapExample/pcapExample.cpp | 11 - example/Win32/pcapExample/pcapExample.vcxproj | 231 ---------- .../Win32/pcapExample/pcapExample.vcxproj.filters | 465 --------------------- example/Win32/pcapExample/pcapExample.vcxproj.user | 3 - example/ndpiReader.c | 25 +- example/ndpiSimpleIntegration.c | 14 +- example/reader_util.c | 25 +- 10 files changed, 75 insertions(+), 752 deletions(-) delete mode 100644 example/Win32/pcapExample.sln delete mode 100644 example/Win32/pcapExample.suo delete mode 100644 example/Win32/pcapExample/pcapExample.cpp delete mode 100644 example/Win32/pcapExample/pcapExample.vcxproj delete mode 100644 example/Win32/pcapExample/pcapExample.vcxproj.filters delete mode 100644 example/Win32/pcapExample/pcapExample.vcxproj.user (limited to 'example') diff --git a/example/Makefile.in b/example/Makefile.in index cef1edb63..11c30ad5c 100644 --- a/example/Makefile.in +++ b/example/Makefile.in @@ -1,22 +1,34 @@ CC=@CC@ CXX=@CXX@ BUILD_MINGW=@BUILD_MINGW@ +BUILD_MINGW_X64=@BUILD_MINGW_X64@ SRCHOME=../src CFLAGS=-g -fPIC -DPIC -I$(SRCHOME)/include @PCAP_INC@ @CFLAGS@ LIBNDPI=$(SRCHOME)/lib/libndpi.a -LDFLAGS=$(LIBNDPI) @PCAP_LIB@ @LIBS@ @ADDITIONAL_LIBS@ -lpthread @LDFLAGS@ +LDFLAGS=$(LIBNDPI) @PCAP_LIB@ @LIBS@ @ADDITIONAL_LIBS@ @LDFLAGS@ HEADERS=intrusion_detection.h reader_util.h $(SRCHOME)/include/ndpi_api.h \ $(SRCHOME)/include/ndpi_typedefs.h $(SRCHOME)/include/ndpi_protocol_ids.h OBJS=ndpiReader.o reader_util.o intrusion_detection.o PREFIX?=@prefix@ ifneq ($(BUILD_MINGW),) -all: - @echo 'Examples disabled due to mingw build.' +SUFFIX:=.exe +CFLAGS+=-I@srcdir@/../windows/WpdPack/Include -I@srcdir@/../windows/WpdPack/Include/pcap +LDFLAGS+=-Wl,-Bstatic -lpthread -Wl,-Bdynamic +ifneq ($(BUILD_MINGW_X64),) +LDFLAGS+=@srcdir@/../windows/WpdPack/Lib/x64/wpcap.lib else +LDFLAGS+=@srcdir@/../windows/WpdPack/Lib/wpcap.lib +endif + +else + +LDFLAGS+=-lpthread -all: ndpiReader @DPDK_TARGET@ +endif + +all: ndpiReader$(SUFFIX) @DPDK_TARGET@ EXECUTABLE_SOURCES := ndpiReader.c ndpiSimpleIntegration.c COMMON_SOURCES := $(filter-out $(EXECUTABLE_SOURCES),$(wildcard *.c )) @@ -24,21 +36,22 @@ COMMON_SOURCES := $(filter-out $(EXECUTABLE_SOURCES),$(wildcard *.c )) libndpiReader.a: $(COMMON_SOURCES:%.c=%.o) $(LIBNDPI) ar rsv libndpiReader.a $(COMMON_SOURCES:%.c=%.o) -ndpiReader: libndpiReader.a $(LIBNDPI) ndpiReader.o +ndpiReader$(SUFFIX): libndpiReader.a $(LIBNDPI) ndpiReader.o $(CC) $(CFLAGS) ndpiReader.o libndpiReader.a -o $@ $(LDFLAGS) -ndpiSimpleIntegration: ndpiSimpleIntegration.o +ndpiSimpleIntegration$(SUFFIX): ndpiSimpleIntegration.o $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) %.o: %.c $(HEADERS) Makefile $(CC) $(CFLAGS) -c $< -o $@ -install: ndpiReader +install: ndpiReader$(SUFFIX) mkdir -p $(DESTDIR)$(PREFIX)/bin/ mkdir -p $(DESTDIR)$(PREFIX)/share/ndpi - cp ndpiReader $(DESTDIR)$(PREFIX)/bin/ + cp ndpiReader$(SUFFIX) $(DESTDIR)$(PREFIX)/bin/ cp protos.txt $(DESTDIR)$(PREFIX)/share/ndpi/ndpiProtos.txt cp mining_hosts.txt $(DESTDIR)$(PREFIX)/share/ndpi/ndpiCustomCategory.txt + [ -f ndpiSimpleIntegration$(SUFFIX) ] && cp ndpiSimpleIntegration$(SUFFIX) $(DESTDIR)$(PREFIX)/bin/ndpiSimpleIntegration$(SUFFIX) || true [ -f build/app/ndpiReader.dpdk ] && cp build/app/ndpiReader.dpdk $(DESTDIR)$(PREFIX)/bin/ || true [ -f ndpiReader.dpdk ] && cp ndpiReader.dpdk $(DESTDIR)$(PREFIX)/bin/ || true @@ -49,7 +62,7 @@ check: cppcheck --template='{file}:{line}:{severity}:{message}' --quiet --enable=all --force -I$(SRCHOME)/include *.c clean: - /bin/rm -f *.o ndpiReader ndpiReader.dpdk + /bin/rm -f *.o ndpiReader ndpiSimpleIntegration ndpiReader$(SUFFIX) ndpiSimpleIntegration$(SUFFIX) ndpiReader.dpdk /bin/rm -f .*.dpdk.cmd .*.o.cmd *.dpdk.map .*.o.d /bin/rm -f _install _postbuild _postinstall _preinstall /bin/rm -rf build @@ -61,5 +74,3 @@ distdir: distclean: clean /bin/rm -f Makefile.dpdk /bin/rm -f Makefile - -endif diff --git a/example/Win32/pcapExample.sln b/example/Win32/pcapExample.sln deleted file mode 100644 index 3c061ed01..000000000 --- a/example/Win32/pcapExample.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual C++ Express 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pcapExample", "pcapExample\pcapExample.vcxproj", "{F6A2C0AE-2110-438A-87E4-7C1CFCE064C6}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F6A2C0AE-2110-438A-87E4-7C1CFCE064C6}.Debug|Win32.ActiveCfg = Debug|Win32 - {F6A2C0AE-2110-438A-87E4-7C1CFCE064C6}.Debug|Win32.Build.0 = Debug|Win32 - {F6A2C0AE-2110-438A-87E4-7C1CFCE064C6}.Release|Win32.ActiveCfg = Release|Win32 - {F6A2C0AE-2110-438A-87E4-7C1CFCE064C6}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/example/Win32/pcapExample.suo b/example/Win32/pcapExample.suo deleted file mode 100644 index 122e224b4..000000000 Binary files a/example/Win32/pcapExample.suo and /dev/null differ diff --git a/example/Win32/pcapExample/pcapExample.cpp b/example/Win32/pcapExample/pcapExample.cpp deleted file mode 100644 index ad7655eea..000000000 --- a/example/Win32/pcapExample/pcapExample.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// pcapExample.cpp : Defines the entry point for the console application. -// - -#include "stdafx.h" - - -int _tmain(int argc, _TCHAR* argv[]) -{ - return 0; -} - diff --git a/example/Win32/pcapExample/pcapExample.vcxproj b/example/Win32/pcapExample/pcapExample.vcxproj deleted file mode 100644 index 87c8e360b..000000000 --- a/example/Win32/pcapExample/pcapExample.vcxproj +++ /dev/null @@ -1,231 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {F6A2C0AE-2110-438A-87E4-7C1CFCE064C6} - Win32Proj - pcapExample - - - - Application - true - Unicode - - - Application - false - true - Unicode - - - - - - - - - - - - - true - - - false - - - - NotUsing - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - C:\ntop\nprobe\nprobe-win-32;C:\ntop\winpcap\Include;C:\ntop\dependencies\nDPI\src\lib\third_party\include;C:\ntop\dependencies\nDPI\src\include;%(AdditionalIncludeDirectories) - - - Console - true - Wsock32.lib;Ws2_32.lib;C:\ntop\winpcap\Lib\Packet.lib;C:\ntop\winpcap\Lib\wpcap.lib;%(AdditionalDependencies) - - - - - Level3 - Use - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/example/Win32/pcapExample/pcapExample.vcxproj.filters b/example/Win32/pcapExample/pcapExample.vcxproj.filters deleted file mode 100644 index a5b3f919e..000000000 --- a/example/Win32/pcapExample/pcapExample.vcxproj.filters +++ /dev/null @@ -1,465 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - diff --git a/example/Win32/pcapExample/pcapExample.vcxproj.user b/example/Win32/pcapExample/pcapExample.vcxproj.user deleted file mode 100644 index 695b5c78b..000000000 --- a/example/Win32/pcapExample/pcapExample.vcxproj.user +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 053dc2ec5..003e19803 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -37,6 +37,8 @@ #else #include #include +#include +#include #endif #include #include @@ -44,7 +46,6 @@ #include #include #include -#include #include #include #include "ndpi_api.h" @@ -52,7 +53,6 @@ #include "../src/lib/third_party/include/ahocorasick.h" #include #include -#include #include #include "reader_util.h" @@ -2996,9 +2996,23 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us t = 0; b = 0; } - strftime(when, sizeof(when), "%d/%b/%Y %H:%M:%S", localtime_r(&pcap_start.tv_sec, &result)); +#ifdef WIN32 + /* localtime() on Windows is thread-safe */ + struct tm * tm_ptr = localtime(&pcap_start.tv_sec); + result = *tm_ptr; +#else + localtime_r(&pcap_start.tv_sec, &result); +#endif + strftime(when, sizeof(when), "%d/%b/%Y %H:%M:%S", &result); printf("\tAnalysis begin: %s\n", when); - strftime(when, sizeof(when), "%d/%b/%Y %H:%M:%S", localtime_r(&pcap_end.tv_sec, &result)); +#ifdef WIN32 + /* localtime() on Windows is thread-safe */ + tm_ptr = localtime(&pcap_end.tv_sec); + result = *tm_ptr; +#else + localtime_r(&pcap_end.tv_sec, &result); +#endif + strftime(when, sizeof(when), "%d/%b/%Y %H:%M:%S", &result); printf("\tAnalysis end: %s\n", when); printf("\tTraffic throughput: %s pps / %s/sec\n", formatPackets(t, buf), formatTraffic(b, 1, buf1)); printf("\tTraffic duration: %.3f sec\n", traffic_duration/1000000); @@ -4442,11 +4456,12 @@ int original_main(int argc, char **argv) { /** @brief Timezone **/ +#ifndef __GNUC__ struct timezone { int tz_minuteswest; /* minutes W of Greenwich */ int tz_dsttime; /* type of dst correction */ }; - +#endif /** @brief Set time diff --git a/example/ndpiSimpleIntegration.c b/example/ndpiSimpleIntegration.c index 42784697a..c668bf7f1 100644 --- a/example/ndpiSimpleIntegration.c +++ b/example/ndpiSimpleIntegration.c @@ -1,6 +1,10 @@ +#ifndef WIN32 #include -#include #include +#else +#include +#endif +#include #include #include #include @@ -130,12 +134,16 @@ static struct nDPI_workflow * init_workflow(char const * const file_or_device) if (access(file_or_device, R_OK) != 0 && errno == ENOENT) { workflow->pcap_handle = pcap_open_live(file_or_device, /* 1536 */ 65535, 1, 250, pcap_error_buffer); } else { +#ifdef WIN32 + workflow->pcap_handle = pcap_open_offline(file_or_device, pcap_error_buffer); +#else workflow->pcap_handle = pcap_open_offline_with_tstamp_precision(file_or_device, PCAP_TSTAMP_PRECISION_MICRO, pcap_error_buffer); +#endif } if (workflow->pcap_handle == NULL) { - fprintf(stderr, "pcap_open_live / pcap_open_offline_with_tstamp_precision: %.*s\n", + fprintf(stderr, "pcap_open_live / pcap_open_offline: %.*s\n", (int) PCAP_ERRBUF_SIZE, pcap_error_buffer); free_workflow(&workflow); return NULL; @@ -994,6 +1002,7 @@ static int processing_threads_error_or_eof(void) static int start_reader_threads(void) { +#ifndef WIN32 sigset_t thread_signal_set, old_signal_set; sigfillset(&thread_signal_set); @@ -1003,6 +1012,7 @@ static int start_reader_threads(void) fprintf(stderr, "pthread_sigmask: %s\n", strerror(errno)); return 1; } +#endif for (int i = 0; i < reader_thread_count; ++i) { reader_threads[i].array_index = i; diff --git a/example/reader_util.c b/example/reader_util.c index bc7444f31..f4fe03504 100644 --- a/example/reader_util.c +++ b/example/reader_util.c @@ -26,16 +26,17 @@ #endif #include +#include +#include #ifdef WIN32 #include /* winsock.h is included automatically */ #include #include +#include #else #include #include -#include -#include #endif #include "reader_util.h" @@ -1581,8 +1582,12 @@ int ndpi_is_datalink_supported(int datalink_type) { case DLT_PPP_SERIAL: case DLT_C_HDLC: case DLT_PPP: +#ifdef DLT_IPV4 case DLT_IPV4: +#endif +#ifdef DLT_IPV6 case DLT_IPV6: +#endif case DLT_EN10MB: case DLT_LINUX_SLL: case DLT_IEEE802_11_RADIO: @@ -1708,15 +1713,19 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow, } break; +#ifdef DLT_IPV4 case DLT_IPV4: type = ETH_P_IP; ip_offset = 0; break; +#endif +#ifdef DLT_IPV6 case DLT_IPV6: type = ETH_P_IPV6; ip_offset = 0; break; +#endif /* IEEE 802.3 Ethernet - 1 */ case DLT_EN10MB: @@ -1878,7 +1887,11 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow, ip_len = ((u_int16_t)iph->ihl * 4); iph6 = NULL; - if(iph->protocol == IPPROTO_IPV6 || iph->protocol == IPPROTO_IPIP) { + if(iph->protocol == IPPROTO_IPV6 +#ifdef IPPROTO_IPIP + || iph->protocol == IPPROTO_IPIP +#endif + ) { ip_offset += ip_len; if(ip_len > 0) goto iph_check; @@ -1914,7 +1927,11 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow, return(nproto); } - if(proto == IPPROTO_IPV6 || proto == IPPROTO_IPIP) { + if(proto == IPPROTO_IPV6 +#ifdef IPPROTO_IPIP + || proto == IPPROTO_IPIP +#endif + ) { if(l4ptr > packet) { /* Better safe than sorry */ ip_offset = (l4ptr - packet); goto iph_check; -- cgit v1.2.3