Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::Error;
#[derive(Display, Clone, Debug, PartialEq)]
pub enum Address {
IpAddr(IpAddr),
MacAddr(String),
MacAddr { addr: String, vendor: Option<String> },
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -97,8 +97,13 @@ fn parse_address_node(node: Node) -> Result<Address, Error> {
.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::<IpAddr>()
Expand Down
19 changes: 16 additions & 3 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
},
}
}

Expand Down Expand Up @@ -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);

}
}
}

Expand Down