@@ -2,6 +2,8 @@ pub mod igmpv1;
22pub mod igmpv2;
33pub mod igmpv3;
44
5+ use std:: fmt:: Display ;
6+
57use crate :: packet:: network:: igmp:: igmpv1:: IGMPv1Packet ;
68
79#[ derive( Debug , Copy , Clone ) ]
@@ -11,7 +13,7 @@ pub enum IgmpPacket {
1113 // V3(IGMPv3),
1214}
1315
14- #[ derive( Debug , Copy , Clone ) ]
16+ #[ derive( Debug , Copy , Clone , PartialEq ) ]
1517pub enum IgmpType {
1618 MembershipQuery = 0x11 ,
1719 IGMPv1MembershipReport = 0x12 ,
@@ -20,19 +22,6 @@ pub enum IgmpType {
2022 LeaveGroup = 0x17 ,
2123}
2224
23- // impl From<u8> for IgmpType {
24- // fn from(value: u8) -> Self {
25- // match value {
26- // 0x11 => IgmpType::MembershipQuery,
27- // 0x12 => IgmpType::IGMPv1MembershipReport,
28- // 0x16 => IgmpType::IGMPv2MembershipReport,
29- // 0x22 => IgmpType::IGMPv3MembershipReport,
30- // 0x17 => IgmpType::LeaveGroup,
31- // _ => unreachable!(),
32- // }
33- // }
34- // }
35-
3625impl TryFrom < u8 > for IgmpType {
3726 type Error = & ' static str ;
3827 fn try_from ( value : u8 ) -> Result < Self , Self :: Error > {
@@ -46,3 +35,25 @@ impl TryFrom<u8> for IgmpType {
4635 }
4736 }
4837}
38+
39+ impl Display for IgmpType {
40+ fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
41+ match self {
42+ IgmpType :: MembershipQuery => {
43+ write ! ( f, "Membership Query" )
44+ }
45+ IgmpType :: IGMPv1MembershipReport => {
46+ write ! ( f, "IGMPv1 Membership Report" )
47+ }
48+ IgmpType :: IGMPv2MembershipReport => {
49+ write ! ( f, "IGMPv2 Membership Report" )
50+ }
51+ IgmpType :: IGMPv3MembershipReport => {
52+ write ! ( f, "IGMPv3 Membership Report" )
53+ }
54+ IgmpType :: LeaveGroup => {
55+ write ! ( f, "Leave Group" )
56+ }
57+ }
58+ }
59+ }
0 commit comments