use flowscope::driver::{DriverBuilder, SlotHandle};
use flowscope::extract::{FiveTuple, FiveTupleKey};
use crate::protocol::{Dispatch, MessageProtocol, Protocol, ProtocolInitError};
#[derive(Debug, Clone, Copy)]
pub struct Nbns;
impl MessageProtocol for Nbns {}
impl Protocol for Nbns {
type Message = flowscope::netbios_ns::NbnsMessage;
const NAME: &'static str = "netbios-ns";
fn dispatch() -> Dispatch {
Dispatch::Udp(vec![flowscope::netbios_ns::NBNS_PORT])
}
fn register(
builder: &mut DriverBuilder<FiveTuple>,
) -> Result<SlotHandle<Self::Message, FiveTupleKey>, ProtocolInitError> {
let ports = match Self::dispatch() {
Dispatch::Udp(p) => p,
_ => unreachable!("Nbns::dispatch is Dispatch::Udp by construction"),
};
Ok(builder.datagram_on_ports(flowscope::netbios_ns::NbnsParser::new(), ports))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn dispatch_targets_udp_137() {
match Nbns::dispatch() {
Dispatch::Udp(ports) => assert_eq!(ports, vec![137]),
other => panic!("expected Dispatch::Udp, got {other:?}"),
}
}
#[test]
fn name_is_netbios_ns() {
assert_eq!(Nbns::NAME, "netbios-ns");
}
}