]>
code.octet-stream.net Git - netwatcher/blob - src/lib.rs
3 net
::{IpAddr
, Ipv4Addr
, Ipv6Addr
},
6 #[cfg_attr(windows, path = "imp_win.rs")]
11 #[derive(Debug, Clone, PartialEq, Eq)]
12 pub struct Interface
{
20 pub fn ipv4_ips(&self) -> impl Iterator
<Item
= &Ipv4Addr
> {
21 self.ips
.iter
().filter
_map
(|ip
| match ip
{
22 IpAddr
::V4(v4
) => Some(v4
),
23 IpAddr
::V6(_
) => None
,
27 pub fn ipv6_ips(&self) -> impl Iterator
<Item
= &Ipv6Addr
> {
28 self.ips
.iter
().filter
_map
(|ip
| match ip
{
29 IpAddr
::V4(_
) => None
,
30 IpAddr
::V6(v6
) => Some(v6
),
35 #[derive(Debug, Clone, PartialEq, Eq)]
37 pub interfaces
: HashMap
<IfIndex
, Interface
>,
41 #[derive(Debug, Clone, PartialEq, Eq)]
42 pub struct UpdateDiff
{
43 pub added
: Vec
<IfIndex
>,
44 pub removed
: Vec
<IfIndex
>,
45 pub modified
: HashMap
<IfIndex
, InterfaceDiff
>,
48 #[derive(Debug, Clone, PartialEq, Eq)]
49 pub struct InterfaceDiff
{
50 pub hw_addr_changed
: bool
,
51 pub addrs_added
: Vec
<IpAddr
>,
52 pub addrs_removed
: Vec
<IpAddr
>,
55 #[derive(Debug, Clone, PartialEq, Eq)]
60 pub fn list_interfaces() -> Result
<HashMap
<IfIndex
, Interface
>, Error
> {
61 imp
::list_interfaces()
64 pub struct WatchHandle
;
66 pub fn watch_interfaces
<F
: FnMut(Update
)>(callback
: F
) -> WatchHandle
{
67 // stop current worker thread
68 // post this into a thread that will use it