]>
code.octet-stream.net Git - netwatcher/blob - src/lib.rs
61e49402d67afee932a878462d309b79cd82fefb
3 net
::{IpAddr
, Ipv4Addr
, Ipv6Addr
},
6 #[cfg_attr(windows, path = "list_win.rs")]
7 #[cfg_attr(target_vendor = "apple", path = "list_mac.rs")]
10 #[cfg_attr(windows, path = "watch_win.rs")]
11 #[cfg_attr(target_vendor = "apple", path = "watch_mac.rs")]
18 #[derive(Debug, Clone, PartialEq, Eq)]
19 pub struct Interface
{
27 pub fn ipv4_ips(&self) -> impl Iterator
<Item
= &Ipv4Addr
> {
28 self.ips
.iter
().filter
_map
(|ip
| match ip
{
29 IpAddr
::V4(v4
) => Some(v4
),
30 IpAddr
::V6(_
) => None
,
34 pub fn ipv6_ips(&self) -> impl Iterator
<Item
= &Ipv6Addr
> {
35 self.ips
.iter
().filter
_map
(|ip
| match ip
{
36 IpAddr
::V4(_
) => None
,
37 IpAddr
::V6(v6
) => Some(v6
),
42 #[derive(Debug, Clone, PartialEq, Eq)]
44 pub interfaces
: HashMap
<IfIndex
, Interface
>,
49 pub fn diff_from_previous(_prev
: &Update
) -> UpdateDiff
{
50 // TODO: real calculation
55 #[derive(Debug, Clone, PartialEq, Eq, Default)]
56 pub struct UpdateDiff
{
57 pub added
: Vec
<IfIndex
>,
58 pub removed
: Vec
<IfIndex
>,
59 pub modified
: HashMap
<IfIndex
, InterfaceDiff
>,
62 #[derive(Debug, Clone, PartialEq, Eq, Default)]
63 pub struct InterfaceDiff
{
64 pub hw_addr_changed
: bool
,
65 pub addrs_added
: Vec
<IpAddr
>,
66 pub addrs_removed
: Vec
<IpAddr
>,
69 #[derive(Debug, Clone, PartialEq, Eq)]
71 // TODO: handle all cases with proper sources
75 pub use list
::list_interfaces
;
76 pub use watch
::{watch_interfaces
, WatchHandle
};