Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pcapplusplus: add version v22.11 #14712

Merged
merged 15 commits into from
Jan 25, 2023
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 not shown.
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()

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
seladb marked this conversation as resolved.
Show resolved Hide resolved
38 changes: 38 additions & 0 deletions recipes/pcapplusplus/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from conan import ConanFile
from conan.tools.build import can_run
from conans import CMake
import os
import shutil


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

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 build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

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)
43 changes: 43 additions & 0 deletions recipes/pcapplusplus/all/test_v1_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file can be removed. Re-use directly from test_package folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 4a0959d

#include <IPv4Layer.h>
#include <Packet.h>
#include <PcapFileDevice.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;
}
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