Skip to content

Commit

Permalink
Allow Netinfo to take multiple NetworkInterfaces for stable API
Browse files Browse the repository at this point in the history
Functionality is not implemented though
  • Loading branch information
ChangSpivey committed Dec 4, 2016
1 parent 8af3d59 commit 3f8a944
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() {
println!("{}", SEPARATOR);
println!("");

let mut netinfo = Netinfo::new(net_interface).unwrap();
let mut netinfo = Netinfo::new(&[net_interface]).unwrap();
netinfo.start_async();


Expand Down
8 changes: 5 additions & 3 deletions src/netinfo/netinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ impl Netinfo {
CaptureHandle::list_net_interfaces()
}

/// Constructor for Netinfo.
pub fn new(interface: NetworkInterface) -> Result<Netinfo> {
/// Constructor for Netinfo. WARNING: this function will only handle the first NetworkInterface -
/// tracking multiple interfaces at the same time will be implemented in the future. Until then
/// this signature is there for API stability.
pub fn new(interface: &[NetworkInterface]) -> Result<Netinfo> {
// These variables are shared between the Netinfo object and the closure in CaptureHandle.
let packet_matcher = Arc::new(Mutex::new(PacketMatcher::new()));
let statistics = Arc::new(Mutex::new(NetStatistics::default()));
Expand All @@ -142,7 +144,7 @@ impl Netinfo {

Ok(Netinfo {
capture_handle:
Arc::new(Mutex::new(CaptureHandle::new(interface,
Arc::new(Mutex::new(CaptureHandle::new(&interface[0],
packet_handler_closure)?)),
statistics: statistics,
thread_handle_opt: None,
Expand Down
6 changes: 3 additions & 3 deletions src/netinfo/packet_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ impl CaptureHandle {

/// Create a new `CaptureHandle` for a specific network interface. The interface can be obtained from `list_net_interfaces()`. The second
/// argument is a closure where all packet infos are dealt with.
pub fn new<F: FnMut(PacketInfo) -> Result<()> + Send + 'static>(interface: NetworkInterface, packet_info_handler: F) -> Result<CaptureHandle> {
pub fn new<F: FnMut(PacketInfo) -> Result<()> + Send + 'static>(interface: &NetworkInterface, packet_info_handler: F) -> Result<CaptureHandle> {
info!("CaptureHandle for interface: {:?}", interface);

Ok(CaptureHandle {
channel: datalink::channel(&interface, Config::default()).chain_err(|| ErrorKind::ChannelCreationError)?,
capture_parser: CaptureParser::new(Box::new(packet_info_handler), interface.ips),
channel: datalink::channel(interface, Config::default()).chain_err(|| ErrorKind::ChannelCreationError)?,
capture_parser: CaptureParser::new(Box::new(packet_info_handler), interface.ips.clone()),
})
}
}

0 comments on commit 3f8a944

Please sign in to comment.