Skip to content

Commit 104237e

Browse files
seladbuilianries
authored andcommitted
(conan-io#14712) pcapplusplus: add version v22.11
* Update recipe to PcapPlusPlus v22.11 * Add `test_v1_package` * Fix typo * Add sources for 22.11 * Trigger CI * Address comment in CMakeLists Co-authored-by: Uilian Ries <[email protected]> * Remove `test_package.cpp` from `test_v1_package` * Try fixing the bin path * Apply changes suggested by @prince-chrismc * Fix bin folder * Fix test_v1_package bin dir * Revert bin location change * Simplify test package Signed-off-by: Uilian Ries <[email protected]> Signed-off-by: Uilian Ries <[email protected]> Co-authored-by: Uilian Ries <[email protected]>
1 parent 214f4fa commit 104237e

File tree

9 files changed

+60
-69
lines changed

9 files changed

+60
-69
lines changed

recipes/pcapplusplus/all/conandata.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ sources:
88
"22.05":
99
url: "https://github.com/seladb/PcapPlusPlus/archive/v22.05.tar.gz"
1010
sha256: "5f299c4503bf5d3c29f82b8d876a19be7dea29c2aadcb52f2f3b394846c21da9"
11+
"22.11":
12+
url: "https://github.com/seladb/PcapPlusPlus/archive/v22.11.tar.gz"
13+
sha256: "3172f12f2f8a8902ae1ad6be5d65c3059c42c49c1a28e97e5d8d25a48b05e44f"
1114
patches:
1215
"21.05":
1316
- patch_file: "patches/0001-Pass-CXXFLAGS-CPPFLAGS-when-compiling-3rd-party-sour.patch"
@@ -50,3 +53,9 @@ patches:
5053
patch_description: Fix md5 include configuration
5154
patch_type: conan
5255
base_path: source_subfolder
56+
57+
"22.11":
58+
- patch_file: "patches/0002-Pass-CXXFLAGS-CPPFLAGS-when-compiling-3rd-party-sour.patch"
59+
patch_description: Pass CXXFLAGS and CPPFLAGS when-compiling 3rd party source
60+
patch_type: conan
61+
base_path: "source_subfolder"

recipes/pcapplusplus/all/conanfile.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ def config_options(self):
4040

4141
def requirements(self):
4242
if self.settings.os == "Windows":
43-
self.requires("pthreads4w/3.0.0")
4443
self.requires("npcap/1.70")
44+
if self.version < "22.11":
45+
self.requires("pthreads4w/3.0.0")
4546
else:
4647
self.requires("libpcap/1.9.1")
4748

@@ -86,9 +87,10 @@ def _build_windows(self):
8687
config_args = [
8788
"configure-windows-visual-studio.bat",
8889
"--pcap-sdk", self.deps_cpp_info["npcap"].rootpath,
89-
"--pthreads-home", self.deps_cpp_info["pthreads4w"].rootpath,
9090
"--vs-version", "vs2015",
9191
]
92+
if self.version < "22.11":
93+
config_args += ["--pthreads-home", self.deps_cpp_info["pthreads4w"].rootpath]
9294
self.run(" ".join(config_args), run_environment=True)
9395
msbuild = MSBuild(self)
9496
targets = ['Common++', 'Packet++', 'Pcap++']
@@ -120,7 +122,7 @@ def package(self):
120122

121123
def package_info(self):
122124
self.cpp_info.libs = ["Pcap++", "Packet++", "Common++"]
123-
if self.settings.os in ("FreeBSD", "Linux"):
125+
if self.version < "22.11" and self.settings.os in ("FreeBSD", "Linux"):
124126
self.cpp_info.system_libs.append("pthread")
125127
if self.settings.os == "Macos":
126128
self.cpp_info.frameworks.extend(["CoreFoundation", "Security", "SystemConfiguration"])
-447 Bytes
Binary file not shown.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
cmake_minimum_required(VERSION 3.1)
2-
project(test_package)
1+
cmake_minimum_required(VERSION 3.8)
2+
project(test_package LANGUAGES CXX)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup()
4+
find_package(pcapplusplus REQUIRED CONFIG)
65

76
add_executable(${PROJECT_NAME} test_package.cpp)
8-
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
7+
target_link_libraries(${PROJECT_NAME} pcapplusplus::pcapplusplus)
Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
from conan import ConanFile
22
from conan.tools.build import can_run
3-
from conans import CMake
3+
from conan.tools.cmake import cmake_layout, CMake
44
import os
5-
import shutil
65

76

8-
class PcapplusplusTestConan(ConanFile):
9-
settings = "os", "compiler", "build_type", "arch"
10-
generators = "cmake"
7+
class TestPackageConan(ConanFile):
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
10+
test_type = "explicit"
1111

1212
def requirements(self):
1313
self.requires(self.tested_reference_str)
14-
if can_run(self) and self.settings.os == "Windows":
15-
self.requires("libpcap/1.10.1")
1614

17-
def configure(self):
18-
if can_run(self) and self.settings.os == "Windows":
19-
self.options["libpcap"].shared = True
15+
def layout(self):
16+
cmake_layout(self)
2017

2118
def build(self):
2219
cmake = CMake(self)
@@ -25,14 +22,5 @@ def build(self):
2522

2623
def test(self):
2724
if can_run(self):
28-
if self.settings.os == "Windows":
29-
# Use libpcap DLL as a replacement for npcap DLL
30-
# It will not provide all the functions
31-
# but it will cover enough to check that what we compiled is correct
32-
shutil.copy(
33-
os.path.join(self.deps_cpp_info['libpcap'].bin_paths[0], "pcap.dll"),
34-
os.path.join("bin", "wpcap.dll")
35-
)
36-
bin_path = os.path.join("bin", "test_package")
37-
pcap_file_path = os.path.join(self.source_folder, "1_packet.pcap")
38-
self.run(f"{bin_path} {pcap_file_path}", run_environment=True)
25+
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
26+
self.run(bin_path, env="conanrun")
Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,8 @@
1+
#include <cstdlib>
12
#include <iostream>
2-
#include <IPv4Layer.h>
3-
#include <Packet.h>
4-
#include <PcapFileDevice.h>
3+
#include <PcapPlusPlusVersion.h>
54

6-
int main(int argc, char **argv) {
7-
if (argc < 2) {
8-
std::cerr << "ERROR: Need at least one argument" << std::endl;
9-
return 1;
10-
}
11-
12-
// open a pcap file for reading
13-
pcpp::PcapFileReaderDevice reader(argv[1]);
14-
if (!reader.open()) {
15-
std::cerr << "ERROR: Error opening the pcap file" << std::endl;
16-
return 1;
17-
}
18-
19-
// read the first (and only) packet from the file
20-
pcpp::RawPacket rawPacket;
21-
if (!reader.getNextPacket(rawPacket)) {
22-
std::cerr << "ERROR: Couldn't read the first packet in the file" << std::endl;
23-
return 1;
24-
}
25-
26-
// parse the raw packet into a parsed packet
27-
pcpp::Packet parsedPacket(&rawPacket);
28-
29-
// verify the packet is IPv4
30-
if (parsedPacket.isPacketOfType(pcpp::IPv4)) {
31-
// extract source and dest IPs
32-
pcpp::IPv4Address srcIP = parsedPacket.getLayerOfType<pcpp::IPv4Layer>()->getSrcIPv4Address();
33-
pcpp::IPv4Address destIP = parsedPacket.getLayerOfType<pcpp::IPv4Layer>()->getDstIPv4Address();
34-
35-
// print source and dest IPs
36-
std::cout << "Source IP is '" << srcIP.toString() << "'; Dest IP is '" << destIP.toString() << "'" << std::endl;
37-
}
38-
39-
// close the file
40-
reader.close();
41-
42-
return 0;
5+
int main() {
6+
std::cout << "PCAP++ VERSION: " << pcpp::getPcapPlusPlusVersionFull() << std::endl;
7+
return EXIT_SUCCESS;
438
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
8+
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from conans import ConanFile, CMake
2+
from conan.tools.build import cross_building
3+
import os
4+
5+
6+
class TestPackageV1Conan(ConanFile):
7+
settings = "os", "arch", "compiler", "build_type"
8+
generators = "cmake", "cmake_find_package_multi"
9+
10+
def build(self):
11+
cmake = CMake(self)
12+
cmake.configure()
13+
cmake.build()
14+
15+
def test(self):
16+
if not cross_building(self):
17+
bin_path = os.path.join("bin", "test_package")
18+
self.run(bin_path, run_environment=True)

recipes/pcapplusplus/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ versions:
55
folder: all
66
"22.05":
77
folder: all
8+
"22.11":
9+
folder: all

0 commit comments

Comments
 (0)