Skip to content

Commit

Permalink
(#14712) pcapplusplus: add version v22.11
Browse files Browse the repository at this point in the history
* 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 <uilianries@gmail.com>

* 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 <uilianries@gmail.com>

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
seladb and uilianries authored Jan 25, 2023
1 parent 1f4f8a3 commit 454af42
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 69 deletions.
9 changes: 9 additions & 0 deletions recipes/pcapplusplus/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ sources:
"22.05":
url: "https://github.com/seladb/PcapPlusPlus/archive/v22.05.tar.gz"
sha256: "5f299c4503bf5d3c29f82b8d876a19be7dea29c2aadcb52f2f3b394846c21da9"
"22.11":
url: "https://github.com/seladb/PcapPlusPlus/archive/v22.11.tar.gz"
sha256: "3172f12f2f8a8902ae1ad6be5d65c3059c42c49c1a28e97e5d8d25a48b05e44f"
patches:
"21.05":
- patch_file: "patches/0001-Pass-CXXFLAGS-CPPFLAGS-when-compiling-3rd-party-sour.patch"
Expand Down Expand Up @@ -50,3 +53,9 @@ patches:
patch_description: Fix md5 include configuration
patch_type: conan
base_path: source_subfolder

"22.11":
- patch_file: "patches/0002-Pass-CXXFLAGS-CPPFLAGS-when-compiling-3rd-party-sour.patch"
patch_description: Pass CXXFLAGS and CPPFLAGS when-compiling 3rd party source
patch_type: conan
base_path: "source_subfolder"
8 changes: 5 additions & 3 deletions recipes/pcapplusplus/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ def config_options(self):

def requirements(self):
if self.settings.os == "Windows":
self.requires("pthreads4w/3.0.0")
self.requires("npcap/1.70")
if self.version < "22.11":
self.requires("pthreads4w/3.0.0")
else:
self.requires("libpcap/1.9.1")

Expand Down Expand Up @@ -86,9 +87,10 @@ def _build_windows(self):
config_args = [
"configure-windows-visual-studio.bat",
"--pcap-sdk", self.deps_cpp_info["npcap"].rootpath,
"--pthreads-home", self.deps_cpp_info["pthreads4w"].rootpath,
"--vs-version", "vs2015",
]
if self.version < "22.11":
config_args += ["--pthreads-home", self.deps_cpp_info["pthreads4w"].rootpath]
self.run(" ".join(config_args), run_environment=True)
msbuild = MSBuild(self)
targets = ['Common++', 'Packet++', 'Pcap++']
Expand Down Expand Up @@ -120,7 +122,7 @@ def package(self):

def package_info(self):
self.cpp_info.libs = ["Pcap++", "Packet++", "Common++"]
if self.settings.os in ("FreeBSD", "Linux"):
if self.version < "22.11" and self.settings.os in ("FreeBSD", "Linux"):
self.cpp_info.system_libs.append("pthread")
if self.settings.os == "Macos":
self.cpp_info.frameworks.extend(["CoreFoundation", "Security", "SystemConfiguration"])
Expand Down
Binary file removed recipes/pcapplusplus/all/test_package/1_packet.pcap
Binary file not shown.
9 changes: 4 additions & 5 deletions recipes/pcapplusplus/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(pcapplusplus REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} pcapplusplus::pcapplusplus)
30 changes: 9 additions & 21 deletions recipes/pcapplusplus/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
from conan import ConanFile
from conan.tools.build import can_run
from conans import CMake
from conan.tools.cmake import cmake_layout, CMake
import os
import shutil


class PcapplusplusTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)
if can_run(self) and self.settings.os == "Windows":
self.requires("libpcap/1.10.1")

def configure(self):
if can_run(self) and self.settings.os == "Windows":
self.options["libpcap"].shared = True
def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
Expand All @@ -25,14 +22,5 @@ def build(self):

def test(self):
if can_run(self):
if self.settings.os == "Windows":
# Use libpcap DLL as a replacement for npcap DLL
# It will not provide all the functions
# but it will cover enough to check that what we compiled is correct
shutil.copy(
os.path.join(self.deps_cpp_info['libpcap'].bin_paths[0], "pcap.dll"),
os.path.join("bin", "wpcap.dll")
)
bin_path = os.path.join("bin", "test_package")
pcap_file_path = os.path.join(self.source_folder, "1_packet.pcap")
self.run(f"{bin_path} {pcap_file_path}", run_environment=True)
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
45 changes: 5 additions & 40 deletions recipes/pcapplusplus/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,8 @@
#include <cstdlib>
#include <iostream>
#include <IPv4Layer.h>
#include <Packet.h>
#include <PcapFileDevice.h>
#include <PcapPlusPlusVersion.h>

int main(int argc, char **argv) {
if (argc < 2) {
std::cerr << "ERROR: Need at least one argument" << std::endl;
return 1;
}

// open a pcap file for reading
pcpp::PcapFileReaderDevice reader(argv[1]);
if (!reader.open()) {
std::cerr << "ERROR: Error opening the pcap file" << std::endl;
return 1;
}

// read the first (and only) packet from the file
pcpp::RawPacket rawPacket;
if (!reader.getNextPacket(rawPacket)) {
std::cerr << "ERROR: Couldn't read the first packet in the file" << std::endl;
return 1;
}

// parse the raw packet into a parsed packet
pcpp::Packet parsedPacket(&rawPacket);

// verify the packet is IPv4
if (parsedPacket.isPacketOfType(pcpp::IPv4)) {
// extract source and dest IPs
pcpp::IPv4Address srcIP = parsedPacket.getLayerOfType<pcpp::IPv4Layer>()->getSrcIPv4Address();
pcpp::IPv4Address destIP = parsedPacket.getLayerOfType<pcpp::IPv4Layer>()->getDstIPv4Address();

// print source and dest IPs
std::cout << "Source IP is '" << srcIP.toString() << "'; Dest IP is '" << destIP.toString() << "'" << std::endl;
}

// close the file
reader.close();

return 0;
int main() {
std::cout << "PCAP++ VERSION: " << pcpp::getPcapPlusPlusVersionFull() << std::endl;
return EXIT_SUCCESS;
}
8 changes: 8 additions & 0 deletions recipes/pcapplusplus/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
18 changes: 18 additions & 0 deletions recipes/pcapplusplus/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


class TestPackageV1Conan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
2 changes: 2 additions & 0 deletions recipes/pcapplusplus/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ versions:
folder: all
"22.05":
folder: all
"22.11":
folder: all

0 comments on commit 454af42

Please sign in to comment.