From 359959c930849c5326697a8dedccaf477ec769d8 Mon Sep 17 00:00:00 2001 From: OGabrielPereira Date: Sun, 3 Jul 2022 10:54:37 -0300 Subject: [PATCH 1/6] GNU License --- src/main.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main.rs b/src/main.rs index 8aab3ab..d2dccc7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,30 @@ mod ip_fn; use std::env; +/* rusnet -- IPv4 Subnet Calculator + Copyright (C) 2022 Gabriel L. Pereira. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + */ + +/* + * author Gabriel L. Pereira + * version 0.1.0 + * since Jul 1, 2022 + */ + fn main() { let args: Vec = env::args() .collect(); From 15c251c215a25787502561471e5a2b8c373bdf1e Mon Sep 17 00:00:00 2001 From: OGabrielPereira Date: Sun, 3 Jul 2022 11:20:35 -0300 Subject: [PATCH 2/6] implementing infos --- src/info/help.rs | 7 +++++++ src/info/mod.rs | 2 ++ src/info/version.rs | 8 ++++++++ src/main.rs | 4 +++- 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/info/help.rs create mode 100644 src/info/mod.rs create mode 100644 src/info/version.rs diff --git a/src/info/help.rs b/src/info/help.rs new file mode 100644 index 0000000..2079777 --- /dev/null +++ b/src/info/help.rs @@ -0,0 +1,7 @@ +#[allow(dead_code)] +pub fn run(){ + println!("IPv4 Subnet Calculator written in Rust"); + println!("USAGE: \n\trusnet [IP Address] [/Mask]\n"); + println!("\t--h, --help display this help and exit"); + println!("\t--v, --version output version information and exit\n"); +} \ No newline at end of file diff --git a/src/info/mod.rs b/src/info/mod.rs new file mode 100644 index 0000000..c9dddb7 --- /dev/null +++ b/src/info/mod.rs @@ -0,0 +1,2 @@ +pub mod help; +pub mod version; \ No newline at end of file diff --git a/src/info/version.rs b/src/info/version.rs new file mode 100644 index 0000000..8d5d52a --- /dev/null +++ b/src/info/version.rs @@ -0,0 +1,8 @@ +#[allow(dead_code)] +pub fn run(){ + println!("rusnet 0.1.0"); + println!("Copyright (C) 2022 Gabriel L. Pereira."); + println!("This program is free software: you can redistribute it and/or modify."); + println!("This program comes with ABSOLUTELY NO WARRANTY."); + println!("\nWritten by Gabriel L. Pereira "); +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index d2dccc7..81cf7e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ mod ip_fn; +mod info; use std::env; /* rusnet -- IPv4 Subnet Calculator @@ -16,7 +17,7 @@ use std::env; You should have received a copy of the GNU General Public License along with this program. If not, see . - + */ /* @@ -28,6 +29,7 @@ use std::env; fn main() { let args: Vec = env::args() .collect(); + let ip: Vec<&str> = args[1] .split(".") .collect(); From 18afcafb1ef903101ae23366d412d244078a5acd Mon Sep 17 00:00:00 2001 From: OGabrielPereira Date: Mon, 4 Jul 2022 09:00:38 -0300 Subject: [PATCH 3/6] clean code --- src/main.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 81cf7e8..be98d89 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,54 +27,60 @@ use std::env; */ fn main() { + // Get the arguments from the command line let args: Vec = env::args() .collect(); + // Split the first argument into a vector(".") let ip: Vec<&str> = args[1] .split(".") .collect(); + + // Split the second argument("/") let mask: String = args[2] .split("/") .collect(); + + // Parse the mask into a u16 -- String to u16 let mask_parsed: u16 = mask .parse() .unwrap(); + // Parse the ip into a vector of u16 -- Vec<&str> to Vec let mut ip_parsed: Vec = vec![]; for i in 0..ip.len() { - let ip_int: u16 = ip[i] + let ip_u16: u16 = ip[i] .parse() .unwrap(); - ip_parsed.push(ip_int); + ip_parsed.push(ip_u16); } - println!("Net Address => {}.{}.{}.{}", ip_parsed[0], ip_parsed[1], ip_parsed[2], ip_parsed[3]); - let sn = ip_fn::subnet::sn(mask_parsed); + let subnet = ip_fn::subnet::sn(mask_parsed); println!("Subnet Mask => {}.{}.{}.{}", - sn[0], sn[1], sn[2], sn[3]); + subnet[0], subnet[1], subnet[2], subnet[3]); - let bc = ip_fn::broadcast::bc(sn[3]); + let broadcast = ip_fn::broadcast::bc(subnet[3]); println!("Broadcast Address => {}.{}.{}.{}", - ip_parsed[0], ip_parsed[1], ip_parsed[2], bc); + ip_parsed[0], ip_parsed[1], ip_parsed[2], broadcast); - let cl = ip_fn::class::class(ip_parsed[0]); - println!("Standard Class => {}", cl); + let class = ip_fn::class::class(ip_parsed[0]); + println!("Standard Class => {}", class); - let rg = ip_fn::range::rg(ip_parsed[3], sn[3]); + let range = ip_fn::range::rg(ip_parsed[3], subnet[3]); println!("Range => {} ~ {}", - rg[0], rg[1]); + range[0], range[1]); println!("Net Address Binary => {:b}.{:b}.{:b}.{:b}", ip_parsed[0], ip_parsed[1], ip_parsed[2], ip_parsed[3]); println!("Mask Binary => {:b}.{:b}.{:b}.{:b}", - sn[0], sn[1], sn[2], sn[3]); + subnet[0], subnet[1], subnet[2], subnet[3]); println!("Broadcast Address Binary => {:b}.{:b}.{:b}.{:b}", - ip_parsed[0], ip_parsed[1], ip_parsed[2], bc); + ip_parsed[0], ip_parsed[1], ip_parsed[2], broadcast); } \ No newline at end of file From f3f771cc4089b86e10765a40087dbd7fd28fdeab Mon Sep 17 00:00:00 2001 From: OGabrielPereira Date: Wed, 6 Jul 2022 10:10:06 -0300 Subject: [PATCH 4/6] binary ajusts --- src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index be98d89..6041f28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,13 +73,13 @@ fn main() { println!("Range => {} ~ {}", range[0], range[1]); - println!("Net Address Binary => {:b}.{:b}.{:b}.{:b}", + println!("Net Address Binary => {:08b}.{:08b}.{:08b}.{:08b}", ip_parsed[0], ip_parsed[1], ip_parsed[2], ip_parsed[3]); - println!("Mask Binary => {:b}.{:b}.{:b}.{:b}", + println!("Mask Binary => {:08b}.{:08b}.{:08b}.{:08b}", subnet[0], subnet[1], subnet[2], subnet[3]); - println!("Broadcast Address Binary => {:b}.{:b}.{:b}.{:b}", + println!("Broadcast Address Binary => {:08b}.{:08b}.{:08b}.{:08b}", ip_parsed[0], ip_parsed[1], ip_parsed[2], broadcast); From 8ea9780abe745719a375b8825831b4b306b7bd6c Mon Sep 17 00:00:00 2001 From: "Gabriel L. Pereira" Date: Sat, 9 Jul 2022 12:13:49 -0300 Subject: [PATCH 5/6] Update main.rs --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6041f28..f0dfaef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ use std::env; * version 0.1.0 * since Jul 1, 2022 */ - +// Rewrite it with clap && add new mask functions fn main() { // Get the arguments from the command line let args: Vec = env::args() @@ -83,4 +83,4 @@ fn main() { ip_parsed[0], ip_parsed[1], ip_parsed[2], broadcast); -} \ No newline at end of file +} From c867017f8ec6e3a5092d85cd9f57122cd8d7382e Mon Sep 17 00:00:00 2001 From: "Gabriel L. Pereira" Date: Wed, 13 Jul 2022 16:19:57 -0300 Subject: [PATCH 6/6] Update main.rs --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index f0dfaef..9c9696d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ use std::env; */ /* - * author Gabriel L. Pereira + * author Gabriel L. Pereira aka * version 0.1.0 * since Jul 1, 2022 */