diff --git a/src/host.rs b/src/host.rs index 45f8988..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(String), + MacAddr { addr: String, vendor: Option }, } #[derive(Clone, Debug)] @@ -97,8 +97,13 @@ 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").map(|v| v.to_string()); + match addrtype { - "mac" => Ok(Address::MacAddr(addr.to_string())), + "mac" => Ok(Address::MacAddr { + addr: addr.to_string(), + vendor + }), _ => { let a = addr .parse::() diff --git a/tests/integration_test.rs b/tests/integration_test.rs index dea2496..473a47d 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()); + assert!(vendor.is_none()); + }, } } @@ -198,17 +201,27 @@ 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(_) => assert!(false), + host::Address::MacAddr { addr, vendor } => { + assert!(!addr.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); + + } } }