pub struct RawSubscriptionConfig {
pub group: IpAddr,
pub source: SourceFilter,
pub interface: Option<IpAddr>,
pub interface_index: Option<u32>,
}Expand description
Configuration for raw multicast IP datagram receive.
Unlike SubscriptionConfig, this configuration is not tied to a UDP
destination port. It represents multicast membership and interface
selection only.
Fields§
§group: IpAddrThe destination multicast group to join.
source: SourceFilterThe source filtering mode for the subscription.
interface: Option<IpAddr>The local interface address to join on, if explicitly specified.
interface_index: Option<u32>The local IPv6 interface index to join on, if explicitly specified.
Implementations§
Source§impl RawSubscriptionConfig
impl RawSubscriptionConfig
Sourcepub fn validate(&self) -> Result<(), McrxError>
pub fn validate(&self) -> Result<(), McrxError>
Validates the configuration and returns an error if it is not usable.
Sourcepub fn family(&self) -> SubscriptionAddressFamily
pub fn family(&self) -> SubscriptionAddressFamily
Returns the configured address family.
Sourcepub fn source_addr(&self) -> Option<IpAddr>
pub fn source_addr(&self) -> Option<IpAddr>
Returns the configured source address, if any.
Sourcepub fn asm_v6(group: Ipv6Addr) -> Self
pub fn asm_v6(group: Ipv6Addr) -> Self
Creates an IPv6 ASM ((*, G)) raw subscription configuration.
Sourcepub fn asm_ip(group: IpAddr) -> Self
pub fn asm_ip(group: IpAddr) -> Self
Creates an ASM ((*, G)) raw subscription configuration from any IP family.
Examples found in repository?
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}Sourcepub fn ssm(group: Ipv4Addr, source: Ipv4Addr) -> Self
pub fn ssm(group: Ipv4Addr, source: Ipv4Addr) -> Self
Creates an SSM ((S, G)) raw subscription configuration.
Sourcepub fn ssm_v6(group: Ipv6Addr, source: Ipv6Addr) -> Self
pub fn ssm_v6(group: Ipv6Addr, source: Ipv6Addr) -> Self
Creates an IPv6 SSM ((S, G)) raw subscription configuration.
Sourcepub fn ssm_ip(group: IpAddr, source: IpAddr) -> Self
pub fn ssm_ip(group: IpAddr, source: IpAddr) -> Self
Creates an SSM ((S, G)) raw subscription configuration from any IP family.
Examples found in repository?
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 RawSubscriptionConfig
impl Clone for RawSubscriptionConfig
Source§fn clone(&self) -> RawSubscriptionConfig
fn clone(&self) -> RawSubscriptionConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more