1use core::mem;
2
3use crate::{getter_be, setter_be};
4
5#[repr(C)]
6#[derive(Debug, Copy, Clone)]
7#[cfg_attr(feature = "wincode", derive(wincode::SchemaRead, wincode::SchemaWrite))]
8#[cfg_attr(feature = "wincode", wincode(assert_zero_copy))]
9pub struct IGMPv1Hdr {
10 pub vt: u8,
12
13 pub _unused: u8,
15
16 pub checksum: [u8; 2],
18
19 pub group_address: [u8; 4],
21}
22
23impl IGMPv1Hdr {
24 pub const LEN: usize = mem::size_of::<IGMPv1Hdr>();
26
27 #[inline]
28 pub fn version(&self) -> u8 {
29 (self.vt >> 4) & 0xF
30 }
31
32 #[inline]
33 pub fn type_(&self) -> u8 {
34 self.vt & 0xF
35 }
36
37 #[inline]
38 pub fn checksum(&self) -> u16 {
39 unsafe { getter_be!(self, checksum, u16) }
41 }
42
43 #[inline]
44 pub fn set_checksum(&mut self, checksum: u16) {
45 unsafe { setter_be!(self, checksum, checksum) }
47 }
48
49 #[inline]
50 pub fn group_address(&self) -> u32 {
51 unsafe { getter_be!(self, group_address, u32) }
53 }
54
55 #[inline]
56 pub fn set_group_address(&mut self, group_address: u32) {
57 unsafe { setter_be!(self, group_address, group_address) }
59 }
60}
61
62#[repr(C)]
63#[derive(Debug, Copy, Clone)]
64#[cfg_attr(feature = "wincode", derive(wincode::SchemaRead, wincode::SchemaWrite))]
65#[cfg_attr(feature = "wincode", wincode(assert_zero_copy))]
66pub struct IGMPv2Hdr {
67 pub message_type: u8,
69
70 pub max_response_time: u8,
72
73 pub checksum: [u8; 2],
75
76 pub group_address: [u8; 4],
78}
79
80impl IGMPv2Hdr {
81 pub const LEN: usize = mem::size_of::<IGMPv2Hdr>();
83
84 #[inline]
85 pub fn checksum(&self) -> u16 {
86 unsafe { getter_be!(self, checksum, u16) }
88 }
89
90 #[inline]
91 pub fn set_checksum(&mut self, checksum: u16) {
92 unsafe { setter_be!(self, checksum, checksum) }
94 }
95
96 #[inline]
97 pub fn group_address(&self) -> u32 {
98 unsafe { getter_be!(self, group_address, u32) }
100 }
101
102 #[inline]
103 pub fn set_group_address(&mut self, group_address: u32) {
104 unsafe { setter_be!(self, group_address, group_address) }
106 }
107}
108
109#[repr(C)]
110#[derive(Debug, Copy, Clone)]
111#[cfg_attr(feature = "wincode", derive(wincode::SchemaRead, wincode::SchemaWrite))]
112#[cfg_attr(feature = "wincode", wincode(assert_zero_copy))]
113pub struct IGMPv3MembershipQueryHdr {
114 pub message_type: u8,
116
117 pub max_response_time: u8,
119
120 pub checksum: [u8; 2],
122
123 pub group_address: [u8; 4],
125
126 pub rsq: u8,
127
128 pub qqic: u8,
130
131 pub nb_sources: [u8; 2],
133}
134
135impl IGMPv3MembershipQueryHdr {
136 pub const LEN: usize = mem::size_of::<IGMPv3MembershipQueryHdr>();
137
138 #[inline]
139 pub fn checksum(&self) -> u16 {
140 unsafe { getter_be!(self, checksum, u16) }
142 }
143
144 #[inline]
145 pub fn set_checksum(&mut self, checksum: u16) {
146 unsafe { setter_be!(self, checksum, checksum) }
148 }
149
150 #[inline]
151 pub fn group_address(&self) -> u32 {
152 unsafe { getter_be!(self, group_address, u32) }
154 }
155
156 #[inline]
157 pub fn set_group_address(&mut self, group_address: u32) {
158 unsafe { setter_be!(self, group_address, group_address) }
160 }
161
162 #[inline]
163 pub fn s(&self) -> u8 {
164 (self.rsq >> 3) & 1
165 }
166
167 #[inline]
168 pub fn qrv(&self) -> u8 {
169 self.rsq & 0b111
170 }
171
172 #[inline]
173 pub fn nb_sources(&self) -> u32 {
174 unsafe { getter_be!(self, nb_sources, u32) }
176 }
177
178 #[inline]
179 pub fn set_nb_sources(&mut self, nb_sources: u32) {
180 unsafe { setter_be!(self, nb_sources, nb_sources) }
182 }
183}
184
185#[repr(C)]
186#[derive(Debug, Copy, Clone)]
187#[cfg_attr(feature = "wincode", derive(wincode::SchemaRead, wincode::SchemaWrite))]
188#[cfg_attr(feature = "wincode", wincode(assert_zero_copy))]
189pub struct IGMPv3MembershipReportHdr {
190 pub message_type: u8,
192
193 _unused_1: u8,
194
195 pub checksum: [u8; 2],
197
198 _unused_2: [u8; 2],
199
200 pub nb_group_records: [u8; 2],
202}
203
204impl IGMPv3MembershipReportHdr {
205 pub const LEN: usize = mem::size_of::<IGMPv3MembershipReportHdr>();
206
207 #[inline]
208 pub fn checksum(&self) -> u16 {
209 unsafe { getter_be!(self, checksum, u16) }
211 }
212
213 #[inline]
214 pub fn set_checksum(&mut self, checksum: u16) {
215 unsafe { setter_be!(self, checksum, checksum) }
217 }
218
219 #[inline]
220 pub fn nb_group_records(&self) -> u16 {
221 unsafe { getter_be!(self, nb_group_records, u16) }
223 }
224
225 #[inline]
226 pub fn set_nb_group_records(&mut self, nb_group_records: u16) {
227 unsafe { setter_be!(self, nb_group_records, nb_group_records) }
229 }
230}