use alloc::string::String;
use core::net::Ipv4Addr;
use crate::ast::Protocol;
use crate::reverse::{ProtocolDissection, ipv4_at, push_if, sd};
pub(crate) fn dissect_igmp(b: &[u8]) -> ProtocolDissection {
if b.len() < 8 {
return sd(Protocol::Igmp, String::from("igmp"), b.to_vec());
}
let (mt, mr, grp, mut t) = (b[0], b[1], ipv4_at(b, 4), String::from("igmp"));
let (kw, dg) = match mt {
0x11 => (" query", [224, 0, 0, 1]),
0x12 => (" v1 report", [239, 1, 1, 1]),
0x22 => (" v3 report", [224, 0, 0, 22]),
0x17 => (" leave", [224, 0, 0, 2]),
_ => (" report", [239, 1, 1, 1]),
};
t.push_str(kw);
if mt == 0x11 {
push_if(&mut t, "max_resp", mr, 100);
}
push_if(&mut t, "group", grp, Ipv4Addr::from(dg));
sd(Protocol::Igmp, t, b[8..].to_vec())
}