mirror of https://github.com/secdev/scapy.git
Merge pull request #886 from gpotter2/py3-contrib-10
Python 3: fix IGMP(v1/3)
This commit is contained in:
commit
1b3b2fb662
|
@ -23,6 +23,7 @@ from scapy.fields import *
|
|||
from scapy.layers.inet import *
|
||||
from scapy.layers.l2 import DestMACField, getmacbyip
|
||||
from scapy.error import warning
|
||||
from scapy.compat import chb, orb
|
||||
|
||||
def isValidMCAddr(ip):
|
||||
"""convert dotted quad string to long and check the first octet"""
|
||||
|
@ -73,15 +74,15 @@ IGMPv2 message format http://www.faqs.org/rfcs/rfc2236.html
|
|||
p += pay
|
||||
if self.chksum is None:
|
||||
ck = checksum(p)
|
||||
p = p[:2]+chr(ck>>8)+chr(ck&0xff)+p[4:]
|
||||
p = p[:2]+chb(ck>>8)+chb(ck&0xff)+p[4:]
|
||||
return p
|
||||
|
||||
@classmethod
|
||||
def dispatch_hook(cls, _pkt=None, *args, **kargs):
|
||||
if _pkt and len(_pkt) >= 4:
|
||||
if ord(_pkt[0]) in [0x22, 0x30, 0x31, 0x32]:
|
||||
if orb(_pkt[0]) in [0x22, 0x30, 0x31, 0x32]:
|
||||
return IGMPv3
|
||||
if ord(_pkt[0]) == 0x11 and len(_pkt) >= 12:
|
||||
if orb(_pkt[0]) == 0x11 and len(_pkt) >= 12:
|
||||
return IGMPv3
|
||||
return IGMP
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ assert x[IP].dst == "224.0.0.1"
|
|||
x = Ether(src="00:01:02:03:04:05")/IP()/IGMP(gaddr="224.2.3.4", type=0x12)
|
||||
x.mrcode = 1
|
||||
x[IGMP].igmpize()
|
||||
x = Ether(str(x))
|
||||
x = Ether(raw(x))
|
||||
assert x.mrcode == 0
|
||||
|
||||
x.gaddr = "224.3.2.4"
|
||||
|
@ -64,7 +64,7 @@ assert IGMP().mysummary() == "IGMP Group Membership Query 0.0.0.0"
|
|||
~ netaccess
|
||||
|
||||
x = Ether(src="00:01:02:03:04:05")/IP(dst="192.168.0.1")/IGMP(gaddr="www.google.fr", type=0x11)
|
||||
x = Ether(str(x))
|
||||
x = Ether(raw(x))
|
||||
assert not x[IGMP].igmpize()
|
||||
assert x[IP].dst == "192.168.0.1"
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ x = a/b/c
|
|||
x[IGMPv3].igmpize()
|
||||
assert x.mrcode == 20
|
||||
assert x[IP].dst == "224.0.0.1"
|
||||
assert isinstance(IGMP(str(x[IGMPv3])), IGMPv3)
|
||||
assert isinstance(IGMP(raw(x[IGMPv3])), IGMPv3)
|
||||
|
||||
= Dissect IGMPv3 - IGMPv3mq
|
||||
|
||||
|
@ -22,7 +22,7 @@ assert IGMPv3 in x
|
|||
assert IGMPv3mq in x
|
||||
assert x[IGMPv3mq].gaddr == "224.0.0.2"
|
||||
assert x.summary() == "Ether / IP / IGMPv3: 192.168.0.1 > 127.0.0.1 Membership Query / IGMPv3mq"
|
||||
assert isinstance(IGMP(str(x[IGMPv3])), IGMPv3)
|
||||
assert isinstance(IGMP(raw(x[IGMPv3])), IGMPv3)
|
||||
|
||||
= Dissect IGMPv3 - IGMPv3mr
|
||||
|
||||
|
@ -32,7 +32,7 @@ assert IGMPv3mr in x
|
|||
assert len(x[IGMPv3mr].records) == 2
|
||||
assert x[IGMPv3mr].records[0].srcaddrs == ["192.168.0.1", "192.168.132.247"]
|
||||
assert x[IGMPv3mr].records[1].maddr == "4.4.4.4"
|
||||
assert isinstance(IGMP(str(x[IGMPv3])), IGMPv3)
|
||||
assert isinstance(IGMP(raw(x[IGMPv3])), IGMPv3)
|
||||
|
||||
= Dissect IGMPv3 - IGMPv3mra
|
||||
|
||||
|
@ -41,6 +41,6 @@ assert IGMPv3 in x
|
|||
assert IGMPv3mra in x
|
||||
assert x[IGMPv3mra].qryIntvl == 3
|
||||
assert x[IGMPv3mra].robust == 2
|
||||
assert isinstance(IGMP(str(x[IGMPv3])), IGMPv3)
|
||||
assert isinstance(IGMP(raw(x[IGMPv3])), IGMPv3)
|
||||
|
||||
= IGMP vs IVMPv3 tests
|
||||
|
|
Loading…
Reference in New Issue