From 8a8d2cc6efea5f8b08eda6bbda9192c777ea463a Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sun, 14 Nov 2021 09:46:58 +0100 Subject: [PATCH] Expose `self.sockets` in `Interface` via iterators This is needed to not loose access to methods on sockets, e.g. iterating over them and closing or checking which ports are being used. --- src/iface/interface.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/iface/interface.rs b/src/iface/interface.rs index 3a4f605..50f9d0f 100644 --- a/src/iface/interface.rs +++ b/src/iface/interface.rs @@ -555,6 +555,16 @@ where &mut self.device } + /// Get an iterator to the inner sockets. + pub fn sockets(&self) -> impl Iterator> { + self.sockets.iter() + } + + /// Get a mutable iterator to the inner sockets. + pub fn sockets_mut(&mut self) -> impl Iterator> { + self.sockets.iter_mut() + } + /// Add an address to a list of subscribed multicast IP addresses. /// /// Returns `Ok(announce_sent)` if the address was added successfully, where `annouce_sent`