From f0ba9978e507afb9c04f7078afe04072ccc5dccc Mon Sep 17 00:00:00 2001 From: Rickyc81 Date: Thu, 28 Mar 2024 17:24:56 +0100 Subject: [PATCH 1/4] add vendor to host --- src/host.rs | 11 +++++++++-- tests/integration_test.rs | 18 +++++++++++++++--- tests/test.xml | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/host.rs b/src/host.rs index 45f8988..1c354bf 100644 --- a/src/host.rs +++ b/src/host.rs @@ -10,7 +10,7 @@ use crate::Error; #[derive(Display, Clone, Debug, PartialEq)] pub enum Address { IpAddr(IpAddr), - MacAddr(String), + MacAddr { addr: String, vendor: String }, } #[derive(Clone, Debug)] @@ -97,8 +97,15 @@ fn parse_address_node(node: Node) -> Result { .attribute("addr") .ok_or_else(|| Error::from("expected `addr` attribute in `address` node"))?; + let vendor = node + .attribute("vendor") + .unwrap_or_default(); + match addrtype { - "mac" => Ok(Address::MacAddr(addr.to_string())), + "mac" => Ok(Address::MacAddr { + addr: addr.to_string(), + vendor: vendor.to_string(), + }), _ => { let a = addr .parse::() diff --git a/tests/integration_test.rs b/tests/integration_test.rs index dea2496..6bb1922 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -78,7 +78,10 @@ fn host_ip_address() { let ip_addr = host.addresses().next().unwrap(); match ip_addr { host::Address::IpAddr(s) => assert_eq!(s, &ip), - host::Address::MacAddr(_) => assert!(false), + host::Address::MacAddr { addr, vendor } => { + assert!(!addr.is_empty()); // Verifica che l'indirizzo non sia vuoto + assert!(!vendor.is_empty()); // Verifica che il fornitore non sia vuoto + }, } } @@ -191,6 +194,7 @@ fn host_portinfo_ports() { fn test_issue_one() { let ip: std::net::IpAddr = "192.168.59.138".parse().unwrap(); let mac = "00:0C:29:71:23:2B".to_string(); + let ven = "VMware".to_string(); let host = NMAP_ISSUE_ONE.hosts().next().unwrap(); assert!(host.addresses().count() == 2); @@ -201,14 +205,22 @@ fn test_issue_one() { println!("{:?}", ip_addr); match ip_addr { host::Address::IpAddr(s) => assert_eq!(s, &ip), - host::Address::MacAddr(_) => assert!(false), + host::Address::MacAddr { addr, vendor } => { + assert!(!addr.is_empty()); + assert!(!vendor.is_empty()); + } } let mac_addr = addresses.next().unwrap(); println!("{:?}", mac_addr); match mac_addr { host::Address::IpAddr(_) => assert!(false), - host::Address::MacAddr(s) => assert_eq!(s, &mac), + //host::Address::MacAddr(s) => assert_eq!(s, &mac), + host::Address::MacAddr { addr, vendor } => { + assert_eq!(addr, &mac); + assert_eq!(vendor, &ven); + + } } } diff --git a/tests/test.xml b/tests/test.xml index c340da7..f5a0a12 100644 --- a/tests/test.xml +++ b/tests/test.xml @@ -7,7 +7,7 @@ -
+
From 1b9a94f9f5e348fc8717e55fd94366e3bc3e5ffe Mon Sep 17 00:00:00 2001 From: Rickyc81 Date: Tue, 2 Apr 2024 12:10:11 +0200 Subject: [PATCH 2/4] clean error on xml response test --- tests/issue_1.xml | 2 +- tests/test.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/issue_1.xml b/tests/issue_1.xml index 547fc53..caaf5ef 100644 --- a/tests/issue_1.xml +++ b/tests/issue_1.xml @@ -8,7 +8,7 @@
-
+
diff --git a/tests/test.xml b/tests/test.xml index f5a0a12..c340da7 100644 --- a/tests/test.xml +++ b/tests/test.xml @@ -7,7 +7,7 @@ -
+
From 5ffa992db55bd0f119ebff561f57e5a9e8ea373d Mon Sep 17 00:00:00 2001 From: Rickyc81 Date: Tue, 2 Apr 2024 12:12:05 +0200 Subject: [PATCH 3/4] typo xml test --- tests/issue_1.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/issue_1.xml b/tests/issue_1.xml index caaf5ef..547fc53 100644 --- a/tests/issue_1.xml +++ b/tests/issue_1.xml @@ -8,7 +8,7 @@
-
+
From df19117cf619c127e83453c7d73ad1347799a898 Mon Sep 17 00:00:00 2001 From: Rickyc81 Date: Tue, 2 Apr 2024 12:57:05 +0200 Subject: [PATCH 4/4] vendor as Option --- src/host.rs | 8 +++----- tests/integration_test.rs | 11 ++++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/host.rs b/src/host.rs index 1c354bf..7608e38 100644 --- a/src/host.rs +++ b/src/host.rs @@ -10,7 +10,7 @@ use crate::Error; #[derive(Display, Clone, Debug, PartialEq)] pub enum Address { IpAddr(IpAddr), - MacAddr { addr: String, vendor: String }, + MacAddr { addr: String, vendor: Option }, } #[derive(Clone, Debug)] @@ -97,14 +97,12 @@ fn parse_address_node(node: Node) -> Result { .attribute("addr") .ok_or_else(|| Error::from("expected `addr` attribute in `address` node"))?; - let vendor = node - .attribute("vendor") - .unwrap_or_default(); + let vendor = node.attribute("vendor").map(|v| v.to_string()); match addrtype { "mac" => Ok(Address::MacAddr { addr: addr.to_string(), - vendor: vendor.to_string(), + vendor }), _ => { let a = addr diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 6bb1922..473a47d 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -79,8 +79,8 @@ fn host_ip_address() { match ip_addr { host::Address::IpAddr(s) => assert_eq!(s, &ip), host::Address::MacAddr { addr, vendor } => { - assert!(!addr.is_empty()); // Verifica che l'indirizzo non sia vuoto - assert!(!vendor.is_empty()); // Verifica che il fornitore non sia vuoto + assert!(!addr.is_empty()); + assert!(vendor.is_none()); }, } } @@ -194,7 +194,6 @@ fn host_portinfo_ports() { fn test_issue_one() { let ip: std::net::IpAddr = "192.168.59.138".parse().unwrap(); let mac = "00:0C:29:71:23:2B".to_string(); - let ven = "VMware".to_string(); let host = NMAP_ISSUE_ONE.hosts().next().unwrap(); assert!(host.addresses().count() == 2); @@ -202,23 +201,25 @@ fn test_issue_one() { let mut addresses = host.addresses(); let ip_addr = addresses.next().unwrap(); + println!("{:?}", ip_addr); + match ip_addr { host::Address::IpAddr(s) => assert_eq!(s, &ip), host::Address::MacAddr { addr, vendor } => { assert!(!addr.is_empty()); - assert!(!vendor.is_empty()); } } let mac_addr = addresses.next().unwrap(); + println!("{:?}", mac_addr); + match mac_addr { host::Address::IpAddr(_) => assert!(false), //host::Address::MacAddr(s) => assert_eq!(s, &mac), host::Address::MacAddr { addr, vendor } => { assert_eq!(addr, &mac); - assert_eq!(vendor, &ven); } }