Struct cross_socket::listener::Listner
source · pub struct Listner {
pub options: PacketCaptureOptions,
pub tx: Arc<Mutex<Sender<PacketFrame>>>,
pub rx: Arc<Mutex<Receiver<PacketFrame>>>,
pub stop: Arc<Mutex<bool>>,
pub packets: Arc<Mutex<Vec<PacketFrame>>>,
}Expand description
Listner
Fields§
§options: PacketCaptureOptions§tx: Arc<Mutex<Sender<PacketFrame>>>§rx: Arc<Mutex<Receiver<PacketFrame>>>§stop: Arc<Mutex<bool>>§packets: Arc<Mutex<Vec<PacketFrame>>>Implementations§
source§impl Listner
impl Listner
sourcepub fn new(options: PacketCaptureOptions) -> Listner
pub fn new(options: PacketCaptureOptions) -> Listner
Create new Listner
Examples found in repository?
examples/pcap/dump.rs (line 30)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main(){
// Get default interface information
let default_interface: Interface =
default_net::get_default_interface().expect("Failed to get default interface information");
// No filter. Capture all packets.
let capture_options: PacketCaptureOptions = PacketCaptureOptions {
interface_index: default_interface.index,
interface_name: default_interface.name,
src_ips: HashSet::new(),
dst_ips: HashSet::new(),
src_ports: HashSet::new(),
dst_ports: HashSet::new(),
ether_types: HashSet::new(),
ip_protocols: HashSet::new(),
duration: Duration::from_secs(30),
promiscuous: false,
store: false,
store_limit: 0,
receive_undefined: true,
};
// Create new listener
let listener: Listner = Listner::new(capture_options);
let rx = listener.get_receiver();
// Start capturing packets
let handle = thread::spawn(move || listener.start());
// Print captured packets
while let Ok(msg) = rx.lock().unwrap().recv() {
println!("{:?}", msg);
}
let _result = handle.join().unwrap();
}More examples
examples/pcap/store.rs (line 34)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn main() {
// Get default interface information
let default_interface: Interface =
default_net::get_default_interface().expect("Failed to get default interface information");
// Filter: Protocol: TCP only, Ports: 22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443
let capture_options: PacketCaptureOptions = PacketCaptureOptions {
interface_index: default_interface.index,
interface_name: default_interface.name,
src_ips: HashSet::new(),
dst_ips: HashSet::new(),
src_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
dst_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
ether_types: HashSet::new(),
ip_protocols: [IpNextLevelProtocol::Tcp].iter().cloned().collect(),
duration: Duration::from_secs(30),
promiscuous: false,
store: true,
store_limit: 1000,
receive_undefined: false,
};
// Create new listener
let listener: Listner = Listner::new(capture_options);
let stop = listener.get_stop_handle();
// Stop after 10 seconds
thread::spawn(move || {
thread::sleep(Duration::from_secs(10));
*stop.lock().unwrap() = true;
});
// Start capturing packets
println!("Capturing packets...");
listener.start();
// Print captured packets
for packet in listener.get_packets() {
println!("{:?}", packet);
}
}examples/pcap/handle.rs (line 33)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn main() {
// Get default interface information
let default_interface: Interface =
default_net::get_default_interface().expect("Failed to get default interface information");
// Filter: Protocol: TCP only, Ports: 22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443
let capture_options: PacketCaptureOptions = PacketCaptureOptions {
interface_index: default_interface.index,
interface_name: default_interface.name,
src_ips: HashSet::new(),
dst_ips: HashSet::new(),
src_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
dst_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
ether_types: HashSet::new(),
ip_protocols: [IpNextLevelProtocol::Tcp].iter().cloned().collect(),
duration: Duration::from_secs(30),
promiscuous: false,
store: false,
store_limit: 0,
receive_undefined: false,
};
// Create new listener
let listener: Listner = Listner::new(capture_options);
let rx = listener.get_receiver();
let stop = listener.get_stop_handle();
// Stop after 10 seconds
thread::spawn(move || {
thread::sleep(Duration::from_secs(10));
*stop.lock().unwrap() = true;
});
// Start capturing packets
let handle = thread::spawn(move || listener.start());
// Print captured packets
while let Ok(msg) = rx.lock().unwrap().recv() {
println!("{:?}", msg);
}
let _result = handle.join().unwrap();
}sourcepub fn get_receiver(&self) -> Arc<Mutex<Receiver<PacketFrame>>>
pub fn get_receiver(&self) -> Arc<Mutex<Receiver<PacketFrame>>>
Get progress receiver
Examples found in repository?
examples/pcap/dump.rs (line 31)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main(){
// Get default interface information
let default_interface: Interface =
default_net::get_default_interface().expect("Failed to get default interface information");
// No filter. Capture all packets.
let capture_options: PacketCaptureOptions = PacketCaptureOptions {
interface_index: default_interface.index,
interface_name: default_interface.name,
src_ips: HashSet::new(),
dst_ips: HashSet::new(),
src_ports: HashSet::new(),
dst_ports: HashSet::new(),
ether_types: HashSet::new(),
ip_protocols: HashSet::new(),
duration: Duration::from_secs(30),
promiscuous: false,
store: false,
store_limit: 0,
receive_undefined: true,
};
// Create new listener
let listener: Listner = Listner::new(capture_options);
let rx = listener.get_receiver();
// Start capturing packets
let handle = thread::spawn(move || listener.start());
// Print captured packets
while let Ok(msg) = rx.lock().unwrap().recv() {
println!("{:?}", msg);
}
let _result = handle.join().unwrap();
}More examples
examples/pcap/handle.rs (line 34)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn main() {
// Get default interface information
let default_interface: Interface =
default_net::get_default_interface().expect("Failed to get default interface information");
// Filter: Protocol: TCP only, Ports: 22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443
let capture_options: PacketCaptureOptions = PacketCaptureOptions {
interface_index: default_interface.index,
interface_name: default_interface.name,
src_ips: HashSet::new(),
dst_ips: HashSet::new(),
src_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
dst_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
ether_types: HashSet::new(),
ip_protocols: [IpNextLevelProtocol::Tcp].iter().cloned().collect(),
duration: Duration::from_secs(30),
promiscuous: false,
store: false,
store_limit: 0,
receive_undefined: false,
};
// Create new listener
let listener: Listner = Listner::new(capture_options);
let rx = listener.get_receiver();
let stop = listener.get_stop_handle();
// Stop after 10 seconds
thread::spawn(move || {
thread::sleep(Duration::from_secs(10));
*stop.lock().unwrap() = true;
});
// Start capturing packets
let handle = thread::spawn(move || listener.start());
// Print captured packets
while let Ok(msg) = rx.lock().unwrap().recv() {
println!("{:?}", msg);
}
let _result = handle.join().unwrap();
}sourcepub fn get_stop_handle(&self) -> Arc<Mutex<bool>>
pub fn get_stop_handle(&self) -> Arc<Mutex<bool>>
Get stop handle
Examples found in repository?
examples/pcap/store.rs (line 35)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn main() {
// Get default interface information
let default_interface: Interface =
default_net::get_default_interface().expect("Failed to get default interface information");
// Filter: Protocol: TCP only, Ports: 22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443
let capture_options: PacketCaptureOptions = PacketCaptureOptions {
interface_index: default_interface.index,
interface_name: default_interface.name,
src_ips: HashSet::new(),
dst_ips: HashSet::new(),
src_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
dst_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
ether_types: HashSet::new(),
ip_protocols: [IpNextLevelProtocol::Tcp].iter().cloned().collect(),
duration: Duration::from_secs(30),
promiscuous: false,
store: true,
store_limit: 1000,
receive_undefined: false,
};
// Create new listener
let listener: Listner = Listner::new(capture_options);
let stop = listener.get_stop_handle();
// Stop after 10 seconds
thread::spawn(move || {
thread::sleep(Duration::from_secs(10));
*stop.lock().unwrap() = true;
});
// Start capturing packets
println!("Capturing packets...");
listener.start();
// Print captured packets
for packet in listener.get_packets() {
println!("{:?}", packet);
}
}More examples
examples/pcap/handle.rs (line 35)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn main() {
// Get default interface information
let default_interface: Interface =
default_net::get_default_interface().expect("Failed to get default interface information");
// Filter: Protocol: TCP only, Ports: 22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443
let capture_options: PacketCaptureOptions = PacketCaptureOptions {
interface_index: default_interface.index,
interface_name: default_interface.name,
src_ips: HashSet::new(),
dst_ips: HashSet::new(),
src_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
dst_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
ether_types: HashSet::new(),
ip_protocols: [IpNextLevelProtocol::Tcp].iter().cloned().collect(),
duration: Duration::from_secs(30),
promiscuous: false,
store: false,
store_limit: 0,
receive_undefined: false,
};
// Create new listener
let listener: Listner = Listner::new(capture_options);
let rx = listener.get_receiver();
let stop = listener.get_stop_handle();
// Stop after 10 seconds
thread::spawn(move || {
thread::sleep(Duration::from_secs(10));
*stop.lock().unwrap() = true;
});
// Start capturing packets
let handle = thread::spawn(move || listener.start());
// Print captured packets
while let Ok(msg) = rx.lock().unwrap().recv() {
println!("{:?}", msg);
}
let _result = handle.join().unwrap();
}sourcepub fn get_packets(&self) -> Vec<PacketFrame>
pub fn get_packets(&self) -> Vec<PacketFrame>
Examples found in repository?
examples/pcap/store.rs (line 45)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn main() {
// Get default interface information
let default_interface: Interface =
default_net::get_default_interface().expect("Failed to get default interface information");
// Filter: Protocol: TCP only, Ports: 22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443
let capture_options: PacketCaptureOptions = PacketCaptureOptions {
interface_index: default_interface.index,
interface_name: default_interface.name,
src_ips: HashSet::new(),
dst_ips: HashSet::new(),
src_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
dst_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
ether_types: HashSet::new(),
ip_protocols: [IpNextLevelProtocol::Tcp].iter().cloned().collect(),
duration: Duration::from_secs(30),
promiscuous: false,
store: true,
store_limit: 1000,
receive_undefined: false,
};
// Create new listener
let listener: Listner = Listner::new(capture_options);
let stop = listener.get_stop_handle();
// Stop after 10 seconds
thread::spawn(move || {
thread::sleep(Duration::from_secs(10));
*stop.lock().unwrap() = true;
});
// Start capturing packets
println!("Capturing packets...");
listener.start();
// Print captured packets
for packet in listener.get_packets() {
println!("{:?}", packet);
}
}sourcepub fn start(&self)
pub fn start(&self)
Start capture
Examples found in repository?
examples/pcap/dump.rs (line 33)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main(){
// Get default interface information
let default_interface: Interface =
default_net::get_default_interface().expect("Failed to get default interface information");
// No filter. Capture all packets.
let capture_options: PacketCaptureOptions = PacketCaptureOptions {
interface_index: default_interface.index,
interface_name: default_interface.name,
src_ips: HashSet::new(),
dst_ips: HashSet::new(),
src_ports: HashSet::new(),
dst_ports: HashSet::new(),
ether_types: HashSet::new(),
ip_protocols: HashSet::new(),
duration: Duration::from_secs(30),
promiscuous: false,
store: false,
store_limit: 0,
receive_undefined: true,
};
// Create new listener
let listener: Listner = Listner::new(capture_options);
let rx = listener.get_receiver();
// Start capturing packets
let handle = thread::spawn(move || listener.start());
// Print captured packets
while let Ok(msg) = rx.lock().unwrap().recv() {
println!("{:?}", msg);
}
let _result = handle.join().unwrap();
}More examples
examples/pcap/store.rs (line 43)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn main() {
// Get default interface information
let default_interface: Interface =
default_net::get_default_interface().expect("Failed to get default interface information");
// Filter: Protocol: TCP only, Ports: 22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443
let capture_options: PacketCaptureOptions = PacketCaptureOptions {
interface_index: default_interface.index,
interface_name: default_interface.name,
src_ips: HashSet::new(),
dst_ips: HashSet::new(),
src_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
dst_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
ether_types: HashSet::new(),
ip_protocols: [IpNextLevelProtocol::Tcp].iter().cloned().collect(),
duration: Duration::from_secs(30),
promiscuous: false,
store: true,
store_limit: 1000,
receive_undefined: false,
};
// Create new listener
let listener: Listner = Listner::new(capture_options);
let stop = listener.get_stop_handle();
// Stop after 10 seconds
thread::spawn(move || {
thread::sleep(Duration::from_secs(10));
*stop.lock().unwrap() = true;
});
// Start capturing packets
println!("Capturing packets...");
listener.start();
// Print captured packets
for packet in listener.get_packets() {
println!("{:?}", packet);
}
}examples/pcap/handle.rs (line 42)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn main() {
// Get default interface information
let default_interface: Interface =
default_net::get_default_interface().expect("Failed to get default interface information");
// Filter: Protocol: TCP only, Ports: 22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443
let capture_options: PacketCaptureOptions = PacketCaptureOptions {
interface_index: default_interface.index,
interface_name: default_interface.name,
src_ips: HashSet::new(),
dst_ips: HashSet::new(),
src_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
dst_ports: [22, 80, 443, 4433, 5000, 8080, 8443, 8888, 9000, 9443].iter().cloned().collect(),
ether_types: HashSet::new(),
ip_protocols: [IpNextLevelProtocol::Tcp].iter().cloned().collect(),
duration: Duration::from_secs(30),
promiscuous: false,
store: false,
store_limit: 0,
receive_undefined: false,
};
// Create new listener
let listener: Listner = Listner::new(capture_options);
let rx = listener.get_receiver();
let stop = listener.get_stop_handle();
// Stop after 10 seconds
thread::spawn(move || {
thread::sleep(Duration::from_secs(10));
*stop.lock().unwrap() = true;
});
// Start capturing packets
let handle = thread::spawn(move || listener.start());
// Print captured packets
while let Ok(msg) = rx.lock().unwrap().recv() {
println!("{:?}", msg);
}
let _result = handle.join().unwrap();
}Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Listner
impl Send for Listner
impl Sync for Listner
impl Unpin for Listner
impl UnwindSafe for Listner
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more