Skip to contentSkip to conversation

pcapplusplus: add new recipe

PATCH In review Christian Eggers 2 participants 2 messages Feb 25, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 pcapplusplus: add new recipe

"A multiplatform C++ library for capturing, parsing and crafting of network packets"

PcapPlusPlus is currently transitioning from a custom build system (shell script + Makefile) to CMake. After this has been merged, SRC_URI must be set the main repository.

---
RFC --> v2:
------------
- Update patch status (Submitted --> Accepted)
- inherit dox2unix (files in GIT have Windows line endings)
- convert patch to unix line endings

v1 --> RFC:
------------
- move to Clément Péron's fork [branch: cmake-ng]
- change recipe to cmake
- add patch for -Wnarrowing warnings/errors
- build shared libraries
- remove RDEPENDS:${PN}-dev (main pkg contains now shared libs)
- add -Wno-psabi to CXXFLAGS

This is the 2nd attempt to move the build system of PcapPlusPlus to CMake. I highly suppose that this will get merged soon.

 ...-Fix-timeval-to-timespec-conversions.patch | 58 +++++++++++++++++++
 .../pcapplusplus/pcapplusplus_21.11.bb        | 33 +++++++++++
 2 files changed, 91 insertions(+)
 create mode 100644 meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus/0001-Fix-timeval-to-timespec-conversions.patch
 create mode 100644 meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb
meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus/0001-Fix-timeval-to-timespec-conversions.patch new file +58 -0
new file mode 100644
index 000000000000..1f050815be61
@@ -0,0 +1,58 @@
+From 740971bb451e1147e19a1b0498436d2332b01293 Mon Sep 17 00:00:00 2001
+From: Christian Eggers <[email protected]>
+Date: Mon, 21 Feb 2022 13:53:49 +0100
+Subject: [PATCH] Fix timeval-to-timespec conversions
+
+Time values returned by gettimeofday() have microseconds in
+timeval::tv_usec while timespec::ts_nsec is nanoseconds.
+
+timeval::tv_usec is 64 bit (at least on some platforms), while
+timespec::tv_nsec is always 'long'. An explicit cast is required to
+avoid -Wnarrowing warnings/errors.
+
+Upstream-Status: Accepted [https://github.com/seladb/PcapPlusPlus/pull/814]
+
+Signed-off-by: Christian Eggers <[email protected]>
+---
+ Pcap++/src/NetworkUtils.cpp   | 4 ++--
+ Pcap++/src/PcapFileDevice.cpp | 2 +-
+ 2 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/Pcap++/src/NetworkUtils.cpp b/Pcap++/src/NetworkUtils.cpp
+index bdbf87f4c380..749853927ecd 100644
+--- a/Pcap++/src/NetworkUtils.cpp
++++ b/Pcap++/src/NetworkUtils.cpp
+@@ -169,7 +169,7 @@ MacAddress NetworkUtils::getMacAddress(IPv4Address ipAddr, PcapLiveDevice* devic
+ 	// create the timeout
+ 	timespec timeout = {
+ 			now.tv_sec + arpTimeout,
+-			now.tv_usec
++			static_cast<long>(now.tv_usec * 1000)
+ 	};
+ 
+ 	// start capturing. The capture is done on another thread, hence "arpPacketRecieved" is running on that thread
+@@ -436,7 +436,7 @@ IPv4Address NetworkUtils::getIPv4Address(std::string hostname, PcapLiveDevice* d
+ 	// create the timeout
+ 	timespec timeout = {
+ 			now.tv_sec + dnsTimeout,
+-			now.tv_usec
++			static_cast<long>(now.tv_usec * 1000)
+ 	};
+ 
+ 	// start capturing. The capture is done on another thread, hence "dnsResponseRecieved" is running on that thread
+diff --git a/Pcap++/src/PcapFileDevice.cpp b/Pcap++/src/PcapFileDevice.cpp
+index 6bf04c1dd31a..256554407c50 100644
+--- a/Pcap++/src/PcapFileDevice.cpp
++++ b/Pcap++/src/PcapFileDevice.cpp
+@@ -188,7 +188,7 @@ bool PcapFileReaderDevice::getNextPacket(RawPacket& rawPacket)
+ 	uint8_t* pMyPacketData = new uint8_t[pkthdr.caplen];
+ 	memcpy(pMyPacketData, pPacketData, pkthdr.caplen);
+ #if defined(PCAP_TSTAMP_PRECISION_NANO)
+-	timespec ts = { pkthdr.ts.tv_sec, pkthdr.ts.tv_usec }; //because we opened with nano second precision 'tv_usec' is actually nanos
++	timespec ts = { pkthdr.ts.tv_sec, static_cast<long>(pkthdr.ts.tv_usec) }; //because we opened with nano second precision 'tv_usec' is actually nanos
+ #else
+ 	struct timeval ts = pkthdr.ts;
+ #endif
+-- 
+2.34.1
+
meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb new file +33 -0
new file mode 100644
index 000000000000..e2a2d104cf7e
@@ -0,0 +1,33 @@
+SUMMARY = "A multiplatform C++ library for capturing, parsing and crafting of network packets"
+HOMEPAGE = "https://pcapplusplus.github.io/"
+BUGTRACKER = "https://github.com/seladb/PcapPlusPlus/issues"
+SECTION = "libs/network"
+LICENSE = "Unlicense"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=911690f51af322440237a253d695d19f"
+
+DEPENDS = "libpcap"
+
+PV = "git${SRCPV}"
+
+# master branch with hand-crafted build system
+#SRC_URI = "git://github.com/seladb/PcapPlusPlus.git;protocol=https;branch=master"
+
+# cmake-ng branch
+SRC_URI = " \
+    git://github.com/clementperon/PcapPlusPlus.git;protocol=https;branch=cmake-ng \
+    file://0001-Fix-timeval-to-timespec-conversions.patch \
+    "
+SRCREV = "1360d0ed91640daf90b3713a4574b8b369990bb3"
+
+S = "${WORKDIR}/git"
+
+inherit cmake dos2unix
+
+# When 'zstd' is not selected, cmake findPackage() finds files from zstd-native.
+# They are not used, but is there a way to avoid this?
+PACKAGECONFIG ??= ""
+PACKAGECONFIG[zstd] = "-DLIGHT_PCAPNG_ZSTD=true,-DLIGHT_PCAPNG_ZSTD=false,zstd"
+
+EXTRA_OECMAKE:append = " -DBUILD_SHARED_LIBS=ON"
+# get rid of "note: parameter passing for argument of type 'xxx' changed in GCC 7.1"
+CXXFLAGS:append = " -Wno-psabi"
Signature · 1 line
2.34.1
#1 lore raw

Hi Christian,

Quoted 8 lines · Christian Eggers

"A multiplatform C++ library for capturing, parsing and crafting of network packets"

PcapPlusPlus is currently transitioning from a custom build system (shell script + Makefile) to CMake. After this has been merged, SRC_URI must be set the main repository.

Quoted 6 lines

---
RFC --> v2:
------------
- Update patch status (Submitted --> Accepted)
- inherit dox2unix (files in GIT have Windows line endings)

We will soon convert to Unix EOL.

Quoted 96 lines

- convert patch to unix line endings

v1 --> RFC:
------------
- move to Clément Péron's fork [branch: cmake-ng]
- change recipe to cmake
- add patch for -Wnarrowing warnings/errors
- build shared libraries
- remove RDEPENDS:${PN}-dev (main pkg contains now shared libs)
- add -Wno-psabi to CXXFLAGS

This is the 2nd attempt to move the build system of PcapPlusPlus to CMake. I highly suppose that this will get merged soon.

 ...-Fix-timeval-to-timespec-conversions.patch | 58 +++++++++++++++++++
 .../pcapplusplus/pcapplusplus_21.11.bb        | 33 +++++++++++
 2 files changed, 91 insertions(+)
 create mode 100644 meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus/0001-Fix-timeval-to-timespec-conversions.patch
 create mode 100644 meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb
meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus/0001-Fix-timeval-to-timespec-conversions.patch new file +58 -0
new file mode 100644
index 000000000000..1f050815be61
@@ -0,0 +1,58 @@
+From 740971bb451e1147e19a1b0498436d2332b01293 Mon Sep 17 00:00:00 2001
+From: Christian Eggers <[email protected]>
+Date: Mon, 21 Feb 2022 13:53:49 +0100
+Subject: [PATCH] Fix timeval-to-timespec conversions
+
+Time values returned by gettimeofday() have microseconds in
+timeval::tv_usec while timespec::ts_nsec is nanoseconds.
+
+timeval::tv_usec is 64 bit (at least on some platforms), while
+timespec::tv_nsec is always 'long'. An explicit cast is required to
+avoid -Wnarrowing warnings/errors.
+
+Upstream-Status: Accepted [https://github.com/seladb/PcapPlusPlus/pull/814]
+
+Signed-off-by: Christian Eggers <[email protected]>
+---
+ Pcap++/src/NetworkUtils.cpp   | 4 ++--
+ Pcap++/src/PcapFileDevice.cpp | 2 +-
+ 2 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/Pcap++/src/NetworkUtils.cpp b/Pcap++/src/NetworkUtils.cpp
+index bdbf87f4c380..749853927ecd 100644
+--- a/Pcap++/src/NetworkUtils.cpp
++++ b/Pcap++/src/NetworkUtils.cpp
+@@ -169,7 +169,7 @@ MacAddress NetworkUtils::getMacAddress(IPv4Address ipAddr, PcapLiveDevice* devic
+       // create the timeout
+       timespec timeout = {
+                       now.tv_sec + arpTimeout,
+-                      now.tv_usec
++                      static_cast<long>(now.tv_usec * 1000)
+       };
+
+       // start capturing. The capture is done on another thread, hence "arpPacketRecieved" is running on that thread
+@@ -436,7 +436,7 @@ IPv4Address NetworkUtils::getIPv4Address(std::string hostname, PcapLiveDevice* d
+       // create the timeout
+       timespec timeout = {
+                       now.tv_sec + dnsTimeout,
+-                      now.tv_usec
++                      static_cast<long>(now.tv_usec * 1000)
+       };
+
+       // start capturing. The capture is done on another thread, hence "dnsResponseRecieved" is running on that thread
+diff --git a/Pcap++/src/PcapFileDevice.cpp b/Pcap++/src/PcapFileDevice.cpp
+index 6bf04c1dd31a..256554407c50 100644
+--- a/Pcap++/src/PcapFileDevice.cpp
++++ b/Pcap++/src/PcapFileDevice.cpp
+@@ -188,7 +188,7 @@ bool PcapFileReaderDevice::getNextPacket(RawPacket& rawPacket)
+       uint8_t* pMyPacketData = new uint8_t[pkthdr.caplen];
+       memcpy(pMyPacketData, pPacketData, pkthdr.caplen);
+ #if defined(PCAP_TSTAMP_PRECISION_NANO)
+-      timespec ts = { pkthdr.ts.tv_sec, pkthdr.ts.tv_usec }; //because we opened with nano second precision 'tv_usec' is actually nanos
++      timespec ts = { pkthdr.ts.tv_sec, static_cast<long>(pkthdr.ts.tv_usec) }; //because we opened with nano second precision 'tv_usec' is actually nanos
+ #else
+       struct timeval ts = pkthdr.ts;
+ #endif
+--
+2.34.1
+
meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb new file +7 -0
new file mode 100644
index 000000000000..e2a2d104cf7e
@@ -0,0 +1,33 @@
+SUMMARY = "A multiplatform C++ library for capturing, parsing and crafting of network packets"
+HOMEPAGE = "https://pcapplusplus.github.io/"
+BUGTRACKER = "https://github.com/seladb/PcapPlusPlus/issues"
+SECTION = "libs/network"
+LICENSE = "Unlicense"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=911690f51af322440237a253d695d19f"
+

meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb line 17

Quoted 10 lines
meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb new file +10 -0
+DEPENDS = "libpcap"
+
+PV = "git${SRCPV}"
+
+# master branch with hand-crafted build system
+#SRC_URI = "git://github.com/seladb/PcapPlusPlus.git;protocol=https;branch=master"
+
+# cmake-ng branch
+SRC_URI = " \
+    git://github.com/clementperon/PcapPlusPlus.git;protocol=https;branch=cmake-ng \

Please don't use my fork, it's still under Dev and I 'push -f' in it frequently.

It should be ready in a couple weeks I hope.

meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb line 27

Quoted 10 lines
meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb new file +10 -0
+    file://0001-Fix-timeval-to-timespec-conversions.patch \
+    "
+SRCREV = "1360d0ed91640daf90b3713a4574b8b369990bb3"
+
+S = "${WORKDIR}/git"
+
+inherit cmake dos2unix
+
+# When 'zstd' is not selected, cmake findPackage() finds files from zstd-native.
+# They are not used, but is there a way to avoid this?

Yes find_package(ZSTD) is always called even when ZSTD is not selected I will fix this.

Thanks for the report,
Regards
Clement

Quoted 9 lines
meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb new file +6 -1
+PACKAGECONFIG ??= ""
+PACKAGECONFIG[zstd] = "-DLIGHT_PCAPNG_ZSTD=true,-DLIGHT_PCAPNG_ZSTD=false,zstd"
+
+EXTRA_OECMAKE:append = " -DBUILD_SHARED_LIBS=ON"
+# get rid of "note: parameter passing for argument of type 'xxx' changed in GCC 7.1"
+CXXFLAGS:append = " -Wno-psabi"
--

2.34.1