From 1dc12276730a679e27d3054d8d3a24d7f01adb88 Mon Sep 17 00:00:00 2001 From: Robert Clipsham Date: Fri, 8 Apr 2022 15:45:49 +0100 Subject: [PATCH 1/4] Fix documentation links --- pnet_datalink/src/lib.rs | 4 ++-- pnet_packet/src/ethernet.rs | 2 +- pnet_packet/src/ip.rs | 2 +- pnet_packet/src/ipv4.rs | 2 +- pnet_packet/src/vlan.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pnet_datalink/src/lib.rs b/pnet_datalink/src/lib.rs index 6ede1ffb..c0a4d5ac 100644 --- a/pnet_datalink/src/lib.rs +++ b/pnet_datalink/src/lib.rs @@ -252,14 +252,14 @@ impl NetworkInterface { } /// Triggered when the driver has signated netif_carrier_on - /// Check https://www.kernel.org/doc/html/latest/networking/operstates.html for more information + /// Check for more information #[cfg(any(target_os = "linux", target_os = "android"))] pub fn is_lower_up(&self) -> bool { self.flags & (pnet_sys::IFF_LOWER_UP as u32) != 0 } /// Triggered when the driver has signated netif_dormant_on - /// Check https://www.kernel.org/doc/html/latest/networking/operstates.html for more information + /// Check for more information #[cfg(any(target_os = "linux", target_os = "android"))] pub fn is_dormant(&self) -> bool { self.flags & (pnet_sys::IFF_DORMANT as u32) != 0 diff --git a/pnet_packet/src/ethernet.rs b/pnet_packet/src/ethernet.rs index b68763d7..1c57a5d9 100644 --- a/pnet_packet/src/ethernet.rs +++ b/pnet_packet/src/ethernet.rs @@ -52,7 +52,7 @@ fn ethernet_header_test() { } /// `EtherTypes` are defined at: -/// http://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml. +/// . /// These values should be used in the `Ethernet` `EtherType` field. /// /// FIXME Should include all diff --git a/pnet_packet/src/ip.rs b/pnet_packet/src/ip.rs index 427247f6..54b2e353 100644 --- a/pnet_packet/src/ip.rs +++ b/pnet_packet/src/ip.rs @@ -13,7 +13,7 @@ use std::fmt; use crate::PrimitiveValues; /// Protocol numbers as defined at: -/// http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml +/// /// Above protocol numbers last updated: 2014-01-16 /// These values should be used in either the IPv4 Next Level Protocol field /// or the IPv6 Next Header field. diff --git a/pnet_packet/src/ipv4.rs b/pnet_packet/src/ipv4.rs index 551206fb..e7e5bab2 100644 --- a/pnet_packet/src/ipv4.rs +++ b/pnet_packet/src/ipv4.rs @@ -29,7 +29,7 @@ pub mod Ipv4Flags { } /// IPv4 header options numbers as defined in -/// http://www.iana.org/assignments/ip-parameters/ip-parameters.xhtml +/// #[allow(non_snake_case)] #[allow(non_upper_case_globals)] pub mod Ipv4OptionNumbers { diff --git a/pnet_packet/src/vlan.rs b/pnet_packet/src/vlan.rs index 476ad127..a4d74126 100644 --- a/pnet_packet/src/vlan.rs +++ b/pnet_packet/src/vlan.rs @@ -24,7 +24,7 @@ impl PrimitiveValues for ClassOfService { } /// IEEE 802.1p classes of service as defined in -/// https://en.wikipedia.org/wiki/IEEE_P802.1p. +/// . #[allow(non_snake_case)] #[allow(non_upper_case_globals)] pub mod ClassesOfService { From 60314692cf1faecb760c2576a5a9da0246c108ff Mon Sep 17 00:00:00 2001 From: Robert Clipsham Date: Fri, 8 Apr 2022 16:17:04 +0100 Subject: [PATCH 2/4] Fix build lifetime issue on macOS --- pnet_datalink/src/bpf.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pnet_datalink/src/bpf.rs b/pnet_datalink/src/bpf.rs index c1c63b18..aaf31a48 100644 --- a/pnet_datalink/src/bpf.rs +++ b/pnet_datalink/src/bpf.rs @@ -91,8 +91,9 @@ pub fn channel(network_interface: &NetworkInterface, config: Config) -> io::Resu for i in 0..attempts { let fd = unsafe { let file_name = format!("/dev/bpf{}", i); + let c_file_name = CString::new(file_name.as_bytes()).unwrap(); libc::open( - CString::new(file_name.as_bytes()).unwrap().as_ptr(), + c_file_name.as_ptr(), libc::O_RDWR, 0, ) From c888bfa2bb1bf920b3ca026aefea090194b13be9 Mon Sep 17 00:00:00 2001 From: Robert Clipsham Date: Fri, 8 Apr 2022 16:17:31 +0100 Subject: [PATCH 3/4] Ensure warnings cause build failures in CI --- .github/workflows/ci.yml | 1 + build.sh | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b7bf4df..684c8e4f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,7 @@ env: CARGO_TERM_COLOR: always PNET_FEATURES: travis pcap serde PNET_MACROS_FEATURES: travis + VERBOSE: 1 jobs: build-ubuntu: diff --git a/build.sh b/build.sh index 0332d2c2..0bd0b291 100644 --- a/build.sh +++ b/build.sh @@ -23,13 +23,13 @@ MACROS_WITH_SYNTEX=0 if [[ -n "$PNET_FEATURES" ]]; then PNET_CARGO_FLAGS="--no-default-features --features \"$PNET_FEATURES\"" else - PNET_CARGO_FLAGS= + PNET_CARGO_FLAGS="" fi if [[ -n "$PNET_MACROS_FEATURES" ]]; then PNET_MACROS_CARGO_FLAGS="--no-default-features --features \"$PNET_MACROS_FEATURES\"" else - PNET_MACROS_CARGO_FLAGS= + PNET_MACROS_CARGO_FLAGS="" fi # FIXME Need to get interface differently on Windows @@ -38,6 +38,8 @@ IPROUTE2=$(which ip) echo $PNET_MACROS_FEATURES | grep -q with-syntex && MACROS_WITH_SYNTEX=1 +PNET_TEST_IFACE="" + if [[ -x "$IFCONFIG" ]]; then PNET_TEST_IFACE=$($IFCONFIG | egrep 'UP| active' | \ perl -pe '/^[A-z0-9]+:([^\n]|\n\t)*status: active/' | \ @@ -60,6 +62,8 @@ if [[ -z "$PNET_TEST_IFACE" && "$SYSTEM" = "Linux" ]]; then done fi +set -euo pipefail + # FIXME Need to link libraries properly on Windows build() { if [[ -x "$CARGO" ]]; then @@ -104,17 +108,17 @@ run_test() { export RUST_TEST_THREADS=1 && case "$SYSTEM" in Linux) - "$SUDO" -E LD_LIBRARY_PATH=$LD_LIBRARY_PATH sh -c "$CARGO build $PNET_CARGO_FLAGS --release && \ - $CARGO test $PNET_CARGO_FLAGS && \ - $CARGO bench --no-run $PNET_CARGO_FLAGS && \ - $CARGO doc $PNET_CARGO_FLAGS" + "$SUDO" -E sh -c "$CARGO build $PNET_CARGO_FLAGS --release && \ + $CARGO test $PNET_CARGO_FLAGS && \ + $CARGO bench --no-run $PNET_CARGO_FLAGS && \ + $CARGO doc $PNET_CARGO_FLAGS" ;; FreeBSD|Darwin) export PNET_TEST_IFACE - "$SUDO" -E DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH bash -c "$CARGO build $PNET_CARGO_FLAGS && \ - $CARGO test $PNET_CARGO_FLAGS && \ - $CARGO bench --no-run $PNET_CARGO_FLAGS && \ - $CARGO doc $PNET_CARGO_FLAGS" + "$SUDO" -E bash -c "$CARGO build $PNET_CARGO_FLAGS && \ + $CARGO test $PNET_CARGO_FLAGS && \ + $CARGO bench --no-run $PNET_CARGO_FLAGS && \ + $CARGO doc $PNET_CARGO_FLAGS" ;; MINGW*|MSYS*) PNET_TEST_IFACE=$PNET_TEST_IFACE RUST_TEST_THREADS=1 $TESTER From 5c3d09d55295733cac7e0d58447b1aed61055d0e Mon Sep 17 00:00:00 2001 From: Robert Clipsham Date: Fri, 8 Apr 2022 16:21:33 +0100 Subject: [PATCH 4/4] Fix fanout example build warnings on macOS --- examples/fanout.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/fanout.rs b/examples/fanout.rs index 211522b8..9899d4d6 100644 --- a/examples/fanout.rs +++ b/examples/fanout.rs @@ -12,11 +12,8 @@ extern crate pnet; extern crate pnet_datalink; -use pnet::datalink::{self, Config, FanoutOption, FanoutType, NetworkInterface}; -use std::env; use std::io::{self, Write}; use std::process; -use std::thread; #[cfg(not(target_os = "linux"))] fn main() { @@ -27,6 +24,9 @@ fn main() { #[cfg(target_os = "linux")] fn main() { use pnet::datalink::Channel::Ethernet; + use pnet::datalink::{self, Config, FanoutOption, FanoutType, NetworkInterface}; + use std::env; + use std::thread; let iface_name = match env::args().nth(1) { Some(n) => n,