Skip to content

Commit

Permalink
Merge pull request #53 from GyulyVGC/npcap_CI_CD
Browse files Browse the repository at this point in the history
Npcap CI/CD (Windows)
  • Loading branch information
GyulyVGC committed Jan 30, 2023
2 parents 6541b2d + 83fea9d commit 661121a
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 34 deletions.
54 changes: 42 additions & 12 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
pull_request:
branches:
- '*'
workflow_call:
secrets:
NPCAP_OEM_URL:
required: true

env:
CARGO_TERM_COLOR: always
Expand All @@ -15,7 +19,7 @@ env:
jobs:
fmt:
name: Rustfmt
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -31,7 +35,7 @@ jobs:

clippy:
name: Clippy
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -48,20 +52,46 @@ jobs:
name: Mac Tests
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

Linux:
Linux:
name: Linux Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install libpcap
run: sudo apt-get install libpcap-dev
- name: Install dependency for alsa-sys
run: sudo apt-get install libasound2-dev
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

Windows:
name: Windows Tests
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Install libpcap
run: sudo apt-get install libpcap-dev
- name: Build
- name: Install npcap sdk
run: |
Invoke-WebRequest -Uri "https://npcap.com/dist/npcap-sdk-1.13.zip" -OutFile "C:/npcap-sdk.zip"
Expand-Archive -LiteralPath C:/npcap-sdk.zip -DestinationPath C:/npcap-sdk
echo "LIB=C:/npcap-sdk/Lib/x64" >> $env:GITHUB_ENV
- name: Install npcap dll
# Secrets are not passed to workflows that are triggered by a pull request from a fork.
# https://docs.github.com/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets
if: github.event_name != 'pull_request'
run: |
Invoke-WebRequest -Uri ${{secrets.NPCAP_OEM_URL}} -OutFile C:/npcap-oem.exe
C:/npcap-oem.exe /S
- name: Build
if: github.event_name != 'pull_request'
run: cargo build --verbose
- name: Run tests
- name: Run tests
if: github.event_name != 'pull_request'
run: cargo test --verbose
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,10 @@ $RECYCLE.BIN/

#####################################################################

# report file generated by the application
# report file generated by the application and country database
*.txt

#folder with gif and images
/img
*.csv
/country_db

#folder with reports
/sniffnet_*
Expand Down
2 changes: 1 addition & 1 deletion src/enums/app_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl fmt::Display for AppProtocol {
if self.eq(&AppProtocol::Other) {
write!(f, "All protocols")
} else {
write!(f, "{:?}", self)
write!(f, "{self:?}")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/enums/ip_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ pub enum IpVersion {

impl fmt::Display for IpVersion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
write!(f, "{self:?}")
}
}
2 changes: 1 addition & 1 deletion src/enums/trans_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ pub enum TransProtocol {

impl fmt::Display for TransProtocol {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
write!(f, "{self:?}")
}
}
6 changes: 3 additions & 3 deletions src/gui/gui_initial_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn initial_page(sniffer: &mut Sniffer) -> Column<Message> {
}
Some(description) => {
#[cfg(not(target_os = "windows"))]
dev_str.push_str(&format!("{}\n", name));
dev_str.push_str(&format!("{name}\n"));
dev_str.push_str(&description);
}
}
Expand All @@ -122,7 +122,7 @@ pub fn initial_page(sniffer: &mut Sniffer) -> Column<Message> {

for addr in dev.addresses {
let address_string = addr.addr.to_string();
dev_str.push_str(&format!("\n {}", address_string));
dev_str.push_str(&format!("\n {address_string}"));
}
dev_str.push_str("\n ");
dev_str_list.push((name, dev_str));
Expand Down Expand Up @@ -329,7 +329,7 @@ pub fn initial_page(sniffer: &mut Sniffer) -> Column<Message> {
let footer_row = Row::new()
.align_items(Alignment::Center)
.push(
Text::new(format!("Sniffnet {} - by Giuliano Bellini ", APP_VERSION))
Text::new(format!("Sniffnet {APP_VERSION} - by Giuliano Bellini "))
.size(FONT_SIZE_FOOTER)
.font(font_footer),
)
Expand Down
13 changes: 6 additions & 7 deletions src/gui/gui_run_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ pub fn run_page(sniffer: &mut Sniffer) -> Column<Message> {
{
(Text::new(sniffer.waiting.len().to_string()).font(ICONS).size(60),
Text::new(format!("No traffic has been observed yet. Waiting for network packets...\n\n\
Network adapter: {}\n\n\
Are you sure you are connected to the internet and you have selected the right adapter?", adapter_name)).font(font))
Network adapter: {adapter_name}\n\n\
Are you sure you are connected to the internet and you have selected the right adapter?")).font(font))
} else {
(Text::new('T'.to_string()).font(ICONS).size(60),
Text::new(format!("No traffic can be observed because the adapter you selected has no active addresses...\n\n\
Network adapter: {}\n\n\
If you are sure you are connected to the internet, try choosing a different adapter.", adapter_name)).font(font))
Network adapter: {adapter_name}\n\n\
If you are sure you are connected to the internet, try choosing a different adapter.")).font(font))
};
body = body
.push(Row::new().height(Length::FillPortion(1)))
Expand Down Expand Up @@ -410,8 +410,7 @@ pub fn run_page(sniffer: &mut Sniffer) -> Column<Message> {

let error_text = Text::new(format!(
"An error occurred! \n\n\
{}",
err_string
{err_string}",
))
.font(font);

Expand All @@ -438,7 +437,7 @@ pub fn run_page(sniffer: &mut Sniffer) -> Column<Message> {
let footer_row = Row::new()
.align_items(Alignment::Center)
.push(
Text::new(format!("Sniffnet {} - by Giuliano Bellini ", APP_VERSION))
Text::new(format!("Sniffnet {APP_VERSION} - by Giuliano Bellini "))
.size(FONT_SIZE_FOOTER)
.font(font_footer),
)
Expand Down
2 changes: 1 addition & 1 deletion src/structs/traffic_chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Chart<Message> for TrafficChart {
.label_style(("notosans", 15).into_font().color(&self.font_color))
.y_label_formatter(&|bytes| match bytes {
0..=999 | -999..=-1 => {
format!("{}", bytes)
format!("{bytes}")
}
1000..=999_999 | -999_999..=-1000 => {
format!("{:.1} {}", *bytes as f64 / 1_000_f64, "k")
Expand Down
7 changes: 3 additions & 4 deletions src/utility/get_formatted_strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ pub fn get_app_count_string(app_count: HashMap<AppProtocol, u128>, tot_packets:
let spaces_string_2 = " ".to_string().repeat(10 - percentage_string.len());

ret_val.push_str(&format!(
" {}:{}{}{}{} \n",
app_proto_string, spaces_string_1, num_string, spaces_string_2, percentage_string
" {app_proto_string}:{spaces_string_1}{num_string}{spaces_string_2}{percentage_string} \n",
));
}
ret_val
Expand Down Expand Up @@ -163,9 +162,9 @@ pub fn get_formatted_bytes_string(bytes: u128) -> String {

if !multiple_transmitted.is_empty() {
// with multiple
format!("{:.1} {}B", n, multiple_transmitted)
format!("{n:.1} {multiple_transmitted}B")
} else {
// no multiple
format!("{} B", n)
format!("{n} B")
}
}

0 comments on commit 661121a

Please sign in to comment.