[oe] [meta-oe][PATCH v2] pcapplusplus: add new recipe

2022-02-24 Thread 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.

Signed-off-by: Christian Eggers 
---
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

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 ..1f050815be61
--- /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 
+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 
+---
+ 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(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(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(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 ..e2a2d104cf7e
--- /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/s

Re: [oe] [meta-oe][PATCH v2] pcapplusplus: add new recipe

2022-02-25 Thread Clément Péron
Hi Christian,

On Fri, 25 Feb 2022 at 08:39, Christian Eggers  wrote:
>
> "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.
>
> Signed-off-by: Christian Eggers 
> ---
> RFC --> v2:
> 
> - Update patch status (Submitted --> Accepted)
> - inherit dox2unix (files in GIT have Windows line endings)

We will soon convert to Unix EOL.

> - 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
>
> 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 ..1f050815be61
> --- /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 
> +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 
> +---
> + 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(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(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(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 ..e2a2d104cf7e
> --- /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: