[meta-oe,RFC] pcapplusplus: add new recipe

Message ID 20220222064130.17190-1-ceggers@arri.de
State New
Headers show
Series [meta-oe,RFC] pcapplusplus: add new recipe | expand

Commit Message

Christian Eggers Feb. 22, 2022, 6:41 a.m. UTC
"A multiplatform C++ library for capturing, parsing and crafting of
network packets"

PcapPlusPlus uses as custom build system (shell script + Makefile).
There were attempts for using cmake but this work has never been
finished.

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
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

Comments

Khem Raj Feb. 23, 2022, 5:21 p.m. UTC | #1
https://errors.yoctoproject.org/Errors/Details/636127/

On Mon, Feb 21, 2022 at 10:41 PM Christian Eggers <ceggers@arri.de> wrote:
>
> "A multiplatform C++ library for capturing, parsing and crafting of
> network packets"
>
> PcapPlusPlus uses as custom build system (shell script + Makefile).
> There were attempts for using cmake but this work has never been
> finished.
>
> Signed-off-by: Christian Eggers <ceggers@arri.de>
> ---
> 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
>
> diff --git a/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus/0001-Fix-timeval-to-timespec-conversions.patch b/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus/0001-Fix-timeval-to-timespec-conversions.patch
> new file mode 100644
> index 000000000000..548a0f0ca0e2
> --- /dev/null
> +++ b/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus/0001-Fix-timeval-to-timespec-conversions.patch
> @@ -0,0 +1,58 @@
> +From 740971bb451e1147e19a1b0498436d2332b01293 Mon Sep 17 00:00:00 2001
> +From: Christian Eggers <ceggers@arri.de>
> +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: Submitted [https://github.com/seladb/PcapPlusPlus/pull/814]
> +
> +Signed-off-by: Christian Eggers <ceggers@arri.de>
> +---
> + 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
> +
> diff --git a/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb b/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb
> new file mode 100644
> index 000000000000..c9cf5adb974f
> --- /dev/null
> +++ b/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb
> @@ -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
> +
> +# 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"
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#95439): https://lists.openembedded.org/g/openembedded-devel/message/95439
> Mute This Topic: https://lists.openembedded.org/mt/89312067/1997914
> Group Owner: openembedded-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [raj.khem@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Christian Eggers Feb. 23, 2022, 6:41 p.m. UTC | #2
On Wednesday, 23 February 2022, 18:21:00 CET, Khem Raj wrote:
> https://errors.yoctoproject.org/Errors/Details/636127/
> 
> NOTE: Applying patch '0001-Fix-timeval-to-timespec-conversions.patch' (sources/meta-openembedded/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus/0001-Fix-timeval-to-timespec-conversions.patch)
> ERROR: Applying patch '0001-Fix-timeval-to-timespec-conversions.patch' on target directory 'TOPDIR/build/tmp/work/mips32r2-yoe-linux/pcapplusplus/gitAUTOINC+1360d0ed91-r0/git'
> CmdError('quilt --quiltrc TOPDIR/build/tmp/work/mips32r2-yoe-linux/pcapplusplus/gitAUTOINC+1360d0ed91-r0/recipe-sysroot-native/etc/quiltrc push', 0, 'stdout: Applying patch 0001-Fix-timeval-to-timespec-conversions.patch
> patching file Pcap++/src/NetworkUtils.cpp
> Hunk #1 FAILED at 169 (different line endings).
> Hunk #2 FAILED at 436 (different line endings).
> 2 out of 2 hunks FAILED -- rejects in file Pcap++/src/NetworkUtils.cpp
> patching file Pcap++/src/PcapFileDevice.cpp
> Hunk #1 FAILED at 188 (different line endings).
> 1 out of 1 hunk FAILED -- rejects in file Pcap++/src/PcapFileDevice.cpp
> Patch 0001-Fix-timeval-to-timespec-conversions.patch does not apply (enforce with -f)

After cloning PcapPlusPlus on my machine, Pcap++/src/PcapFileDevice.cpp has
Windows line endings. The patch has the same for changed lines and the
context.

Is there an implicit conversion from Windows to Unix line endings on
the build machine (e.g. by git)? Are line feeds altered on when sent
via `git send-email`?

For reference, I have a attached the patch file to this email.

regards
Christian
Khem Raj Feb. 23, 2022, 6:45 p.m. UTC | #3
On Wed, Feb 23, 2022 at 10:41 AM Christian Eggers <ceggers@arri.de> wrote:
>
> On Wednesday, 23 February 2022, 18:21:00 CET, Khem Raj wrote:
> > https://errors.yoctoproject.org/Errors/Details/636127/
> >
> > NOTE: Applying patch '0001-Fix-timeval-to-timespec-conversions.patch' (sources/meta-openembedded/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus/0001-Fix-timeval-to-timespec-conversions.patch)
> > ERROR: Applying patch '0001-Fix-timeval-to-timespec-conversions.patch' on target directory 'TOPDIR/build/tmp/work/mips32r2-yoe-linux/pcapplusplus/gitAUTOINC+1360d0ed91-r0/git'
> > CmdError('quilt --quiltrc TOPDIR/build/tmp/work/mips32r2-yoe-linux/pcapplusplus/gitAUTOINC+1360d0ed91-r0/recipe-sysroot-native/etc/quiltrc push', 0, 'stdout: Applying patch 0001-Fix-timeval-to-timespec-conversions.patch
> > patching file Pcap++/src/NetworkUtils.cpp
> > Hunk #1 FAILED at 169 (different line endings).
> > Hunk #2 FAILED at 436 (different line endings).
> > 2 out of 2 hunks FAILED -- rejects in file Pcap++/src/NetworkUtils.cpp
> > patching file Pcap++/src/PcapFileDevice.cpp
> > Hunk #1 FAILED at 188 (different line endings).
> > 1 out of 1 hunk FAILED -- rejects in file Pcap++/src/PcapFileDevice.cpp
> > Patch 0001-Fix-timeval-to-timespec-conversions.patch does not apply (enforce with -f)
>
> After cloning PcapPlusPlus on my machine, Pcap++/src/PcapFileDevice.cpp has
> Windows line endings. The patch has the same for changed lines and the
> context.
>
> Is there an implicit conversion from Windows to Unix line endings on
> the build machine (e.g. by git)? Are line feeds altered on when sent
> via `git send-email`?
>
> For reference, I have a attached the patch file to this email.

maybe inheriting dos2unix would fix this.

>
> regards
> Christian

Patch

diff --git a/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus/0001-Fix-timeval-to-timespec-conversions.patch b/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus/0001-Fix-timeval-to-timespec-conversions.patch
new file mode 100644
index 000000000000..548a0f0ca0e2
--- /dev/null
+++ b/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus/0001-Fix-timeval-to-timespec-conversions.patch
@@ -0,0 +1,58 @@ 
+From 740971bb451e1147e19a1b0498436d2332b01293 Mon Sep 17 00:00:00 2001
+From: Christian Eggers <ceggers@arri.de>
+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: Submitted [https://github.com/seladb/PcapPlusPlus/pull/814]
+
+Signed-off-by: Christian Eggers <ceggers@arri.de>
+---
+ 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
+
diff --git a/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb b/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb
new file mode 100644
index 000000000000..c9cf5adb974f
--- /dev/null
+++ b/meta-oe/recipes-connectivity/pcapplusplus/pcapplusplus_21.11.bb
@@ -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
+
+# 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"