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

source

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
Hide additional 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();
}
source

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
Hide additional 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();
}
source

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
Hide additional 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();
}
source

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);
    }
}
source

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
Hide additional 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§

source§

impl Debug for Listner

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V