diff --git a/src/address_family.rs b/src/address_family.rs new file mode 100644 index 00000000..4e210b9f --- /dev/null +++ b/src/address_family.rs @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT + +use std::net::IpAddr; + +use crate::AddressFamily; + +impl From for AddressFamily { + fn from(v: IpAddr) -> Self { + match v { + IpAddr::V4(_) => AddressFamily::Inet, + IpAddr::V6(_) => AddressFamily::Inet6, + } + } +} diff --git a/src/lib.rs b/src/lib.rs index b391941d..037c57ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,6 +23,7 @@ //! [rtnetlink_url]: https://docs.rs/rtnetlink pub mod address; +mod address_family; pub mod link; pub mod neighbour; pub mod neighbour_table; diff --git a/src/neighbour/address.rs b/src/neighbour/address.rs index 8063bfc7..94e7e67d 100644 --- a/src/neighbour/address.rs +++ b/src/neighbour/address.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT -use std::net::{Ipv4Addr, Ipv6Addr}; +use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use netlink_packet_core::{DecodeError, Emitable}; @@ -51,6 +51,15 @@ impl Emitable for NeighbourAddress { } } +impl From for NeighbourAddress { + fn from(v: IpAddr) -> Self { + match v { + IpAddr::V4(a) => a.into(), + IpAddr::V6(a) => a.into(), + } + } +} + impl From for NeighbourAddress { fn from(v: Ipv4Addr) -> Self { Self::Inet(v)