pub struct RawPacket {
pub subscription_id: SubscriptionId,
pub datagram: Bytes,
pub source_ip: Option<IpAddr>,
pub group: Option<IpAddr>,
pub ip_protocol: Option<u8>,
pub metadata: ReceiveMetadata,
}Expand description
A received raw multicast IP datagram.
Fields§
§subscription_id: SubscriptionIdThe subscription through which this datagram was received.
datagram: BytesThe complete received IP datagram bytes, including the IP header.
source_ip: Option<IpAddr>The parsed source IP address, if it was cheaply available.
group: Option<IpAddr>The parsed destination/group IP address, if it was cheaply available.
ip_protocol: Option<u8>The parsed IP protocol / next-header value, if it was cheaply available.
metadata: ReceiveMetadataAdditional receive context supplied by the platform layer.
Implementations§
Source§impl RawPacket
impl RawPacket
Sourcepub fn datagram_len(&self) -> usize
pub fn datagram_len(&self) -> usize
Returns the length of the complete datagram in bytes.
Examples found in repository?
examples/shared_raw_capture.rs (line 47)
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§
Auto Trait Implementations§
impl !Freeze for RawPacket
impl RefUnwindSafe for RawPacket
impl Send for RawPacket
impl Sync for RawPacket
impl Unpin for RawPacket
impl UnsafeUnpin for RawPacket
impl UnwindSafe for RawPacket
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