Skip to main content

SharedRawPacket

Struct SharedRawPacket 

Source
pub struct SharedRawPacket {
    pub packet: RawPacket,
    /* private fields */
}
Expand description

One raw IP datagram and every joined logical subscription that matched it.

The kernel datagram is captured once and the RawPacket uses the first matching ID in deterministic ascending order as its primary subscription. Use Self::matching_subscription_ids when overlapping logical memberships need to be distinguished.

Fields§

§packet: RawPacket

The received complete IP datagram and primary matching subscription ID.

Implementations§

Source§

impl SharedRawPacket

Source

pub fn packet(&self) -> &RawPacket

Returns the captured complete IP datagram.

Source

pub fn matching_subscription_ids(&self) -> &[SubscriptionId]

Returns every joined logical subscription matched by this datagram.

Examples found in repository?
examples/shared_raw_capture.rs (line 48)
8fn main() -> Result<(), Box<dyn Error>> {
9    let mut args = env::args().skip(1);
10    let Some(group) = args.next() else {
11        print_usage();
12        return Ok(());
13    };
14    let Some(interface) = args.next() else {
15        print_usage();
16        return Ok(());
17    };
18    let source = args.next();
19    if args.next().is_some() {
20        print_usage();
21        return Ok(());
22    }
23
24    let group: IpAddr = group.parse()?;
25    let interface: IpAddr = interface.parse()?;
26    let source_address = source.as_deref().map(str::parse).transpose()?;
27    let mut config = match source_address {
28        Some(source) => RawSubscriptionConfig::ssm_ip(group, source),
29        None => RawSubscriptionConfig::asm_ip(group),
30    };
31    config.interface = Some(interface);
32
33    let mut context = SharedRawContext::new();
34    let id = context.add_subscription(config)?;
35    context.join_subscription(id)?;
36
37    println!("shared raw capture ready");
38    println!("  group:      {group}");
39    println!("  interface:  {interface}");
40    println!("  source:     {}", source.as_deref().unwrap_or("any"));
41    println!("  sub_id:     {}", id.0);
42
43    loop {
44        if let Some(packet) = context.try_recv_any()? {
45            println!(
46                "received {} raw bytes matching {:?}",
47                packet.packet.datagram_len(),
48                packet.matching_subscription_ids()
49            );
50        } else {
51            thread::sleep(Duration::from_millis(10));
52        }
53    }
54}

Trait Implementations§

Source§

impl Clone for SharedRawPacket

Source§

fn clone(&self) -> SharedRawPacket

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SharedRawPacket

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.