diff options
Diffstat (limited to 'src/route_monitor/linux.rs')
-rw-r--r-- | src/route_monitor/linux.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/route_monitor/linux.rs b/src/route_monitor/linux.rs new file mode 100644 index 0000000..a08cff2 --- /dev/null +++ b/src/route_monitor/linux.rs @@ -0,0 +1,34 @@ +use failure::Error; +use futures::stream::Stream; +use futures::{Async, Poll}; +use pnetlink::socket::NetlinkProtocol; +use pnetlink::packet::route::RtMsgPacket; +use pnetlink::tokio::{NetlinkSocket, NetlinkCodec}; +use tokio_core::reactor::Handle; +use tokio_io::{AsyncRead, codec::Framed}; +use std::io; + +pub struct RouteListener { + inner: Framed<NetlinkSocket, NetlinkCodec>, +} + +impl RouteListener { + pub fn bind(handle: &Handle) -> io::Result<Self> { + let sock = NetlinkSocket::bind(NetlinkProtocol::Route, 0, handle)?; + + Ok(RouteListener { + inner: AsyncRead::framed(sock, NetlinkCodec {}); + }) + } +} + +impl Stream for RouteListener { + type Item = (); + type Error = Error; + + fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> { + match self.inner.poll() { + Ok(Async::Ready(Some(packet))) + } + } +}
\ No newline at end of file |