Skip to content

Commit

Permalink
allow .igmpize() on IGMPv3 packet types
Browse files Browse the repository at this point in the history
  • Loading branch information
Radvendii committed Mar 23, 2020
1 parent 485f2e7 commit 1c9e816
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scapy/contrib/igmp.py
Expand Up @@ -114,6 +114,7 @@ def igmpize(self):
adjusted to ensure correct formatting and assignment. The Ethernet header
is then adjusted to the proper IGMP packet format.
"""
from scapy.contrib.igmpv3 import IGMPv3
gaddr = self.gaddr if hasattr(self, "gaddr") and self.gaddr else "0.0.0.0" # noqa: E501
underlayer = self.underlayer
if self.type not in [0x11, 0x30]: # General Rule 1 # noqa: E501
Expand All @@ -131,6 +132,8 @@ def igmpize(self):
underlayer.dst = "224.0.0.2" # IP rule 2 # noqa: E501
elif ((self.type == 0x12) or (self.type == 0x16)) and (isValidMCAddr(gaddr)): # noqa: E501
underlayer.dst = gaddr # IP rule 3b # noqa: E501
elif (self.type in [0x11, 0x22, 0x30, 0x31, 0x32] and isinstance(self, IGMPv3)):
pass
else:
warning("Invalid IGMP Type detected !")
return False
Expand All @@ -141,7 +144,6 @@ def igmpize(self):
if _root.haslayer(Ether):
# Force recalculate Ether dst
_root[Ether].dst = getmacbyip(underlayer.dst) # Ether rule 1 # noqa: E501
from scapy.contrib.igmpv3 import IGMPv3
if isinstance(self, IGMPv3):
self.encode_maxrespcode()
return True
Expand Down
9 changes: 9 additions & 0 deletions test/contrib/igmpv3.uts
Expand Up @@ -15,6 +15,15 @@ assert x.mrcode == 131
assert x[IP].dst == "224.0.0.1"
assert isinstance(IGMP(raw(x[IGMPv3])), IGMPv3)

= Build IGMPv3 - igmpize

a=Ether(src="00:01:02:03:04:05")
b=IP(src="1.2.3.4")
c=IGMPv3()/IGMPv3mr(records = [IGMPv3gr(maddr = "232.1.1.10", srcaddrs = ["10.0.0.10"])])
x = a/b/c
ret = x[IGMPv3].igmpize()
assert ret

= Dissect IGMPv3 - IGMPv3mq

x = Ether(b'\x14\x0cv\x8f\xfe(\x00\x01\x02\x03\x04\x05\x08\x00F\xc0\x00$\x00\x01\x00\x00\x01\x02\xe4h\xc0\xa8\x00\x01\xe0\x00\x00\x16\x94\x04\x00\x00\x11\x14\x0e\xe9\xe6\x00\x00\x02\x00\x00\x00\x00')
Expand Down

0 comments on commit 1c9e816

Please sign in to comment.