Skip to content

Commit

Permalink
Merge pull request #548 from mrmonday/assorted-cleanup
Browse files Browse the repository at this point in the history
Assorted cleanup
  • Loading branch information
mrmonday authored Apr 8, 2022
2 parents c10134b + 5c3d09d commit 8f37c4b
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 20 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env:
CARGO_TERM_COLOR: always
PNET_FEATURES: travis pcap serde
PNET_MACROS_FEATURES: travis
VERBOSE: 1

jobs:
build-ubuntu:
Expand Down
24 changes: 14 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/' | \
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/fanout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion pnet_datalink/src/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions pnet_datalink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.kernel.org/doc/html/latest/networking/operstates.html> 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 <https://www.kernel.org/doc/html/latest/networking/operstates.html> 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
Expand Down
2 changes: 1 addition & 1 deletion pnet_packet/src/ethernet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn ethernet_header_test() {
}

/// `EtherTypes` are defined at:
/// http://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml.
/// <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
Expand Down
2 changes: 1 addition & 1 deletion pnet_packet/src/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// <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.
Expand Down
2 changes: 1 addition & 1 deletion pnet_packet/src/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub mod Ipv4Flags {
}

/// IPv4 header options numbers as defined in
/// http://www.iana.org/assignments/ip-parameters/ip-parameters.xhtml
/// <http://www.iana.org/assignments/ip-parameters/ip-parameters.xhtml>
#[allow(non_snake_case)]
#[allow(non_upper_case_globals)]
pub mod Ipv4OptionNumbers {
Expand Down
2 changes: 1 addition & 1 deletion pnet_packet/src/vlan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// <https://en.wikipedia.org/wiki/IEEE_P802.1p>.
#[allow(non_snake_case)]
#[allow(non_upper_case_globals)]
pub mod ClassesOfService {
Expand Down

0 comments on commit 8f37c4b

Please sign in to comment.