]>
code.octet-stream.net Git - netwatcher/blob - src/lib.rs
9f82092e8d7dc9e5a74da68b09349b98347690cd
3 net
::{IpAddr
, Ipv4Addr
, Ipv6Addr
},
6 #[cfg_attr(windows, path = "imp_win.rs")]
7 #[cfg_attr(target_vendor = "apple", path = "imp_mac.rs")]
13 #[derive(Debug, Clone, PartialEq, Eq)]
14 pub struct Interface
{
22 pub fn ipv4_ips(&self) -> impl Iterator
<Item
= &Ipv4Addr
> {
23 self.ips
.iter
().filter
_map
(|ip
| match ip
{
24 IpAddr
::V4(v4
) => Some(v4
),
25 IpAddr
::V6(_
) => None
,
29 pub fn ipv6_ips(&self) -> impl Iterator
<Item
= &Ipv6Addr
> {
30 self.ips
.iter
().filter
_map
(|ip
| match ip
{
31 IpAddr
::V4(_
) => None
,
32 IpAddr
::V6(v6
) => Some(v6
),
37 #[derive(Debug, Clone, PartialEq, Eq)]
39 pub interfaces
: HashMap
<IfIndex
, Interface
>,
43 #[derive(Debug, Clone, PartialEq, Eq)]
44 pub struct UpdateDiff
{
45 pub added
: Vec
<IfIndex
>,
46 pub removed
: Vec
<IfIndex
>,
47 pub modified
: HashMap
<IfIndex
, InterfaceDiff
>,
50 #[derive(Debug, Clone, PartialEq, Eq)]
51 pub struct InterfaceDiff
{
52 pub hw_addr_changed
: bool
,
53 pub addrs_added
: Vec
<IpAddr
>,
54 pub addrs_removed
: Vec
<IpAddr
>,
57 #[derive(Debug, Clone, PartialEq, Eq)]
62 pub fn list_interfaces() -> Result
<HashMap
<IfIndex
, Interface
>, Error
> {
63 imp
::list_interfaces()
66 pub struct WatchHandle
;
68 pub fn watch_interfaces
<F
: FnMut(Update
)>(callback
: F
) -> WatchHandle
{
69 // stop current worker thread
70 // post this into a thread that will use it