From 857b92c386cc97fe46144d3d27325099b93261eb Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Thu, 27 Aug 2020 10:41:16 +0900 Subject: [PATCH 1/8] [WIP] Github Actions for Windows CI --- .github/workflows/rust.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 000000000..917870517 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,22 @@ +name: Rust + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose From 0a1a8be5c3cfdebd056c7debbbd80369667cf354 Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Thu, 27 Aug 2020 12:20:48 +0900 Subject: [PATCH 2/8] Add a step to install npcap sdk. --- .github/workflows/rust.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 917870517..646b0d1de 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,7 +16,18 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Install npcap sdk + shell: bash + run: | + mkdir $TEMP/whatever + curl -O https://nmap.org/npcap/dist/npcap-sdk-1.05.zip + 7z x npcap-sdk-1.05.zip -o$TEMP/whatever + ls $TEMP/whatever/Lib/x64 - name: Build run: cargo build --verbose - name: Run tests - run: cargo test --verbose + shell: bash + run: env LIB=$TEMP/whatever/Lib/x64/ cargo test --verbose + - name: Clean up + shell: bash + run: rm -r $TEMP/whatever \ No newline at end of file From ba86fbd16fd8d58276cc994c0895825c7c14472b Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Thu, 27 Aug 2020 12:43:19 +0900 Subject: [PATCH 3/8] tweak folder name. --- .github/workflows/rust.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 646b0d1de..d90e00c64 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -19,15 +19,18 @@ jobs: - name: Install npcap sdk shell: bash run: | - mkdir $TEMP/whatever + mkdir $TEMP/npcap-sdk + pushd $TEMP/npcap-sdk curl -O https://nmap.org/npcap/dist/npcap-sdk-1.05.zip - 7z x npcap-sdk-1.05.zip -o$TEMP/whatever - ls $TEMP/whatever/Lib/x64 + 7z x npcap-sdk-1.05.zip -o. + ls -l $TEMP/npcap-sdk/Lib/x64 + # echo "::set-env LIB=$LIB:$TEMP/npcap-sdk/Lib/x64" + popd - name: Build run: cargo build --verbose - name: Run tests shell: bash - run: env LIB=$TEMP/whatever/Lib/x64/ cargo test --verbose + run: env LIB=$TEMP/npcap-sdk/Lib/x64/ cargo test --verbose - name: Clean up shell: bash - run: rm -r $TEMP/whatever \ No newline at end of file + run: rm -r $TEMP/npcap-sdk \ No newline at end of file From 171b11771465b5e9f4652c6fdebc148ca52de375 Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Thu, 27 Aug 2020 15:11:34 +0900 Subject: [PATCH 4/8] Add step for winpcap installation. --- .github/workflows/rust.yml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d90e00c64..53caa5b33 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,21 +16,23 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Install npcap sdk + - name: Install WinPcap 4.1.3 + run: cinst -y winpcap --version 4.1.3.20161116 + - name: Install WinPcap 4.1.2 Developer's Pack shell: bash run: | - mkdir $TEMP/npcap-sdk - pushd $TEMP/npcap-sdk - curl -O https://nmap.org/npcap/dist/npcap-sdk-1.05.zip - 7z x npcap-sdk-1.05.zip -o. - ls -l $TEMP/npcap-sdk/Lib/x64 - # echo "::set-env LIB=$LIB:$TEMP/npcap-sdk/Lib/x64" + mkdir $TEMP/winpcap-dp + pushd $TEMP/winpcap-dp + curl -O https://www.winpcap.org/install/bin/WpdPack_4_1_2.zip + 7z x WpdPack_4_1_2.zip -o. + ls -l WpdPack/Lib/x64 + # echo "::set-env LIB=$LIB:$TEMP/winpcap-dp/WpdPack/Lib/x64" popd - name: Build run: cargo build --verbose - name: Run tests shell: bash - run: env LIB=$TEMP/npcap-sdk/Lib/x64/ cargo test --verbose + run: env LIB=$TEMP/winpcap-dp/Lib/x64/ cargo test --verbose - name: Clean up shell: bash - run: rm -r $TEMP/npcap-sdk \ No newline at end of file + run: rm -r $TEMP/winpcap-dp \ No newline at end of file From 40abfa70e3891d9f86ea5a1057388c62abdb40cd Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Thu, 27 Aug 2020 16:11:44 +0900 Subject: [PATCH 5/8] Use correct `LIB` env. --- .github/workflows/rust.yml | 10 +++++----- README.md | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 53caa5b33..680d7e503 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,18 +21,18 @@ jobs: - name: Install WinPcap 4.1.2 Developer's Pack shell: bash run: | - mkdir $TEMP/winpcap-dp - pushd $TEMP/winpcap-dp + mkdir /c/winpcap-dp + pushd /c/winpcap-dp curl -O https://www.winpcap.org/install/bin/WpdPack_4_1_2.zip 7z x WpdPack_4_1_2.zip -o. ls -l WpdPack/Lib/x64 - # echo "::set-env LIB=$LIB:$TEMP/winpcap-dp/WpdPack/Lib/x64" + # echo "::set-env LIB=$LIB:/c/winpcap-dp/WpdPack/Lib/x64" popd - name: Build run: cargo build --verbose - name: Run tests shell: bash - run: env LIB=$TEMP/winpcap-dp/Lib/x64/ cargo test --verbose + run: env LIB='c:\winpcap-dp\WpdPack\Lib\x64' cargo test --verbose - name: Clean up shell: bash - run: rm -r $TEMP/winpcap-dp \ No newline at end of file + run: rm -r /c/winpcap-dp \ No newline at end of file diff --git a/README.md b/README.md index d66088269..a33ecc832 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ See examples for usage. Install [WinPcap](http://www.winpcap.org/install/default.htm). -Place wpcap.dll in your `C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib\` directory on 64 bit -or `C:\Rust\bin\rustlib\i686-pc-windows-gnu\lib\` on 32 bit. +Download the WinPcap [Developer's Pack](https://www.winpcap.org/devel.htm). +Add the `/Lib` or `/Lib/x64` folder to your `LIB` environment variable. ## Linux From c6550c072048bdd7866d62cb2439207a742b60e8 Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Thu, 27 Aug 2020 16:12:29 +0900 Subject: [PATCH 6/8] Fix windows cargo test. --- tests/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lib.rs b/tests/lib.rs index f17ec60d8..7c4eaa1aa 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -61,8 +61,8 @@ impl Packets { } pub fn push(&mut self, - tv_sec: libc::time_t, - tv_usec: libc::suseconds_t, + tv_sec: libc::c_long, + tv_usec: libc::c_long, caplen: u32, len: u32, data: &[u8]) { From b8259cfb664bc23e2a5d48de4097852aa8f22786 Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Thu, 27 Aug 2020 16:27:16 +0900 Subject: [PATCH 7/8] add features test. --- .github/workflows/rust.yml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 680d7e503..32c4f9364 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,6 +8,7 @@ on: env: CARGO_TERM_COLOR: always + LIB: 'c:\winpcap-dp\WpdPack\Lib\x64' jobs: build: @@ -28,11 +29,21 @@ jobs: ls -l WpdPack/Lib/x64 # echo "::set-env LIB=$LIB:/c/winpcap-dp/WpdPack/Lib/x64" popd - - name: Build - run: cargo build --verbose - - name: Run tests - shell: bash - run: env LIB='c:\winpcap-dp\WpdPack\Lib\x64' cargo test --verbose + - name: Build and Test (default) + run: | + cargo build --verbose + cargo test --verbose + cargo clean + - name: Build and Test (tokio) + run: | + cargo build --verbose --features tokio + cargo test --verbose --features tokio + cargo clean + - name: Build and Test (full) + run: | + cargo build --verbose --features full + cargo test --verbose --features full + cargo clean - name: Clean up shell: bash run: rm -r /c/winpcap-dp \ No newline at end of file From 7d6be7bc69aff09ae36cdd6d7c85d23aab5aa00e Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Thu, 27 Aug 2020 16:41:25 +0900 Subject: [PATCH 8/8] fix mac builds. --- tests/lib.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/lib.rs b/tests/lib.rs index 7c4eaa1aa..89215c40c 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -9,6 +9,16 @@ use tempdir::TempDir; use pcap::{Active, Activated, Offline, Capture, Packet, PacketHeader, Linktype, Precision, Error}; +#[cfg(not(windows))] +type time_t = libc::time_t; +#[cfg(windows)] +type time_t = libc::c_long; + +#[cfg(not(windows))] +type suseconds_t = libc::suseconds_t; +#[cfg(windows)] +type suseconds_t = libc::c_long; + #[test] fn read_packet_with_full_data() { let mut capture = capture_from_test_file("packet_snaplen_65535.pcap"); @@ -61,8 +71,8 @@ impl Packets { } pub fn push(&mut self, - tv_sec: libc::c_long, - tv_usec: libc::c_long, + tv_sec: time_t, + tv_usec: suseconds_t, caplen: u32, len: u32, data: &[u8]) { @@ -163,8 +173,8 @@ fn test_raw_fd_api() { let data: Vec = (0..191).cycle().take(N_PACKETS * 1024).collect(); let mut packets = Packets::new(); for i in 0..N_PACKETS { - packets.push(1460408319 + i as libc::time_t, - 1000 + i as libc::suseconds_t, + packets.push(1460408319 + i as time_t, + 1000 + i as suseconds_t, 1024, 1024, &data[i * 1024..(i + 1) * 1024]);