Skip to content

Commit 52798c9

Browse files
authored
Revert "Use forked LightPcapNg instead of including the sources in 3rdParty (#1792)" (#1816)
This reverts commit 0f4e858.
1 parent 59d0b64 commit 52798c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+6365
-12
lines changed

3rdParty/CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@ add_subdirectory(EndianPortable)
22
add_subdirectory(Getopt-for-Visual-Studio)
33
add_subdirectory(hash-library)
44
add_subdirectory(json)
5+
add_subdirectory(LightPcapNg)
56
add_subdirectory(MemPlumber/MemPlumber)
67

7-
include(FetchContent)
8-
9-
set(LIGHT_PCAPNG_BUILD_TYPE OBJECT CACHE STRING "" FORCE)
10-
11-
FetchContent_Declare(LightPcapNg GIT_REPOSITORY https://github.com/PcapPlusPlus/LightPcapNg GIT_TAG v1.0.0)
12-
13-
FetchContent_MakeAvailable(LightPcapNg)
14-
158
if(PCAPPP_INSTALL)
169
install(
1710
TARGETS light_pcapng

3rdParty/LightPcapNg/CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
project(light_pcapng C)
4+
5+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/LightPcapNg/cmake/")
6+
7+
option(LIGHT_PCAPNG_ZSTD "Build with ZSTD compression support" OFF)
8+
9+
add_library(
10+
light_pcapng
11+
OBJECT
12+
LightPcapNg/src/light_advanced.c
13+
LightPcapNg/src/light_alloc.c
14+
LightPcapNg/src/light_compression.c
15+
LightPcapNg/src/light_internal.c
16+
LightPcapNg/src/light_io.c
17+
LightPcapNg/src/light_manipulate.c
18+
LightPcapNg/src/light_null_compression.c
19+
LightPcapNg/src/light_option.c
20+
LightPcapNg/src/light_pcapng_cont.c
21+
LightPcapNg/src/light_pcapng_ext.c
22+
LightPcapNg/src/light_pcapng.c
23+
LightPcapNg/src/light_platform.c
24+
LightPcapNg/src/light_zstd_compression.c
25+
)
26+
27+
target_compile_definitions(light_pcapng PUBLIC -DUNIVERSAL)
28+
29+
if(BUILD_SHARED_LIBS)
30+
set_property(TARGET light_pcapng PROPERTY POSITION_INDEPENDENT_CODE ON)
31+
endif()
32+
33+
target_include_directories(
34+
light_pcapng
35+
PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/LightPcapNg/include>
36+
)
37+
38+
if(LIGHT_PCAPNG_ZSTD)
39+
find_package(ZSTD)
40+
if(NOT ZSTD_FOUND)
41+
message(FATAL_ERROR "ZSTD required but not found!")
42+
elseif(ZSTD_VERSION_STRING VERSION_LESS "1.4.0")
43+
message(FATAL_ERROR "ZSTD >= 1.4.0 required!")
44+
endif()
45+
add_definitions(-DUSE_Z_STD)
46+
47+
# Linking with objects required CMake 3.12
48+
cmake_minimum_required(VERSION 3.12)
49+
target_link_libraries(light_pcapng PUBLIC ZSTD::ZSTD)
50+
endif()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.o
2+
*.zip
3+
*.gch
4+
*.test
5+
*.pcapng
6+
*.data
7+
*.old
8+
*.a
9+
*.so
10+
*.cap
11+
*.ntar
12+
*.log
13+
*.cmake
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
cmake_minimum_required(VERSION 2.6)
2+
project(light_pcapng C)
3+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_CURRENT_SOURCE_DIR}/include/ -Wall -O2 -fPIC -DUNIVERSAL -g")
4+
5+
add_library(
6+
light_pcapng
7+
SHARED
8+
src/light_io.c
9+
src/light_pcapng.c
10+
src/light_pcapng_cont.c
11+
src/light_platform.c
12+
src/light_manipulate.c
13+
src/light_internal.c
14+
src/light_alloc.c
15+
src/light_advanced.c
16+
src/light_option.c
17+
src/light_pcapng_ext.c
18+
)
19+
20+
add_library(
21+
light_pcapng_static
22+
STATIC
23+
src/light_io.c
24+
src/light_pcapng.c
25+
src/light_pcapng_cont.c
26+
src/light_platform.c
27+
src/light_manipulate.c
28+
src/light_internal.c
29+
src/light_alloc.c
30+
src/light_advanced.c
31+
src/light_option.c
32+
src/light_pcapng_ext.c
33+
)
34+
35+
add_executable(test_read.test src/tests/test_read.c)
36+
target_link_libraries(test_read.test light_pcapng_static)
37+
38+
add_executable(test_read_write.test src/tests/test_read_write.c)
39+
target_link_libraries(test_read_write.test light_pcapng_static)
40+
41+
add_executable(test_mem.test src/tests/test_mem.c)
42+
target_link_libraries(test_mem.test light_pcapng_static)
43+
44+
add_executable(test_histogram.test src/tests/test_histogram.c)
45+
target_link_libraries(test_histogram.test light_pcapng_static)
46+
47+
add_executable(test_subcapture.test src/tests/test_subcapture.c)
48+
target_link_libraries(test_subcapture.test light_pcapng_static)
49+
50+
add_executable(test_feature.test src/tests/test_feature.c)
51+
target_link_libraries(test_feature.test light_pcapng_static)
52+
53+
add_executable(test_flow.test src/tests/test_flow.c)
54+
target_link_libraries(test_flow.test light_pcapng_static)
55+
56+
add_executable(test_feature_advanced.test src/tests/test_feature_advanced.c)
57+
target_link_libraries(test_feature_advanced.test light_pcapng_static dl)
58+
59+
add_executable(test_read_packets.test src/tests/test_read_packets.c)
60+
target_link_libraries(test_read_packets.test light_pcapng_static)
61+
62+
add_executable(test_read_write_packets.test src/tests/test_read_write_packets.c)
63+
target_link_libraries(test_read_write_packets.test light_pcapng_static)
64+
65+
add_executable(test_split.test src/tests/test_split.c)
66+
target_link_libraries(test_split.test light_pcapng_static)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Radu Velea, radu.velea@gmail.com
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
LightPcapNg
2+
3+
Library for general-purpose tracing based on PcapNg[1] file format.
4+
The current project represents work in progress to provide an API
5+
that can read, write and manipulate PcapNg files (possibly outside
6+
normal contexts).
7+
8+
[1] https://github.com/pcapng/pcapng
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2+
# file Copyright.txt or https://cmake.org/licensing for details.
3+
4+
#[=======================================================================[.rst:
5+
FindZSTD
6+
--------
7+
8+
Find the native ZSTD includes and library.
9+
10+
IMPORTED Targets
11+
^^^^^^^^^^^^^^^^
12+
13+
This module defines :prop_tgt:`IMPORTED` target ``ZSTD::ZSTD``, if
14+
ZSTD has been found.
15+
16+
Result Variables
17+
^^^^^^^^^^^^^^^^
18+
19+
This module defines the following variables:
20+
21+
::
22+
23+
ZSTD_INCLUDE_DIRS - where to find zstd.h, etc.
24+
ZSTD_LIBRARIES - List of libraries when using zstd.
25+
ZSTD_FOUND - True if zstd found.
26+
27+
::
28+
29+
ZSTD_VERSION_STRING - The version of zstd found (x.y.z)
30+
ZSTD_VERSION_MAJOR - The major version of zstd
31+
ZSTD_VERSION_MINOR - The minor version of zstd
32+
33+
Debug and Release variants are found separately.
34+
#]=======================================================================]
35+
36+
# Standard names to search for
37+
set(ZSTD_NAMES zstd zstd_static)
38+
set(ZSTD_NAMES_DEBUG zstdd zstd_staticd)
39+
40+
find_path(ZSTD_INCLUDE_DIR NAMES zstd.h PATH_SUFFIXES include)
41+
42+
# Allow ZSTD_LIBRARY to be set manually, as the location of the zstd library
43+
if(NOT ZSTD_LIBRARY)
44+
find_library(ZSTD_LIBRARY_RELEASE NAMES ${ZSTD_NAMES} PATH_SUFFIXES lib)
45+
find_library(ZSTD_LIBRARY_DEBUG NAMES ${ZSTD_NAMES_DEBUG} PATH_SUFFIXES lib)
46+
47+
include(SelectLibraryConfigurations)
48+
select_library_configurations(ZSTD)
49+
endif()
50+
51+
unset(ZSTD_NAMES)
52+
unset(ZSTD_NAMES_DEBUG)
53+
54+
mark_as_advanced(ZSTD_INCLUDE_DIR)
55+
56+
if(ZSTD_INCLUDE_DIR AND EXISTS "${ZSTD_INCLUDE_DIR}/zstd.h")
57+
file(STRINGS "${ZSTD_INCLUDE_DIR}/zstd.h" ZSTD_H REGEX "^#define ZSTD_VERSION_.*$")
58+
59+
string(REGEX REPLACE "^.*ZSTD_VERSION_MAJOR *([0-9]+).*$" "\\1" ZSTD_MAJOR_VERSION "${ZSTD_H}")
60+
string(REGEX REPLACE "^.*ZSTD_VERSION_MINOR *([0-9]+).*$" "\\1" ZSTD_MINOR_VERSION "${ZSTD_H}")
61+
string(REGEX REPLACE "^.*ZSTD_VERSION_RELEASE *([0-9]+).*$" "\\1" ZSTD_PATCH_VERSION "${ZSTD_H}")
62+
set(ZSTD_VERSION_STRING "${ZSTD_MAJOR_VERSION}.${ZSTD_MINOR_VERSION}.${ZSTD_PATCH_VERSION}")
63+
endif()
64+
65+
include(FindPackageHandleStandardArgs)
66+
find_package_handle_standard_args(ZSTD REQUIRED_VARS ZSTD_LIBRARY ZSTD_INCLUDE_DIR VERSION_VAR ZSTD_VERSION_STRING)
67+
68+
if(ZSTD_FOUND)
69+
set(ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR})
70+
71+
if(NOT ZSTD_LIBRARIES)
72+
set(ZSTD_LIBRARIES ${ZSTD_LIBRARY})
73+
endif()
74+
75+
if(NOT TARGET ZSTD::ZSTD)
76+
add_library(ZSTD::ZSTD UNKNOWN IMPORTED)
77+
set_target_properties(ZSTD::ZSTD PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIRS}")
78+
79+
if(ZSTD_LIBRARY_RELEASE)
80+
set_property(TARGET ZSTD::ZSTD APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
81+
set_target_properties(ZSTD::ZSTD PROPERTIES IMPORTED_LOCATION_RELEASE "${ZSTD_LIBRARY_RELEASE}")
82+
endif()
83+
84+
if(ZSTD_LIBRARY_DEBUG)
85+
set_property(TARGET ZSTD::ZSTD APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
86+
set_target_properties(ZSTD::ZSTD PROPERTIES IMPORTED_LOCATION_DEBUG "${ZSTD_LIBRARY_DEBUG}")
87+
endif()
88+
89+
if(NOT ZSTD_LIBRARY_RELEASE AND NOT ZSTD_LIBRARY_DEBUG)
90+
set_target_properties(ZSTD::ZSTD PROPERTIES IMPORTED_LOCATION_RELEASE "${ZSTD_LIBRARY}")
91+
endif()
92+
endif()
93+
endif()
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// light_compression.h
2+
// Created on: Aug 13, 2019
3+
4+
// Copyright (c) 2019 TMEIC Corporation - Robert Kriener
5+
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
24+
#ifndef INCLUDE_LIGHT_COMPRESSION_H_
25+
#define INCLUDE_LIGHT_COMPRESSION_H_
26+
27+
#include <stdint.h>
28+
29+
//This block should include the compression type you want to build for
30+
#if defined(USE_Z_STD)
31+
#include "light_zstd_compression.h"
32+
//Setup some other compression
33+
#elif defined(USE_THIS_COMPRESSION_INSTEAD)
34+
//No compression
35+
#else
36+
#define USE_NULL_COMPRESSION
37+
#include "light_null_compression.h"
38+
#endif
39+
40+
#ifdef __cplusplus
41+
extern "C" {
42+
#endif
43+
44+
struct light_file_t;
45+
46+
//Any compression types to be added need to plug their appropriate code into these functions
47+
48+
//Init anything needed to keep state of your compression or configure your compression here
49+
void light_free_compression_context(_compression_t* context);
50+
_compression_t * light_get_compression_context(int compression_level);
51+
52+
//Init anything needed to keep state of your decompression or configure your decompression here
53+
void light_free_decompression_context(_decompression_t* context);
54+
_decompression_t * light_get_decompression_context();
55+
56+
//Return true if the file at file_path is a compressed file and should be decompressed
57+
int light_is_compressed_file(const char* file_path);
58+
59+
//Return number of decompressed bytes read from file
60+
size_t light_read_compressed(struct light_file_t *fd, void *buf, size_t count);
61+
62+
//Return number of bytes written to file from the provided buffer - do not return the number of compressed bytes written
63+
size_t light_write_compressed(struct light_file_t *fd, const void *buf, size_t count);
64+
65+
//Called when the file being read/written is to be closed - this is called first!
66+
int light_close_compressed(struct light_file_t *fd);
67+
68+
#ifdef __cplusplus
69+
}
70+
#endif
71+
72+
#endif /* INCLUDE_LIGHT_COMPRESSION_H_ */
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// light_compression.h
2+
// Created on: Aug 16, 2019
3+
4+
// Copyright (c) 2019 TMEIC Corporation - Robert Kriener
5+
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
24+
#ifndef INCLUDE_LIGHT_COMPRESSION_FUNCTIONS_H_
25+
#define INCLUDE_LIGHT_COMPRESSION_FUNCTIONS_H_
26+
27+
#include <stdint.h>
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
struct light_file_t;
34+
35+
extern _compression_t * (*get_compression_context_ptr)(int);
36+
extern void(*free_compression_context_ptr)(_compression_t*);
37+
extern _decompression_t * (*get_decompression_context_ptr)();
38+
extern void(*free_decompression_context_ptr)(_decompression_t*);
39+
extern int(*is_compressed_file)(const char*);
40+
extern size_t(*read_compressed)(struct light_file_t *, void *, size_t);
41+
extern size_t(*write_compressed)(struct light_file_t *, const void *, size_t);
42+
extern int(*close_compressed)(struct light_file_t *);
43+
44+
#ifdef __cplusplus
45+
}
46+
#endif
47+
48+
#endif /* INCLUDE_LIGHT_COMPRESSION_FUNCTIONS_H_ */

0 commit comments

Comments
 (0)