From 0d92fc9fbb58df9cc4bbeb007bf65020fe1aa092 Mon Sep 17 00:00:00 2001 From: Victor Pfautz <v.pfautz@gmx.net> Date: Wed, 1 Mar 2017 13:08:36 +0100 Subject: [PATCH] Fixed spacing bug (#532) Fixed some typos and bad whitespaces. --- doc/scapy/introduction.rst | 2 +- scapy/arch/unix.py | 24 +- scapy/arch/windows/compatibility.py | 2 +- scapy/arch/winpcapy.py | 6 +- scapy/contrib/avs.py | 1 - scapy/contrib/cdp.py | 2 +- scapy/contrib/dtp.py | 2 +- scapy/contrib/eigrp.py | 2 +- scapy/contrib/gsm_um.py | 10 +- scapy/contrib/ikev2.py | 52 ++-- scapy/fields.py | 60 ++-- scapy/layers/dhcp6.py | 4 +- scapy/layers/dns.py | 168 +++++------ scapy/layers/inet6.py | 450 ++++++++++++++-------------- scapy/layers/ntp.py | 2 +- scapy/layers/snmp.py | 2 +- scapy/layers/tls/tools.py | 2 +- scapy/packet.py | 2 +- scapy/route6.py | 48 +-- scapy/sendrecv.py | 4 +- test/dnssecRR.uts | 2 +- test/edns0.uts | 2 +- 22 files changed, 424 insertions(+), 425 deletions(-) diff --git a/doc/scapy/introduction.rst b/doc/scapy/introduction.rst index 114c01a2..1f8c00e5 100644 --- a/doc/scapy/introduction.rst +++ b/doc/scapy/introduction.rst @@ -165,7 +165,7 @@ Sensible default values ----------------------- Scapy tries to use sensible default values for all packet fields. -If not overriden, +If not overridden, * IP source is chosen according to destination and routing table * Checksum is computed diff --git a/scapy/arch/unix.py b/scapy/arch/unix.py index c55e4413..725d17d0 100644 --- a/scapy/arch/unix.py +++ b/scapy/arch/unix.py @@ -80,7 +80,7 @@ def read_routes(): dest,gw,flg = rt[:3] netif = rt[4 + mtu_present + prio_present + refs_present] if flg.find("Lc") >= 0: - continue + continue if dest == "default": dest = 0L netmask = 0L @@ -133,7 +133,7 @@ def read_routes(): routes.append((dest,netmask,gw,gw_if,gw_if_addr)) else: warning("Did not find output interface to reach gateway %s" % gw) - + return routes ############ @@ -174,7 +174,7 @@ def _in6_getifaddr(ifname): return ret -def in6_getifaddr(): +def in6_getifaddr(): """ Returns a list of 3-tuples of the form (addr, scope, iface) where 'addr' is the address of scope 'scope' associated to the interface @@ -189,8 +189,8 @@ def in6_getifaddr(): try: f = os.popen("%s" % conf.prog.ifconfig) except OSError,msg: - log_interactive.warning("Failed to execute ifconfig.") - return [] + log_interactive.warning("Failed to execute ifconfig.") + return [] # Get the list of network interfaces splitted_line = [] @@ -201,18 +201,18 @@ def in6_getifaddr(): else: # FreeBSD, NetBSD or Darwin try: - f = os.popen("%s -l" % conf.prog.ifconfig) + f = os.popen("%s -l" % conf.prog.ifconfig) except OSError,msg: - log_interactive.warning("Failed to execute ifconfig.") - return [] + log_interactive.warning("Failed to execute ifconfig.") + return [] # Get the list of network interfaces splitted_line = f.readline().rstrip().split() ret = [] for i in splitted_line: - ret += _in6_getifaddr(i) - return ret + ret += _in6_getifaddr(i) + return ret def read_routes6(): @@ -221,7 +221,7 @@ def read_routes6(): # Call netstat to retrieve IPv6 routes fd_netstat = os.popen("netstat -rn -f inet6") - # List interfaces IPv6 addresses + # List interfaces IPv6 addresses lifaddr = in6_getifaddr() if not lifaddr: return [] @@ -253,7 +253,7 @@ def read_routes6(): destination, next_hop, flags = splitted_line[:3] dev = splitted_line[index] else: - # FREEBSD or DARWIN + # FREEBSD or DARWIN if len(splitted_line) < 4: warning("Not enough columns in route entry !") continue diff --git a/scapy/arch/windows/compatibility.py b/scapy/arch/windows/compatibility.py index 7d0a20d5..0f717c5c 100644 --- a/scapy/arch/windows/compatibility.py +++ b/scapy/arch/windows/compatibility.py @@ -176,7 +176,7 @@ def sniff(count=0, store=1, offline=None, prn = None, stop_filter=None, lfilter= sniff([count=0,] [prn=None,] [store=1,] [offline=None,] [lfilter=None,] + L2ListenSocket args) -> list of packets Select interface to sniff by setting conf.iface. Use show_interfaces() to see interface names. count: number of packets to capture. 0 means infinity - store: wether to store sniffed packets or discard them + store: whether to store sniffed packets or discard them prn: function to apply to each packet. If something is returned, it is displayed. Ex: ex: prn = lambda x: x.summary() diff --git a/scapy/arch/winpcapy.py b/scapy/arch/winpcapy.py index 6decea39..c1b7af52 100755 --- a/scapy/arch/winpcapy.py +++ b/scapy/arch/winpcapy.py @@ -68,7 +68,7 @@ timeval._fields_ = [('tv_sec', c_long), ('tv_usec', c_long)] ## sockaddr is used by pcap_addr. -## For exapmle if sa_family==socket.AF_INET then we need cast +## For example if sa_family==socket.AF_INET then we need cast ## with sockaddr_in if WIN32: class sockaddr(Structure): @@ -543,7 +543,7 @@ if WIN32: # Defines if the adapter has to go in promiscuous mode. PCAP_OPENFLAG_PROMISCUOUS=1 # define PCAP_OPENFLAG_DATATX_UDP 2 - # Defines if the data trasfer (in case of a remote capture) has to be done with UDP protocol. + # Defines if the data transfer (in case of a remote capture) has to be done with UDP protocol. PCAP_OPENFLAG_DATATX_UDP=2 # define PCAP_OPENFLAG_NOCAPTURE_RPCAP 4 PCAP_OPENFLAG_NOCAPTURE_RPCAP=4 @@ -585,7 +585,7 @@ if WIN32: # Defines the maximum buffer size in which address, port, interface names are kept. PCAP_BUF_SIZE = 1024 # define RPCAP_HOSTLIST_SIZE 1024 - # Maximum lenght of an host name (needed for the RPCAP active mode). + # Maximum length of an host name (needed for the RPCAP active mode). RPCAP_HOSTLIST_SIZE = 1024 class pcap_send_queue(Structure): diff --git a/scapy/contrib/avs.py b/scapy/contrib/avs.py index 461b94b8..b31d58ec 100644 --- a/scapy/contrib/avs.py +++ b/scapy/contrib/avs.py @@ -54,4 +54,3 @@ class AVSWLANHeader(Packet): ] bind_layers(AVSWLANHeader, Dot11) - diff --git a/scapy/contrib/cdp.py b/scapy/contrib/cdp.py index f2cdafcd..6730ea75 100644 --- a/scapy/contrib/cdp.py +++ b/scapy/contrib/cdp.py @@ -67,7 +67,7 @@ _cdp_tlv_types = { 0x0001: "Device ID", 0x0006: "Platform", 0x0007: "IP Prefix", 0x0008: "Protocol Hello", - 0x0009: "VTP Mangement Domain", # CDPv2 + 0x0009: "VTP Management Domain", # CDPv2 0x000a: "Native VLAN", # CDPv2 0x000b: "Duplex", # 0x000c: "CDP Unknown command (send us a pcap file)", diff --git a/scapy/contrib/dtp.py b/scapy/contrib/dtp.py index 294350bc..d367d5a9 100644 --- a/scapy/contrib/dtp.py +++ b/scapy/contrib/dtp.py @@ -94,7 +94,7 @@ def _DTPGuessPayloadClass(p, **kargs): t = struct.unpack("!H", p[:2])[0] clsname = _DTP_TLV_CLS.get(t, "DtpGenericTlv") cls = globals()[clsname] - return cls(p, **kargs) + return cls(p, **kargs) class DTP(Packet): name = "DTP" diff --git a/scapy/contrib/eigrp.py b/scapy/contrib/eigrp.py index fed3e213..a92782d5 100644 --- a/scapy/contrib/eigrp.py +++ b/scapy/contrib/eigrp.py @@ -439,7 +439,7 @@ def _EIGRPGuessPayloadClass(p, **kargs): t = struct.unpack("!H", p[:2])[0] clsname = _eigrp_tlv_cls.get(t, "EIGRPGeneric") cls = globals()[clsname] - return cls(p, **kargs) + return cls(p, **kargs) _EIGRP_OPCODES = { 1 : "Update", 2 : "Request", diff --git a/scapy/contrib/gsm_um.py b/scapy/contrib/gsm_um.py index c1f919e0..4d1bd330 100644 --- a/scapy/contrib/gsm_um.py +++ b/scapy/contrib/gsm_um.py @@ -4032,7 +4032,7 @@ class IraRestOctetsHdr(Packet): ] -# len is 1 to 5 what do we do with the variable size? no lenght +# len is 1 to 5 what do we do with the variable size? no length # field?! WTF class IaxRestOctetsHdr(Packet): """IAX Rest Octets Section 10.5.2.18""" @@ -4509,7 +4509,7 @@ class PageModeAndChannelNeeded(Packet): class NccPermittedHdr(Packet): """NCC Permitted Section 10.5.2.27""" - name = "NCC Permited" + name = "NCC Permitted" fields_desc = [ BitField("eightBitNP", None, 1), XBitField("ieiNP", None, 7), @@ -7899,7 +7899,7 @@ class PTmsiSignature(Packet): name = "P-TMSI Signature" fields_desc = [ ByteField("ieiPTS", 0x0), - BitField("sgnature", 0x0, 24) + BitField("signature", 0x0, 24) ] @@ -9740,7 +9740,7 @@ class IraRestOctets(Packet): ] -# len is 1 to 5 what do we do with the variable size? no lenght +# len is 1 to 5 what do we do with the variable size? no length # field?! WTF class IaxRestOctets(Packet): """IAX Rest Octets Section 10.5.2.18""" @@ -10032,7 +10032,7 @@ class PageMode(Packet): class NccPermitted(Packet): """NCC Permitted Section 10.5.2.27""" - name = "NCC Permited" + name = "NCC Permitted" fields_desc = [ ByteField("nccPerm", 0x0) ] diff --git a/scapy/contrib/ikev2.py b/scapy/contrib/ikev2.py index ed58194f..34d21da7 100644 --- a/scapy/contrib/ikev2.py +++ b/scapy/contrib/ikev2.py @@ -23,9 +23,9 @@ IKEv2AttributeTypes= { "Encryption": (1, { "DES-IV64" : 1, "DES" : 2, "3DES" : 3, "RC5" : 4, - "IDEA" : 5, - "CAST" : 6, - "Blowfish" : 7, + "IDEA" : 5, + "CAST" : 6, + "Blowfish" : 7, "3IDEA" : 8, "DES-IV32" : 9, "AES-CBC" : 12, @@ -67,13 +67,13 @@ IKEv2AttributeTypes= { "Encryption": (1, { "DES-IV64" : 1, "SHA2-512-256": 14, }, 0), "GroupDesc": (4, { "768MODPgr" : 1, - "1024MODPgr" : 2, - "1536MODPgr" : 5, - "2048MODPgr" : 14, - "3072MODPgr" : 15, - "4096MODPgr" : 16, - "6144MODPgr" : 17, - "8192MODPgr" : 18, + "1024MODPgr" : 2, + "1536MODPgr" : 5, + "2048MODPgr" : 14, + "3072MODPgr" : 15, + "4096MODPgr" : 16, + "6144MODPgr" : 17, + "8192MODPgr" : 18, "256randECPgr" : 19, "384randECPgr" : 20, "521randECPgr" : 21, @@ -177,8 +177,8 @@ IKEv2CertificateEncodings = { 13 : "Hash and URL of X.509 bundle" } -# the name 'IKEv2TransformTypes' is actually a misnomer (since the table -# holds info for all IKEv2 Attribute types, not just transforms, but we'll +# the name 'IKEv2TransformTypes' is actually a misnomer (since the table +# holds info for all IKEv2 Attribute types, not just transforms, but we'll # keep it for backwards compatibility... for now at least IKEv2TransformTypes = IKEv2AttributeTypes @@ -192,7 +192,7 @@ for n in IKEv2TransformTypes: IKEv2Transforms = {} for n in IKEv2TransformTypes: - IKEv2Transforms[IKEv2TransformTypes[n][0]]=n + IKEv2Transforms[IKEv2TransformTypes[n][0]]=n del(n) del(e) @@ -200,7 +200,7 @@ del(tmp) del(val) # Note: Transform and Proposal can only be used inside the SA payload -IKEv2_payload_type = ["None", "", "Proposal", "Transform"] +IKEv2_payload_type = ["None", "", "Proposal", "Transform"] IKEv2_payload_type.extend([""] * 29) IKEv2_payload_type.extend(["SA","KE","IDi","IDr", "CERT","CERTREQ","AUTH","Nonce","Notify","Delete", @@ -253,19 +253,19 @@ class IKEv2(IKEv2_class): # rfc4306 if self.length is None: p = p[:24]+struct.pack("!I",len(p))+p[28:] return p - + class IKEv2_Key_Length_Attribute(IntField): - # We only support the fixed-length Key Length attribute (the only one currently defined) - def __init__(self, name): - IntField.__init__(self, name, 0x800E0000) - - def i2h(self, pkt, x): - return IntField.i2h(self, pkt, x & 0xFFFF) - - def h2i(self, pkt, x): - return IntField.h2i(self, pkt, x if x !=None else 0 | 0x800E0000) - + # We only support the fixed-length Key Length attribute (the only one currently defined) + def __init__(self, name): + IntField.__init__(self, name, 0x800E0000) + + def i2h(self, pkt, x): + return IntField.i2h(self, pkt, x & 0xFFFF) + + def h2i(self, pkt, x): + return IntField.h2i(self, pkt, x if x !=None else 0 | 0x800E0000) + class IKEv2_payload_Transform(IKEv2_class): name = "IKE Transform" fields_desc = [ @@ -277,7 +277,7 @@ class IKEv2_payload_Transform(IKEv2_class): MultiEnumField("transform_id",None,IKEv2TransformNum,depends_on=lambda pkt:pkt.transform_type,fmt="H"), ConditionalField(IKEv2_Key_Length_Attribute("key_length"), lambda pkt: pkt.length > 8), ] - + class IKEv2_payload_Proposal(IKEv2_class): name = "IKEv2 Proposal" fields_desc = [ diff --git a/scapy/fields.py b/scapy/fields.py index 7f49f2cc..a4b45c67 100644 --- a/scapy/fields.py +++ b/scapy/fields.py @@ -101,7 +101,7 @@ class Field(object): return RandBin(l) else: warning("no random class for [%s] (fmt=%s)." % (self.name, self.fmt)) - + @@ -115,7 +115,7 @@ class Emph(object): return hash(self.fld) def __eq__(self, other): return self.fld == other - + class ActionField(object): __slots__ = ["_fld", "_action_method", "_privdata"] @@ -173,10 +173,10 @@ class PadField(object): def addfield(self, pkt, s, val): sval = self._fld.addfield(pkt, "", val) return s+sval+struct.pack("%is" % (self.padlen(len(sval))), self._padwith) - + def __getattr__(self, attr): return getattr(self._fld,attr) - + class DestField(Field): __slots__ = ["defaultdst"] @@ -231,7 +231,7 @@ class IPField(Field): except socket.error: x = Net(x) elif type(x) is list: - x = [self.h2i(pkt, n) for n in x] + x = [self.h2i(pkt, n) for n in x] return x def resolve(self, x): if self in conf.resolve: @@ -280,13 +280,13 @@ class SourceIPField(IPField): x = self.__findaddr(pkt) return IPField.i2h(self, pkt, x) - + class ByteField(Field): def __init__(self, name, default): Field.__init__(self, name, default, "B") - + class XByteField(ByteField): def i2repr(self, pkt, x): return lhex(self.i2h(pkt, x)) @@ -374,7 +374,7 @@ class StrField(Field): __slots__ = ["remain"] def __init__(self, name, default, fmt="H", remain=0): Field.__init__(self,name,default,fmt) - self.remain = remain + self.remain = remain def i2len(self, pkt, i): return len(i) def i2m(self, pkt, x): @@ -411,7 +411,7 @@ class PacketField(StrField): del(r.underlayer.payload) remain = r.load return remain,i - + class PacketLenField(PacketField): __slots__ = ["length_from"] def __init__(self, name, default, cls, length_from=None): @@ -461,7 +461,7 @@ class PacketListField(PacketField): l = self.length_from(pkt) elif self.count_from is not None: c = self.count_from(pkt) - + lst = [] ret = "" remain = s @@ -554,7 +554,7 @@ class StrLenField(StrField): def getfield(self, pkt, s): l = self.length_from(pkt) return s[l:], self.m2i(pkt,s[:l]) - + class XStrField(StrField): """ StrField which value is printed as hexadecimal. @@ -591,7 +591,7 @@ class BoundStrLenField(StrLenField): StrLenField.__init__(self, name, default, fld, length_from) self.minlen = minlen self.maxlen = maxlen - + def randval(self): return RandBin(RandNum(self.minlen, self.maxlen)) @@ -605,14 +605,14 @@ class FieldListField(Field): Field.__init__(self, name, default) self.count_from = count_from self.length_from = length_from - + def i2count(self, pkt, val): if type(val) is list: return len(val) return 1 def i2len(self, pkt, val): return sum( self.field.i2len(pkt,v) for v in val ) - + def i2m(self, pkt, val): if val is None: val = [] @@ -644,7 +644,7 @@ class FieldListField(Field): ret="" if l is not None: s,ret = s[:l],s[l:] - + while s: if c is not None: if c <= 0: @@ -719,7 +719,7 @@ class BitField(Field): __slots__ = ["rev", "size"] def __init__(self, name, default, size): Field.__init__(self, name, default) - self.rev = size < 0 + self.rev = size < 0 self.size = abs(size) def reverse(self, val): if self.size == 16: @@ -727,7 +727,7 @@ class BitField(Field): elif self.size == 32: val = socket.ntohl(val) return val - + def addfield(self, pkt, s, val): val = self.i2m(pkt, val) if type(s) is tuple: @@ -815,8 +815,8 @@ class _EnumField(Field): and the second callable does the converse. The first callable may return None to default to a literal string (repr()) representation. - @param fmt: struct.pack format used to parse and serialize the - internal value from and to machine representation. + @param fmt: struct.pack format used to parse and serialize the + internal value from and to machine representation. """ if isinstance(enum, tuple): self.i2s_cb = enum[0] @@ -858,7 +858,7 @@ class _EnumField(Field): if ret is not None: return ret return repr(x) - + def any2i(self, pkt, x): if type(x) is list: return map(lambda z,pkt=pkt:self.any2i_one(pkt,z), x) @@ -943,7 +943,7 @@ class XShortEnumField(ShortEnumField): class _MultiEnumField(_EnumField): def __init__(self, name, default, enum, depends_on, fmt = "H"): - + self.depends_on = depends_on self.i2s_multi = enum self.s2i_multi = {} @@ -1258,11 +1258,11 @@ class _IPPrefixFieldBase(Field): self.ntoa = ntoa Field.__init__(self, name, default, "%is" % self.maxbytes) self.length_from = length_from - + def _numbytes(self, pfxlen): wbits= self.wordbytes * 8 return ((pfxlen + (wbits - 1)) / wbits) * self.wordbytes - + def h2i(self, pkt, x): # "fc00:1::1/64" -> ("fc00:1::1", 64) [pfx,pfxlen]= x.split('/') @@ -1280,30 +1280,30 @@ class _IPPrefixFieldBase(Field): (pfx,pfxlen)= x s= self.aton(pfx); return (s[:self._numbytes(pfxlen)], pfxlen) - + def m2i(self, pkt, x): # ("\xfc\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", 64) -> ("fc00:1::1", 64) (s,pfxlen)= x - + if len(s) < self.maxbytes: s= s + ("\0" * (self.maxbytes - len(s))) return (self.ntoa(s), pfxlen) - + def any2i(self, pkt, x): if x is None: return (self.ntoa("\0"*self.maxbytes), 1) - + return self.h2i(pkt,x) - + def i2len(self, pkt, x): (_,pfxlen)= x return pfxlen - + def addfield(self, pkt, s, val): (rawpfx,pfxlen)= self.i2m(pkt,val) fmt= "!%is" % self._numbytes(pfxlen) return s+struct.pack(fmt, rawpfx) - + def getfield(self, pkt, s): pfxlen= self.length_from(pkt) numbytes= self._numbytes(pfxlen) diff --git a/scapy/layers/dhcp6.py b/scapy/layers/dhcp6.py index 19715c06..65c30203 100644 --- a/scapy/layers/dhcp6.py +++ b/scapy/layers/dhcp6.py @@ -638,7 +638,7 @@ class DHCP6OptIfaceId(_DHCP6OptGuessPayload):# RFC sect 22.18 # A server includes a Reconfigure Message option in a Reconfigure # message to indicate to the client whether the client responds with a -# renew message or an Informatiion-request message. +# renew message or an Information-request message. class DHCP6OptReconfMsg(_DHCP6OptGuessPayload): # RFC sect 22.19 name = "DHCP6 Reconfigure Message Option" fields_desc = [ ShortEnumField("optcode", 19, dhcp6opts), @@ -1118,7 +1118,7 @@ class DHCP6_RelayForward(_DHCP6OptGuessPayload,Packet): # Normalement, doit inclure une option "Relay Message Option" # peut en inclure d'autres. # Les valeurs des champs hop-count, link-addr et peer-addr -# sont copiees du messsage Forward associe. POur le suivi de session. +# sont copiees du message Forward associe. POur le suivi de session. # Pour le moment, comme decrit dans le commentaire, le hashret # se limite au contenu du champ peer address. # Voir section 7.2 de la 3315. diff --git a/scapy/layers/dns.py b/scapy/layers/dns.py index ccbefcce..d29da49b 100644 --- a/scapy/layers/dns.py +++ b/scapy/layers/dns.py @@ -67,7 +67,7 @@ class DNSRRCountField(ShortField): x = x.payload i += 1 return i - + def i2m(self, pkt, x): if x is None: x = self._countRR(pkt) @@ -76,7 +76,7 @@ class DNSRRCountField(ShortField): if x is None: x = self._countRR(pkt) return x - + def DNSgetstr(s,p): name = "" @@ -108,7 +108,7 @@ def DNSgetstr(s,p): if q: p = q return name,p - + class DNSRRField(StrField): __slots__ = ["countfld", "passon"] @@ -131,11 +131,11 @@ class DNSRRField(StrField): del(rr.rdlen) elif type in DNSRR_DISPATCHER: rr = DNSRR_DISPATCHER[type]("\x00"+ret+s[p:p+rdlen]) - else: + else: del(rr.rdlen) - + p += rdlen - + rr.rrname = name return rr,p def getfield(self, pkt, s): @@ -160,8 +160,8 @@ class DNSRRField(StrField): return (s,p),ret else: return s[p:],ret - - + + class DNSQRField(DNSRRField): def decodeRR(self, name, s, p): ret = s[p:p+4] @@ -169,8 +169,8 @@ class DNSQRField(DNSRRField): rr = DNSQR("\x00"+ret) rr.qname = name return rr,p - - + + class RDataField(StrLenField): def m2i(self, pkt, s): @@ -193,7 +193,7 @@ class RDataField(StrLenField): s = ret_s elif pkt.type == 28: # AAAA family = socket.AF_INET6 - if family is not None: + if family is not None: s = inet_ntop(family, s) return s def i2m(self, pkt, s): @@ -212,7 +212,7 @@ class RDataField(StrLenField): while len(s) >= 255: ret_s += "\xff" + s[:255] s = s[255:] - # The remaining string is less than 255 bytes long + # The remaining string is less than 255 bytes long if len(s): ret_s += struct.pack("!B", len(s)) + s s = ret_s @@ -318,8 +318,8 @@ class DNSQR(Packet): fields_desc = [DNSStrField("qname", "www.example.com"), ShortEnumField("qtype", 1, dnsqtypes), ShortEnumField("qclass", 1, dnsclasses)] - - + + # RFC 2671 - Extension Mechanisms for DNS (EDNS0) @@ -330,7 +330,7 @@ class EDNS0TLV(Packet): StrLenField("optdata", "", length_from=lambda pkt: pkt.optlen) ] def extract_padding(self, p): - return "", p + return "", p class DNSRROPT(Packet): name = "DNS OPT Resource Record" @@ -348,7 +348,7 @@ class DNSRROPT(Packet): # RFC 4034 - Resource Records for the DNS Security Extensions # 09/2013 from http://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml -dnssecalgotypes = { 0:"Reserved", 1:"RSA/MD5", 2:"Diffie-Hellman", 3:"DSA/SHA-1", +dnssecalgotypes = { 0:"Reserved", 1:"RSA/MD5", 2:"Diffie-Hellman", 3:"DSA/SHA-1", 4:"Reserved", 5:"RSA/SHA-1", 6:"DSA-NSEC3-SHA1", 7:"RSASHA1-NSEC3-SHA1", 8:"RSA/SHA-256", 9:"Reserved", 10:"RSA/SHA-512", 11:"Reserved", 12:"GOST R 34.10-2001", @@ -364,21 +364,21 @@ class TimeField(IntField): def any2i(self, pkt, x): if type(x) == str: - import time, calendar - t = time.strptime(x, "%Y%m%d%H%M%S") + import time, calendar + t = time.strptime(x, "%Y%m%d%H%M%S") return int(calendar.timegm(t)) return x def i2repr(self, pkt, x): - import time - x = self.i2h(pkt, x) - t = time.strftime("%Y%m%d%H%M%S", time.gmtime(x)) - return "%s (%d)" % (t ,x) + import time + x = self.i2h(pkt, x) + t = time.strftime("%Y%m%d%H%M%S", time.gmtime(x)) + return "%s (%d)" % (t ,x) def bitmap2RRlist(bitmap): """ - Decode the 'Type Bit Maps' field of the NSEC Resource Record into an + Decode the 'Type Bit Maps' field of the NSEC Resource Record into an integer list. """ # RFC 4034, 4.1.2. The Type Bit Maps Field @@ -387,38 +387,38 @@ def bitmap2RRlist(bitmap): while bitmap: - if len(bitmap) < 2: - warning("bitmap too short (%i)" % len(bitmap)) - return - - window_block = ord(bitmap[0]) # window number - offset = 256*window_block # offset of the Ressource Record - bitmap_len = ord(bitmap[1]) # length of the bitmap in bytes - - if bitmap_len <= 0 or bitmap_len > 32: - warning("bitmap length is no valid (%i)" % bitmap_len) - return - - tmp_bitmap = bitmap[2:2+bitmap_len] - - # Let's compare each bit of tmp_bitmap and compute the real RR value - for b in xrange(len(tmp_bitmap)): - v = 128 - for i in xrange(8): - if ord(tmp_bitmap[b]) & v: - # each of the RR is encoded as a bit - RRlist += [ offset + b*8 + i ] - v = v >> 1 - - # Next block if any - bitmap = bitmap[2+bitmap_len:] + if len(bitmap) < 2: + warning("bitmap too short (%i)" % len(bitmap)) + return + + window_block = ord(bitmap[0]) # window number + offset = 256*window_block # offset of the Resource Record + bitmap_len = ord(bitmap[1]) # length of the bitmap in bytes + + if bitmap_len <= 0 or bitmap_len > 32: + warning("bitmap length is no valid (%i)" % bitmap_len) + return + + tmp_bitmap = bitmap[2:2+bitmap_len] + + # Let's compare each bit of tmp_bitmap and compute the real RR value + for b in xrange(len(tmp_bitmap)): + v = 128 + for i in xrange(8): + if ord(tmp_bitmap[b]) & v: + # each of the RR is encoded as a bit + RRlist += [ offset + b*8 + i ] + v = v >> 1 + + # Next block if any + bitmap = bitmap[2+bitmap_len:] return RRlist def RRlist2bitmap(lst): """ - Encode a list of integers representing Resource Records to a bitmap field + Encode a list of integers representing Resource Records to a bitmap field used in the NSEC Resource Record. """ # RFC 4034, 4.1.2. The Type Bit Maps Field @@ -428,7 +428,7 @@ def RRlist2bitmap(lst): bitmap = "" lst = list(set(lst)) lst.sort() - + lst = filter(lambda x: x <= 65535, lst) lst = map(lambda x: abs(x), lst) @@ -436,7 +436,7 @@ def RRlist2bitmap(lst): max_window_blocks = int(math.ceil(lst[-1] / 256.)) min_window_blocks = int(math.floor(lst[0] / 256.)) if min_window_blocks == max_window_blocks: - max_window_blocks += 1 + max_window_blocks += 1 for wb in xrange(min_window_blocks, max_window_blocks+1): # First, filter out RR not encoded in the current window block @@ -445,15 +445,15 @@ def RRlist2bitmap(lst): rrlist.sort() if rrlist == []: continue - + # Compute the number of bytes used to store the bitmap if rrlist[-1] == 0: # only one element in the list - bytes = 1 + bytes = 1 else: - max = rrlist[-1] - 256*wb - bytes = int(math.ceil(max / 8)) + 1 # use at least 1 byte + max = rrlist[-1] - 256*wb + bytes = int(math.ceil(max / 8)) + 1 # use at least 1 byte if bytes > 32: # Don't encode more than 256 bits / values - bytes = 32 + bytes = 32 bitmap += struct.pack("B", wb) bitmap += struct.pack("B", bytes) @@ -461,7 +461,7 @@ def RRlist2bitmap(lst): # Generate the bitmap for tmp in xrange(bytes): v = 0 - # Remove out of range Ressource Records + # Remove out of range Resource Records tmp_rrlist = filter(lambda x: 256 * wb + 8 * tmp <= x < 256 * wb + 8 * tmp + 8, rrlist) if not tmp_rrlist == []: # 1. rescale to fit into 8 bits @@ -471,24 +471,24 @@ def RRlist2bitmap(lst): # 3. sum everything v = reduce(lambda x,y: x+y, tmp_rrlist) bitmap += struct.pack("B", v) - + return bitmap class RRlistField(StrField): def h2i(self, pkt, x): - if type(x) == list: - return RRlist2bitmap(x) - return x + if type(x) == list: + return RRlist2bitmap(x) + return x def i2repr(self, pkt, x): - x = self.i2h(pkt, x) - rrlist = bitmap2RRlist(x) - return [ dnstypes.get(rr, rr) for rr in rrlist ] + x = self.i2h(pkt, x) + rrlist = bitmap2RRlist(x) + return [ dnstypes.get(rr, rr) for rr in rrlist ] class _DNSRRdummy(Packet): - name = "Dummy class that implements post_build() for Ressource Records" + name = "Dummy class that implements post_build() for Resource Records" def post_build(self, pkt, pay): if not self.rdlen == None: return pkt @@ -496,7 +496,7 @@ class _DNSRRdummy(Packet): lrrname = len(self.fields_desc[0].i2m("", self.getfieldval("rrname"))) l = len(pkt) - lrrname - 10 pkt = pkt[:lrrname+8] + struct.pack("!H", l) + pkt[lrrname+8+2:] - + return pkt class DNSRRSOA(_DNSRRdummy): @@ -592,15 +592,15 @@ class DNSRRNSEC3(_DNSRRdummy): ShortEnumField("rclass", 1, dnsclasses), IntField("ttl", 0), ShortField("rdlen", None), - ByteField("hashalg", 0), + ByteField("hashalg", 0), BitEnumField("flags", 0, 8, {1:"Opt-Out"}), - ShortField("iterations", 0), - FieldLenField("saltlength", 0, fmt="!B", length_of="salt"), - StrLenField("salt", "", length_from=lambda x: x.saltlength), - FieldLenField("hashlength", 0, fmt="!B", length_of="nexthashedownername"), - StrLenField("nexthashedownername", "", length_from=lambda x: x.hashlength), + ShortField("iterations", 0), + FieldLenField("saltlength", 0, fmt="!B", length_of="salt"), + StrLenField("salt", "", length_from=lambda x: x.saltlength), + FieldLenField("hashlength", 0, fmt="!B", length_of="nexthashedownername"), + StrLenField("nexthashedownername", "", length_from=lambda x: x.hashlength), RRlistField("typebitmaps", "") - ] + ] class DNSRRNSEC3PARAM(_DNSRRdummy): @@ -610,12 +610,12 @@ class DNSRRNSEC3PARAM(_DNSRRdummy): ShortEnumField("rclass", 1, dnsclasses), IntField("ttl", 0), ShortField("rdlen", None), - ByteField("hashalg", 0), - ByteField("flags", 0), - ShortField("iterations", 0), - FieldLenField("saltlength", 0, fmt="!B", length_of="salt"), - StrLenField("salt", "", length_from=lambda pkt: pkt.saltlength) - ] + ByteField("hashalg", 0), + ByteField("flags", 0), + ShortField("iterations", 0), + FieldLenField("saltlength", 0, fmt="!B", length_of="salt"), + StrLenField("salt", "", length_from=lambda pkt: pkt.saltlength) + ] DNSRR_DISPATCHER = { @@ -673,9 +673,9 @@ RFC2136 return r.getlayer(DNS).rcode else: return -1 - - - + + + @conf.commands.register def dyndns_del(nameserver, name, type="ALL", ttl=10): @@ -695,7 +695,7 @@ RFC2136 return r.getlayer(DNS).rcode else: return -1 - + class DNS_am(AnsweringMachine): function_name="dns_spoof" @@ -710,7 +710,7 @@ class DNS_am(AnsweringMachine): def is_request(self, req): return req.haslayer(DNS) and req.getlayer(DNS).qr == 0 - + def make_reply(self, req): ip = req.getlayer(IP) dns = req.getlayer(DNS) diff --git a/scapy/layers/inet6.py b/scapy/layers/inet6.py index bbfc1c8d..0cb32c1f 100644 --- a/scapy/layers/inet6.py +++ b/scapy/layers/inet6.py @@ -73,11 +73,11 @@ conf.netcache.new_cache("in6_neighbor", 120) def neighsol(addr, src, iface, timeout=1, chainCC=0): """ Sends an ICMPv6 Neighbor Solicitation message to get the MAC address - of the neighbor with specified IPv6 address addr. 'src' address is + of the neighbor with specified IPv6 address addr. 'src' address is used as source of the message. Message is sent on iface. By default, timeout waiting for an answer is 1 second. - If no answer is gathered, None is returned. Else, the answer is + If no answer is gathered, None is returned. Else, the answer is returned (ethernet frame). """ @@ -87,14 +87,14 @@ def neighsol(addr, src, iface, timeout=1, chainCC=0): p = Ether(dst=dm)/IPv6(dst=d, src=src, hlim=255) p /= ICMPv6ND_NS(tgt=addr) p /= ICMPv6NDOptSrcLLAddr(lladdr=get_if_hwaddr(iface)) - res = srp1(p,type=ETH_P_IPV6, iface=iface, timeout=1, verbose=0, - chainCC=chainCC) + res = srp1(p,type=ETH_P_IPV6, iface=iface, timeout=1, verbose=0, + chainCC=chainCC) return res def getmacbyip6(ip6, chainCC=0): """ - Returns the mac address to be used for provided 'ip6' peer. + Returns the mac address to be used for provided 'ip6' peer. neighborCache.get() method is used on instantiated neighbor cache. Resolution mechanism is described in associated doc string. @@ -102,7 +102,7 @@ def getmacbyip6(ip6, chainCC=0): used to perform the resolution, if needed) """ - if in6_ismaddr(ip6): # Multicast + if in6_ismaddr(ip6): # Multicast mac = in6_getnsmac(inet_pton(socket.AF_INET6, ip6)) return mac @@ -115,7 +115,7 @@ def getmacbyip6(ip6, chainCC=0): if iff.name == LOOPBACK_NAME: return "ff:ff:ff:ff:ff:ff" - if nh != '::': + if nh != '::': ip6 = nh # Found next hop mac = conf.netcache.in6_neighbor.get(ip6) @@ -126,9 +126,9 @@ def getmacbyip6(ip6, chainCC=0): if res is not None: if ICMPv6NDOptDstLLAddr in res: - mac = res[ICMPv6NDOptDstLLAddr].lladdr - else: - mac = res.src + mac = res[ICMPv6NDOptDstLLAddr].lladdr + else: + mac = res.src conf.netcache.in6_neighbor[ip6] = mac return mac @@ -166,17 +166,17 @@ class Net6(Gen): # syntax ex. fec0::/126 a = in6_and(self.net, self.mask) tmp = map(lambda x: x, struct.unpack('16B', a)) - + def parse_digit(a, netmask): netmask = min(8,max(netmask,0)) a = (int(a) & (0xffL<<netmask),(int(a) | (0xffL>>(8-netmask)))+1) return a self.parsed = map(lambda x,y: parse_digit(x,y), tmp, map(lambda x,nm=self.plen: x-nm, tuple)) - def rec(n, l): + def rec(n, l): if n and n % 2 == 0: sep = ':' - else: + else: sep = '' if n == 16: return l @@ -226,7 +226,7 @@ class IP6Field(Field): return self.i2h(pkt,x) elif not isinstance(x, Net6) and not type(x) is list: if in6_isaddrTeredo(x): # print Teredo info - server, flag, maddr, mport = teredoAddrExtractInfo(x) + server, flag, maddr, mport = teredoAddrExtractInfo(x) return "%s [Teredo srv: %s cli: %s:%s]" % (self.i2h(pkt, x), server, maddr,mport) elif in6_isaddr6to4(x): # print encapsulated address vaddr = in6_6to4ExtractAddr(x) @@ -288,7 +288,7 @@ ipv6nh = { 0:"Hop-by-Hop Option Header", 59:"No Next Header", 60:"Destination Option Header", 132:"SCTP", - 135:"Mobility Header"} + 135:"Mobility Header"} ipv6nhcls = { 0: "IPv6ExtHdrHopByHop", 4: "IP", @@ -298,7 +298,7 @@ ipv6nhcls = { 0: "IPv6ExtHdrHopByHop", 44: "IPv6ExtHdrFragment", #50: "IPv6ExtHrESP", #51: "IPv6ExtHdrAH", - 58: "ICMPv6Unknown", + 58: "ICMPv6Unknown", 59: "Raw", 60: "IPv6ExtHdrDestOpt" } @@ -319,14 +319,14 @@ class IP6ListField(StrField): if type(i) is list: return len(i) return 0 - + def getfield(self, pkt, s): c = l = None if self.length_from is not None: l = self.length_from(pkt) elif self.count_from is not None: c = self.count_from(pkt) - + lst = [] ret = "" remain = s @@ -360,8 +360,8 @@ class IP6ListField(StrField): for y in x: s.append('%s' % y) return "[ %s ]" % (", ".join(s)) - -class _IPv6GuessPayload: + +class _IPv6GuessPayload: name = "Dummy class that implements guess_payload_class() for IPv6" def default_payload_class(self,p): if self.nh == 58: # ICMPv6 @@ -421,8 +421,8 @@ class IPv6(_IPv6GuessPayload, Packet, IPTools): sd = self.dst ss = self.src if self.nh == 43 and isinstance(self.payload, IPv6ExtHdrRouting): - # With routing header, the destination is the last - # address of the IPv6 list if segleft > 0 + # With routing header, the destination is the last + # address of the IPv6 list if segleft > 0 nh = self.payload.nh try: sd = self.addresses[-1] @@ -438,10 +438,10 @@ class IPv6(_IPv6GuessPayload, Packet, IPTools): sd = inet_ntop(socket.AF_INET6, sd) if self.nh == 44 and isinstance(self.payload, IPv6ExtHdrFragment): - nh = self.payload.nh + nh = self.payload.nh if self.nh == 0 and isinstance(self.payload, IPv6ExtHdrHopByHop): - nh = self.payload.nh + nh = self.payload.nh if self.nh == 60 and isinstance(self.payload, IPv6ExtHdrDestOpt): foundhao = None @@ -469,25 +469,25 @@ class IPv6(_IPv6GuessPayload, Packet, IPTools): return self.answers(other.payload) if not isinstance(other, IPv6): # self is reply, other is request return False - if conf.checkIPaddr: + if conf.checkIPaddr: ss = inet_pton(socket.AF_INET6, self.src) sd = inet_pton(socket.AF_INET6, self.dst) os = inet_pton(socket.AF_INET6, other.src) od = inet_pton(socket.AF_INET6, other.dst) # request was sent to a multicast address (other.dst) - # Check reply destination addr matches request source addr (i.e + # Check reply destination addr matches request source addr (i.e # sd == os) except when reply is multicasted too # XXX test mcast scope matching ? if in6_ismaddr(other.dst): if in6_ismaddr(self.dst): - if ((od == sd) or + if ((od == sd) or (in6_isaddrllallnodes(self.dst) and in6_isaddrllallservers(other.dst))): return self.payload.answers(other.payload) return False - if (os == sd): + if (os == sd): return self.payload.answers(other.payload) return False - elif (sd != os): # or ss != od): <- removed for ICMP errors + elif (sd != os): # or ss != od): <- removed for ICMP errors return False if self.nh == 58 and isinstance(self.payload, _ICMPv6) and self.payload.type < 128: # ICMPv6 Error message -> generated by IPv6 packet @@ -498,9 +498,9 @@ class IPv6(_IPv6GuessPayload, Packet, IPTools): # a specific task. Currently, don't see any use ... return self.payload.payload.answers(other) elif other.nh == 0 and isinstance(other.payload, IPv6ExtHdrHopByHop): - return self.payload.answers(other.payload.payload) + return self.payload.answers(other.payload.payload) elif other.nh == 44 and isinstance(other.payload, IPv6ExtHdrFragment): - return self.payload.answers(other.payload.payload) + return self.payload.answers(other.payload.payload) elif other.nh == 43 and isinstance(other.payload, IPv6ExtHdrRouting): return self.payload.answers(other.payload.payload) # Buggy if self.payload is a IPv6ExtHdrRouting elif other.nh == 60 and isinstance(other.payload, IPv6ExtHdrDestOpt): @@ -530,7 +530,7 @@ class IPerror6(IPv6): # Make sure that the ICMPv6 error is related to the packet scapy sent if isinstance(self.underlayer, _ICMPv6) and self.underlayer.type < 128: - + # find upper layer for self (possible citation) selfup = self.payload while selfup is not None and isinstance(selfup, _IPv6ExtHdr): @@ -544,16 +544,16 @@ class IPerror6(IPv6): request_has_rh = True otherup = otherup.payload - if ((ss == os and sd == od) or # <- Basic case - (ss == os and request_has_rh)): # <- Request has a RH : + if ((ss == os and sd == od) or # <- Basic case + (ss == os and request_has_rh)): # <- Request has a RH : # don't check dst address - - # Let's deal with possible MSS Clamping - if (isinstance(selfup, TCP) and + + # Let's deal with possible MSS Clamping + if (isinstance(selfup, TCP) and isinstance(otherup, TCP) and selfup.options != otherup.options): # seems clamped - # Save fields modified by MSS clamping + # Save fields modified by MSS clamping old_otherup_opts = otherup.options old_otherup_cksum = otherup.chksum old_otherup_dataofs = otherup.dataofs @@ -591,7 +591,7 @@ class IPerror6(IPv6): return s1[:l] == s2[:l] return False - + def mysummary(self): return Packet.mysummary(self) @@ -608,15 +608,15 @@ class PseudoIPv6(Packet): # IPv6 Pseudo-header for checksum computation IP6Field("dst", "::"), ShortField("uplen", None), BitField("zero", 0, 24), - ByteField("nh", 0) ] + ByteField("nh", 0) ] def in6_chksum(nh, u, p): """ Performs IPv6 Upper Layer checksum computation. Provided parameters are: - - 'nh' : value of upper layer protocol - - 'u' : upper layer instance (TCP, UDP, ICMPv6*, ). Instance must be - provided with all under layers (IPv6 and all extension headers, + - 'nh' : value of upper layer protocol + - 'u' : upper layer instance (TCP, UDP, ICMPv6*, ). Instance must be + provided with all under layers (IPv6 and all extension headers, for example) - 'p' : the payload of the upper layer provided as a string @@ -625,7 +625,7 @@ def in6_chksum(nh, u, p): - Next Header value - the address of _final_ destination (if some Routing Header with non segleft field is present in underlayer classes, last address is used.) - - the address of _real_ source (basically the source address of an + - the address of _real_ source (basically the source address of an IPv6 class instance available in the underlayer or the source address in HAO option if some Destination Option header found in underlayer includes this option). @@ -647,10 +647,10 @@ def in6_chksum(nh, u, p): isinstance(u.options[0], HAO)): hahdr = u.options[0].hoa u = u.underlayer - if u is None: + if u is None: warning("No IPv6 underlayer to compute checksum. Leaving null.") return 0 - if hahdr: + if hahdr: ph6.src = hahdr else: ph6.src = u.src @@ -670,7 +670,7 @@ def in6_chksum(nh, u, p): ############################################################################# -# Inherited by all extension header classes +# Inherited by all extension header classes class _IPv6ExtHdr(_IPv6GuessPayload, Packet): name = 'Abstract IPV6 Option Header' aliastypes = [IPv6, IPerror6] # TODO ... @@ -687,18 +687,18 @@ _hbhopts = { 0x00: "Pad1", 0xc9: "Home Address Option" } class _OTypeField(ByteEnumField): - """ + """ Modified BytEnumField that displays information regarding the IPv6 option based on its option type value (What should be done by nodes that process the option if they do not understand it ...) - It is used by Jumbo, Pad1, PadN, RouterAlert, HAO options + It is used by Jumbo, Pad1, PadN, RouterAlert, HAO options """ pol = {0x00: "00: skip", 0x40: "01: discard", 0x80: "10: discard+ICMP", 0xC0: "11: discard+ICMP not mcast"} - + enroutechange = {0x00: "0: Don't change en-route", 0x20: "1: May change en-route" } @@ -710,17 +710,17 @@ class _OTypeField(ByteEnumField): class HBHOptUnknown(Packet): # IPv6 Hop-By-Hop Option name = "Scapy6 Unknown Option" - fields_desc = [_OTypeField("otype", 0x01, _hbhopts), + fields_desc = [_OTypeField("otype", 0x01, _hbhopts), FieldLenField("optlen", None, length_of="optdata", fmt="B"), StrLenField("optdata", "", - length_from = lambda pkt: pkt.optlen) ] + length_from = lambda pkt: pkt.optlen) ] def alignment_delta(self, curpos): # By default, no alignment requirement """ - As specified in section 4.2 of RFC 2460, every options has - an alignment requirement ususally expressed xn+y, meaning - the Option Type must appear at an integer multiple of x octest + As specified in section 4.2 of RFC 2460, every options has + an alignment requirement ususally expressed xn+y, meaning + the Option Type must appear at an integer multiple of x octest from the start of the header, plus y octet. - + That function is provided the current position from the start of the header and returns required padding length. """ @@ -733,7 +733,7 @@ class Pad1(Packet): # IPv6 Hop-By-Hop Option return 0 class PadN(Packet): # IPv6 Hop-By-Hop Option - name = "PadN" + name = "PadN" fields_desc = [_OTypeField("otype", 0x01, _hbhopts), FieldLenField("optlen", None, length_of="optdata", fmt="B"), StrLenField("optdata", "", @@ -758,17 +758,17 @@ class RouterAlert(Packet): # RFC 2711 - IPv6 Hop-By-Hop Option # iana.org/assignments/ipv6-routeralert-values/ipv6-routeralert-values.xhtml def alignment_delta(self, curpos): # alignment requirement : 2n+0 x = 2 ; y = 0 - delta = x*((curpos - y + x - 1)/x) + y - curpos + delta = x*((curpos - y + x - 1)/x) + y - curpos return delta class Jumbo(Packet): # IPv6 Hop-By-Hop Option - name = "Jumbo Payload" + name = "Jumbo Payload" fields_desc = [_OTypeField("otype", 0xC2, _hbhopts), ByteField("optlen", 4), IntField("jumboplen", None) ] def alignment_delta(self, curpos): # alignment requirement : 4n+2 x = 4 ; y = 2 - delta = x*((curpos - y + x - 1)/x) + y - curpos + delta = x*((curpos - y + x - 1)/x) + y - curpos return delta class HAO(Packet): # IPv6 Destination Options Header Option @@ -778,7 +778,7 @@ class HAO(Packet): # IPv6 Destination Options Header Option IP6Field("hoa", "::") ] def alignment_delta(self, curpos): # alignment requirement : 8n+6 x = 8 ; y = 6 - delta = x*((curpos - y + x - 1)/x) + y - curpos + delta = x*((curpos - y + x - 1)/x) + y - curpos return delta _hbhoptcls = { 0x00: Pad1, @@ -795,7 +795,7 @@ class _HopByHopOptionsField(PacketListField): def __init__(self, name, default, cls, curpos, count_from=None, length_from=None): self.curpos = curpos PacketListField.__init__(self, name, default, cls, count_from=count_from, length_from=length_from) - + def i2len(self, pkt, i): l = len(self.i2m(pkt, i)) return l @@ -811,7 +811,7 @@ class _HopByHopOptionsField(PacketListField): l = self.length_from(pkt) elif self.count_from is not None: c = self.count_from(pkt) - + opt = [] ret = "" x = s @@ -844,7 +844,7 @@ class _HopByHopOptionsField(PacketListField): autopad = getattr(pkt, "autopad") # Hack : 'autopad' phantom field except: autopad = 1 - + if not autopad: return "".join(map(str, x)) @@ -860,7 +860,7 @@ class _HopByHopOptionsField(PacketListField): pstr = str(p) curpos += len(pstr) s += pstr - + # Let's make the class including our option field # a multiple of 8 octets long d = curpos % 8 @@ -870,7 +870,7 @@ class _HopByHopOptionsField(PacketListField): if d == 1: s += str(Pad1()) elif d != 0: - s += str(PadN(optdata='\x00'*(d-2))) + s += str(PadN(optdata='\x00'*(d-2))) return s @@ -890,11 +890,11 @@ class _PhantomAutoPadField(ByteField): return "Off" -class IPv6ExtHdrHopByHop(_IPv6ExtHdr): +class IPv6ExtHdrHopByHop(_IPv6ExtHdr): name = "IPv6 Extension Header - Hop-by-Hop Options Header" fields_desc = [ ByteEnumField("nh", 59, ipv6nh), FieldLenField("len", None, length_of="options", fmt="B", - adjust = lambda pkt,x: (x+2+7)/8 - 1), + adjust = lambda pkt,x: (x+2+7)/8 - 1), _PhantomAutoPadField("autopad", 1), # autopad activated by default _HopByHopOptionsField("options", [], HBHOptUnknown, 2, length_from = lambda pkt: (8*(pkt.len+1))-2) ] @@ -903,11 +903,11 @@ class IPv6ExtHdrHopByHop(_IPv6ExtHdr): ######################## Destination Option Header ########################## -class IPv6ExtHdrDestOpt(_IPv6ExtHdr): +class IPv6ExtHdrDestOpt(_IPv6ExtHdr): name = "IPv6 Extension Header - Destination Options Header" fields_desc = [ ByteEnumField("nh", 59, ipv6nh), FieldLenField("len", None, length_of="options", fmt="B", - adjust = lambda pkt,x: (x+2+7)/8 - 1), + adjust = lambda pkt,x: (x+2+7)/8 - 1), _PhantomAutoPadField("autopad", 1), # autopad activated by default _HopByHopOptionsField("options", [], HBHOptUnknown, 2, length_from = lambda pkt: (8*(pkt.len+1))-2) ] @@ -935,7 +935,7 @@ class IPv6ExtHdrRouting(_IPv6ExtHdr): ########################### Fragmentation Header ############################ -class IPv6ExtHdrFragment(_IPv6ExtHdr): +class IPv6ExtHdrFragment(_IPv6ExtHdr): name = "IPv6 Extension Header - Fragmentation header" fields_desc = [ ByteEnumField("nh", 59, ipv6nh), BitField("res1", 0, 8), @@ -951,12 +951,12 @@ def defragment6(pktlist): Performs defragmentation of a list of IPv6 packets. Packets are reordered. Crap is dropped. What lacks is completed by 'X' characters. """ - + l = filter(lambda x: IPv6ExtHdrFragment in x, pktlist) # remove non fragments if not l: return [] - id = l[0][IPv6ExtHdrFragment].id + id = l[0][IPv6ExtHdrFragment].id llen = len(l) l = filter(lambda x: x[IPv6ExtHdrFragment].id == id, l) @@ -964,8 +964,8 @@ def defragment6(pktlist): warning("defragment6: some fragmented packets have been removed from list") llen = len(l) - # reorder fragments - i = 0 + # reorder fragments + i = 0 res = [] while l: min_pos = 0 @@ -994,13 +994,13 @@ def defragment6(pktlist): q[IPv6ExtHdrFragment].underlayer.nh = nh del q[IPv6ExtHdrFragment].underlayer.payload q /= conf.raw_layer(load=fragmentable) - + return IPv6(str(q)) def fragment6(pkt, fragSize): """ - Performs fragmentation of an IPv6 packet. Provided packet ('pkt') must already + Performs fragmentation of an IPv6 packet. Provided packet ('pkt') must already contain an IPv6ExtHdrFragment() class. 'fragSize' argument is the expected maximum size of fragments (MTU). The list of packets is returned. @@ -1017,11 +1017,11 @@ def fragment6(pkt, fragSize): return [pkt] # If the payload is bigger than 65535, a Jumbo payload must be used, as - # an IPv6 packet can't be bigger than 65535 bytes. + # an IPv6 packet can't be bigger than 65535 bytes. if len(str(pkt[IPv6ExtHdrFragment])) > 65535: warning("An IPv6 packet can'be bigger than 65535, please use a Jumbo payload.") return [] - + s = str(pkt) # for instantiation to get upper layer checksum right if len(s) <= fragSize: @@ -1045,14 +1045,14 @@ def fragment6(pkt, fragSize): unfragPart = pkt del pkt[IPv6ExtHdrFragment].underlayer.payload # detach payload - # Cut the fragmentable part to fit fragSize. Inner fragments have + # Cut the fragmentable part to fit fragSize. Inner fragments have # a length that is an integer multiple of 8 octets. last Frag MTU # can be anything below MTU lastFragSize = fragSize - unfragPartLen - 8 innerFragSize = lastFragSize - (lastFragSize % 8) - + if lastFragSize <= 0 or innerFragSize == 0: - warning("Provided fragment size value is too low. " + + warning("Provided fragment size value is too low. " + "Should be more than %d" % (unfragPartLen + 8)) return [unfragPart/fragHeader/fragPart] @@ -1069,11 +1069,11 @@ def fragment6(pkt, fragSize): # Main loop : cut, fit to FRAGSIZEs, fragOffset, Id ... while True: if (len(remain) > lastFragSize): - tmp = remain[:innerFragSize] + tmp = remain[:innerFragSize] remain = remain[innerFragSize:] fragHeader.offset = fragOffset # update offset fragOffset += (innerFragSize / 8) # compute new one - if IPv6 in unfragPart: + if IPv6 in unfragPart: unfragPart[IPv6].plen = None tempo = unfragPart/fragHeader/conf.raw_layer(load=tmp) res.append(tempo) @@ -1095,11 +1095,11 @@ def fragment6(pkt, fragSize): # l = getattr(pkt, self.fld) # l = (l*8)-self.shift # i = self.m2i(pkt, s[:l]) -# return s[l:],i +# return s[l:],i # class _AHICVStrLenField(StrLenField): # def i2len(self, pkt, x): - + # class IPv6ExtHdrAH(_IPv6ExtHdr): @@ -1126,11 +1126,11 @@ def fragment6(pkt, fragSize): # name = "IPv6 Extension Header - ESP" # fields_desc = [ IntField("spi", 0), # IntField("sn", 0), -# # there is things to extract from IKE work +# # there is things to extract from IKE work # ] # overloads_fields = {IPv6: { "nh": 50 }} - + ############################################################################# ############################################################################# @@ -1144,7 +1144,7 @@ icmp6typescls = { 1: "ICMPv6DestUnreach", 4: "ICMPv6ParamProblem", 128: "ICMPv6EchoRequest", 129: "ICMPv6EchoReply", - 130: "ICMPv6MLQuery", + 130: "ICMPv6MLQuery", 131: "ICMPv6MLReport", 132: "ICMPv6MLDone", 133: "ICMPv6ND_RS", @@ -1158,7 +1158,7 @@ icmp6typescls = { 1: "ICMPv6DestUnreach", 141: "ICMPv6ND_INDSol", 142: "ICMPv6ND_INDAdv", #143: Do Me - RFC 3810 - 144: "ICMPv6HAADRequest", + 144: "ICMPv6HAADRequest", 145: "ICMPv6HAADReply", 146: "ICMPv6MPSol", 147: "ICMPv6MPAdv", @@ -1196,8 +1196,8 @@ icmp6typesminhdrlen = { 1: 8, 153: 4 } -icmp6types = { 1 : "Destination unreachable", - 2 : "Packet too big", +icmp6types = { 1 : "Destination unreachable", + 2 : "Packet too big", 3 : "Time exceeded", 4 : "Parameter problem", 100 : "Private Experimentation", @@ -1213,8 +1213,8 @@ icmp6types = { 1 : "Destination unreachable", 136 : "Neighbor Advertisement", 137 : "Redirect Message", 138 : "Router Renumbering", - 139 : "ICMP Node Information Query", - 140 : "ICMP Node Information Response", + 139 : "ICMP Node Information Query", + 140 : "ICMP Node Information Response", 141 : "Inverse Neighbor Discovery Solicitation Message", 142 : "Inverse Neighbor Discovery Advertisement Message", 143 : "Version 2 Multicast Listener Report", @@ -1236,7 +1236,7 @@ class _ICMPv6(Packet): overload_fields = {IPv6: {"nh": 58}} def post_build(self, p, pay): p += pay - if self.cksum == None: + if self.cksum == None: chksum = in6_chksum(58, self.underlayer, p) p = p[:2]+struct.pack("!H", chksum)+p[4:] return p @@ -1266,7 +1266,7 @@ class ICMPv6Unknown(_ICMPv6): fields_desc = [ ByteEnumField("type",1, icmp6types), ByteField("code",0), XShortField("cksum", None), - StrField("msgbody", "")] + StrField("msgbody", "")] ################################## RFC 2460 ################################# @@ -1289,7 +1289,7 @@ class ICMPv6PacketTooBig(_ICMPv6Error): ByteField("code",0), XShortField("cksum", None), IntField("mtu",1280)] - + class ICMPv6TimeExceeded(_ICMPv6Error): name = "ICMPv6 Time Exceeded" fields_desc = [ ByteEnumField("type",3, icmp6types), @@ -1299,9 +1299,9 @@ class ICMPv6TimeExceeded(_ICMPv6Error): ByteField("length", 0), X3BytesField("unused",0)] -# The default pointer value is set to the next header field of +# The default pointer value is set to the next header field of # the encapsulated IPv6 packet -class ICMPv6ParamProblem(_ICMPv6Error): +class ICMPv6ParamProblem(_ICMPv6Error): name = "ICMPv6 Parameter Problem" fields_desc = [ ByteEnumField("type",4, icmp6types), ByteEnumField("code",0, {0: "erroneous header field encountered", @@ -1323,12 +1323,12 @@ class ICMPv6EchoRequest(_ICMPv6): def hashret(self): return struct.pack("HH",self.id,self.seq)+self.payload.hashret() - + class ICMPv6EchoReply(ICMPv6EchoRequest): name = "ICMPv6 Echo Reply" type = 129 def answers(self, other): - # We could match data content between request and reply. + # We could match data content between request and reply. return (isinstance(other, ICMPv6EchoRequest) and self.id == other.id and self.seq == other.seq and self.data == other.data) @@ -1342,7 +1342,7 @@ class ICMPv6EchoReply(ICMPv6EchoRequest): # "and an IPv6 Router Alert option in a Hop-by-Hop Options # header. (The router alert option is necessary to cause routers to # examine MLD messages sent to multicast addresses in which the router -# itself has no interest" +# itself has no interest" class _ICMPv6ML(_ICMPv6): fields_desc = [ ByteEnumField("type", 130, icmp6types), ByteField("code", 0), @@ -1363,7 +1363,7 @@ class ICMPv6MLQuery(_ICMPv6ML): # RFC 2710 type = 130 mrd = 10000 # 10s for mrd mladdr = "::" - overload_fields = {IPv6: { "dst": "ff02::1", "hlim": 1, "nh": 58 }} + overload_fields = {IPv6: { "dst": "ff02::1", "hlim": 1, "nh": 58 }} def hashret(self): if self.mladdr != "::": return ( @@ -1371,8 +1371,8 @@ class ICMPv6MLQuery(_ICMPv6ML): # RFC 2710 ) else: return self.payload.hashret() - - + + # TODO : See what we can do to automatically include a Router Alert # Option in a Destination Option Header. class ICMPv6MLReport(_ICMPv6ML): # RFC 2710 @@ -1380,7 +1380,7 @@ class ICMPv6MLReport(_ICMPv6ML): # RFC 2710 type = 131 overload_fields = {IPv6: {"hlim": 1, "nh": 58}} # implementer le hashret et le answers - + # When a node ceases to listen to a multicast address on an interface, # it SHOULD send a single Done message to the link-scope all-routers # multicast address (FF02::2), carrying in its multicast address field @@ -1395,13 +1395,13 @@ class ICMPv6MLDone(_ICMPv6ML): # RFC 2710 ########## ICMPv6 MRD - Multicast Router Discovery (RFC 4286) ############### -# TODO: +# TODO: # - 04/09/06 troglocan : find a way to automatically add a router alert # option for all MRD packets. This could be done in a specific # way when IPv6 is the under layer with some specific keyword # like 'exthdr'. This would allow to keep compatibility with # providing IPv6 fields to be overloaded in fields_desc. -# +# # At the moment, if user inserts an IPv6 Router alert option # none of the IPv6 default values of IPv6 layer will be set. @@ -1432,7 +1432,7 @@ class ICMPv6MRD_Termination(_ICMPv6): fields_desc = [ByteEnumField("type", 153, icmp6types), ByteField("res", 0), XShortField("cksum", None) ] - overload_fields = {IPv6: { "nh": 58, "hlim": 1, "dst": "ff02::6A"}} + overload_fields = {IPv6: { "nh": 58, "hlim": 1, "dst": "ff02::6A"}} # IPv6 Router Alert requires manual inclusion def extract_padding(self, s): return s[:4], s[4:] @@ -1459,7 +1459,7 @@ icmp6ndopts = { 1: "Source Link-Layer Address", 17: "IP Address Option", # RFC 4068 18: "New Router Prefix Information Option", # RFC 4068 19: "Link-layer Address Option", # RFC 4068 - 20: "Neighbor Advertisement Acknowledgement Option", + 20: "Neighbor Advertisement Acknowledgement Option", 21: "CARD Request Option", # RFC 4065/4066/4067 22: "CARD Reply Option", # RFC 4065/4066/4067 23: "MAP Option", # RFC 4140 @@ -1467,7 +1467,7 @@ icmp6ndopts = { 1: "Source Link-Layer Address", 25: "Recusive DNS Server Option", 26: "IPv6 Router Advertisement Flags Option" } - + icmp6ndoptscls = { 1: "ICMPv6NDOptSrcLLAddr", 2: "ICMPv6NDOptDstLLAddr", 3: "ICMPv6NDOptPrefixInfo", @@ -1484,7 +1484,7 @@ icmp6ndoptscls = { 1: "ICMPv6NDOptSrcLLAddr", #14: Do Me, #15: Do Me, #16: Do Me, - 17: "ICMPv6NDOptIPAddr", + 17: "ICMPv6NDOptIPAddr", 18: "ICMPv6NDOptNewRtrPrefix", 19: "ICMPv6NDOptLLA", #18: Do Me, @@ -1523,7 +1523,7 @@ class ICMPv6NDOptSrcLLAddr(_ICMPv6NDGuessPayload, Packet): fields_desc = [ ByteField("type", 1), ByteField("len", 1), MACField("lladdr", ETHER_ANY) ] - def mysummary(self): + def mysummary(self): return self.sprintf("%name% %lladdr%") class ICMPv6NDOptDstLLAddr(ICMPv6NDOptSrcLLAddr): @@ -1543,7 +1543,7 @@ class ICMPv6NDOptPrefixInfo(_ICMPv6NDGuessPayload, Packet): XIntField("preferredlifetime",0xffffffffL), XIntField("res2",0x00000000), IP6Field("prefix","::") ] - def mysummary(self): + def mysummary(self): return self.sprintf("%name% %prefix%") # TODO: We should also limit the size of included packet to something @@ -1604,24 +1604,24 @@ class ICMPv6NDOptShortcutLimit(_ICMPv6NDGuessPayload, Packet): # RFC 2491 ByteField("shortcutlim", 40), # XXX ByteField("res1", 0), IntField("res2", 0) ] - + class ICMPv6NDOptAdvInterval(_ICMPv6NDGuessPayload, Packet): name = "ICMPv6 Neighbor Discovery - Interval Advertisement" fields_desc = [ ByteField("type",7), ByteField("len",1), ShortField("res", 0), IntField("advint", 0) ] - def mysummary(self): + def mysummary(self): return self.sprintf("%name% %advint% milliseconds") -class ICMPv6NDOptHAInfo(_ICMPv6NDGuessPayload, Packet): +class ICMPv6NDOptHAInfo(_ICMPv6NDGuessPayload, Packet): name = "ICMPv6 Neighbor Discovery - Home Agent Information" fields_desc = [ ByteField("type",8), ByteField("len",1), ShortField("res", 0), ShortField("pref", 0), ShortField("lifetime", 1)] - def mysummary(self): + def mysummary(self): return self.sprintf("%name% %pref% %lifetime% seconds") # type 9 : See ICMPv6NDOptSrcAddrList class below in IND (RFC 3122) support @@ -1671,9 +1671,9 @@ class ICMPv6NDOptMAP(_ICMPv6NDGuessPayload, Packet): # RFC 4140 BitField("dist", 1, 4), BitField("pref", 15, 4), # highest availability BitField("R", 1, 1), - BitField("res", 0, 7), + BitField("res", 0, 7), IntField("validlifetime", 0xffffffff), - IP6Field("addr", "::") ] + IP6Field("addr", "::") ] class _IP6PrefixField(IP6Field): @@ -1694,7 +1694,7 @@ class _IP6PrefixField(IP6Field): def i2len(self, pkt, x): return len(self.i2m(pkt, x)) - + def i2m(self, pkt, x): l = pkt.len @@ -1724,7 +1724,7 @@ class ICMPv6NDOptRouteInfo(_ICMPv6NDGuessPayload, Packet): # RFC 4191 BitField("res2",0,3), IntField("rtlifetime", 0xffffffff), _IP6PrefixField("prefix", None) ] - + class ICMPv6NDOptRDNSS(_ICMPv6NDGuessPayload, Packet): # RFC 5006 name = "ICMPv6 Neighbor Discovery Option - Recursive DNS Server Option" fields_desc = [ ByteField("type", 25), @@ -1732,7 +1732,7 @@ class ICMPv6NDOptRDNSS(_ICMPv6NDGuessPayload, Packet): # RFC 5006 adjust = lambda pkt,x: 2*x+1), ShortField("res", None), IntField("lifetime", 0xffffffff), - IP6ListField("dns", [], + IP6ListField("dns", [], length_from = lambda pkt: 8*(pkt.len-1)) ] class ICMPv6NDOptEFA(_ICMPv6NDGuessPayload, Packet): # RFC 5175 (prev. 5075) @@ -1828,7 +1828,7 @@ class ICMPv6ND_RA(_ICMPv6NDGuessPayload, _ICMPv6): 2: "Reserved", 3: "Low" } ), # RFC 4191 BitField("P",0,1), - BitField("res",0,2), + BitField("res",0,2), ShortField("routerlifetime",1800), IntField("reachabletime",0), IntField("retranstimer",0) ] @@ -1850,7 +1850,7 @@ class ICMPv6ND_NS(_ICMPv6NDGuessPayload, _ICMPv6, Packet): return self.sprintf("%name% (tgt: %tgt%)") def hashret(self): - return self.tgt+self.payload.hashret() + return self.tgt+self.payload.hashret() class ICMPv6ND_NA(_ICMPv6NDGuessPayload, _ICMPv6, Packet): name = "ICMPv6 Neighbor Discovery - Neighbor Advertisement" @@ -1868,7 +1868,7 @@ class ICMPv6ND_NA(_ICMPv6NDGuessPayload, _ICMPv6, Packet): return self.sprintf("%name% (tgt: %tgt%)") def hashret(self): - return self.tgt+self.payload.hashret() + return self.tgt+self.payload.hashret() def answers(self, other): return isinstance(other, ICMPv6ND_NS) and self.tgt == other.tgt @@ -1899,7 +1899,7 @@ class ICMPv6NDOptSrcAddrList(_ICMPv6NDGuessPayload, Packet): class ICMPv6NDOptTgtAddrList(ICMPv6NDOptSrcAddrList): name = "ICMPv6 Inverse Neighbor Discovery Option - Target Address List" - type = 10 + type = 10 # RFC3122 @@ -1909,7 +1909,7 @@ class ICMPv6NDOptTgtAddrList(ICMPv6NDOptSrcAddrList): # demandee dans l'option requise target lladdr et l'utiliser au niveau # de l'adresse destination ethernet si aucune adresse n'est precisee # - ca semble pas forcement pratique si l'utilisateur doit preciser toutes -# les options. +# les options. # Ether() must use the target lladdr as destination class ICMPv6ND_INDSol(_ICMPv6NDGuessPayload, _ICMPv6): name = "ICMPv6 Inverse Neighbor Discovery Solicitation" @@ -1934,22 +1934,22 @@ class ICMPv6ND_INDAdv(_ICMPv6NDGuessPayload, _ICMPv6): # ICMPv6 Node Information Queries (RFC 4620) ############################################################################### -# [ ] Add automatic destination address computation using computeNIGroupAddr +# [ ] Add automatic destination address computation using computeNIGroupAddr # in IPv6 class (Scapy6 modification when integrated) if : # - it is not provided # - upper layer is ICMPv6NIQueryName() with a valid value # [ ] Try to be liberal in what we accept as internal values for _explicit_ -# DNS elements provided by users. Any string should be considered +# DNS elements provided by users. Any string should be considered # valid and kept like it has been provided. At the moment, i2repr() will # crash on many inputs # [ ] Do the documentation # [ ] Add regression tests -# [ ] Perform test against real machines (NOOP reply is proof of implementation). -# [ ] Check if there are differences between different stacks. Among *BSD, -# with others. +# [ ] Perform test against real machines (NOOP reply is proof of implementation). +# [ ] Check if there are differences between different stacks. Among *BSD, +# with others. # [ ] Deal with flags in a consistent way. -# [ ] Implement compression in names2dnsrepr() and decompresiion in -# dnsrepr2names(). Should be deactivable. +# [ ] Implement compression in names2dnsrepr() and decompresiion in +# dnsrepr2names(). Should be deactivable. icmp6_niqtypes = { 0: "NOOP", 2: "Node Name", @@ -1983,28 +1983,28 @@ def computeNIGroupAddr(name): return addr -# Here is the deal. First, that protocol is a piece of shit. Then, we +# Here is the deal. First, that protocol is a piece of shit. Then, we # provide 4 classes for the different kinds of Requests (one for every # valid qtype: NOOP, Node Name, IPv6@, IPv4@). They all share the same -# data field class that is made to be smart by guessing the specifc -# type of value provided : +# data field class that is made to be smart by guessing the specific +# type of value provided : # # - IPv6 if acceptable for inet_pton(AF_INET6, ): code is set to 0, -# if not overriden by user +# if not overridden by user # - IPv4 if acceptable for inet_pton(AF_INET, ): code is set to 2, -# if not overriden -# - Name in the other cases: code is set to 0, if not overriden by user +# if not overridden +# - Name in the other cases: code is set to 0, if not overridden by user # # Internal storage, is not only the value, but the a pair providing # the type and the value (1 is IPv6@, 1 is Name or string, 2 is IPv4@) # -# Note : I merged getfield() and m2i(). m2i() should not be called -# directly anyway. Same remark for addfield() and i2m() +# Note : I merged getfield() and m2i(). m2i() should not be called +# directly anyway. Same remark for addfield() and i2m() # -# -- arno +# -- arno -# "The type of information present in the Data field of a query is -# declared by the ICMP Code, whereas the type of information in a +# "The type of information present in the Data field of a query is +# declared by the ICMP Code, whereas the type of information in a # Reply is determined by the Qtype" def names2dnsrepr(x): @@ -2015,7 +2015,7 @@ def names2dnsrepr(x): is passed, it is returned unmodified. Result is a string. !!! At the moment, compression is not implemented !!! """ - + if type(x) is str: if x and x[-1] == '\x00': # stupid heuristic return x @@ -2025,7 +2025,7 @@ def names2dnsrepr(x): for n in x: termin = "\x00" if n.count('.') == 0: # single-component gets one more - termin += '\x00' + termin += '\x00' n = "".join(map(lambda y: chr(len(y))+y, n.split("."))) + termin res.append(n) return "".join(res) @@ -2033,7 +2033,7 @@ def names2dnsrepr(x): def dnsrepr2names(x): """ - Take as input a DNS encoded string (possibly compressed) + Take as input a DNS encoded string (possibly compressed) and returns a list of DNS names contained in it. If provided string is already in printable format (does not end with a null character, a one element list @@ -2094,12 +2094,12 @@ class NIQueryDataField(StrField): def i2repr(self, pkt, x): t,val = x if t == 1: # DNS Name - # we don't use dnsrepr2names() to deal with + # we don't use dnsrepr2names() to deal with # possible weird data extracted info res = [] weird = None while val: - l = ord(val[0]) + l = ord(val[0]) val = val[1:] if l == 0: if (len(res) > 1 and val): # fqdn with data behind @@ -2155,59 +2155,59 @@ class NIQueryCodeField(ByteEnumField): else: return 1 return x - + _niquery_code = {0: "IPv6 Query", 1: "Name Query", 2: "IPv4 Query"} #_niquery_flags = { 2: "All unicast addresses", 4: "IPv4 addresses", -# 8: "Link-local addresses", 16: "Site-local addresses", +# 8: "Link-local addresses", 16: "Site-local addresses", # 32: "Global addresses" } # "This NI type has no defined flags and never has a Data Field". Used # to know if the destination is up and implements NI protocol. -class ICMPv6NIQueryNOOP(_ICMPv6NIHashret, _ICMPv6): +class ICMPv6NIQueryNOOP(_ICMPv6NIHashret, _ICMPv6): name = "ICMPv6 Node Information Query - NOOP Query" fields_desc = [ ByteEnumField("type", 139, icmp6types), NIQueryCodeField("code", None, _niquery_code), XShortField("cksum", None), ShortEnumField("qtype", 0, icmp6_niqtypes), BitField("unused", 0, 10), - FlagsField("flags", 0, 6, "TACLSG"), + FlagsField("flags", 0, 6, "TACLSG"), NonceField("nonce", None), NIQueryDataField("data", None) ] -class ICMPv6NIQueryName(ICMPv6NIQueryNOOP): +class ICMPv6NIQueryName(ICMPv6NIQueryNOOP): name = "ICMPv6 Node Information Query - IPv6 Name Query" - qtype = 2 + qtype = 2 -# We ask for the IPv6 address of the peer +# We ask for the IPv6 address of the peer class ICMPv6NIQueryIPv6(ICMPv6NIQueryNOOP): name = "ICMPv6 Node Information Query - IPv6 Address Query" qtype = 3 flags = 0x3E -class ICMPv6NIQueryIPv4(ICMPv6NIQueryNOOP): +class ICMPv6NIQueryIPv4(ICMPv6NIQueryNOOP): name = "ICMPv6 Node Information Query - IPv4 Address Query" qtype = 4 -_nireply_code = { 0: "Successful Reply", - 1: "Response Refusal", +_nireply_code = { 0: "Successful Reply", + 1: "Response Refusal", 3: "Unknown query type" } -_nireply_flags = { 1: "Reply set incomplete", - 2: "All unicast addresses", - 4: "IPv4 addresses", - 8: "Link-local addresses", - 16: "Site-local addresses", +_nireply_flags = { 1: "Reply set incomplete", + 2: "All unicast addresses", + 4: "IPv4 addresses", + 8: "Link-local addresses", + 16: "Site-local addresses", 32: "Global addresses" } # Internal repr is one of those : # (0, "some string") : unknow qtype value are mapped to that one # (3, [ (ttl, ip6), ... ]) -# (4, [ (ttl, ip4), ... ]) +# (4, [ (ttl, ip4), ... ]) # (2, [ttl, dns_names]) : dns_names is one string that contains -# all the DNS names. Internally it is kept ready to be sent -# (undissected). i2repr() decode it for user. This is to +# all the DNS names. Internally it is kept ready to be sent +# (undissected). i2repr() decode it for user. This is to # make build after dissection bijective. # # I also merged getfield() and m2i(), and addfield() and i2m(). @@ -2223,7 +2223,7 @@ class NIReplyDataField(StrField): return val def h2i(self, pkt, x): - qtype = 0 # We will decode it as string if not + qtype = 0 # We will decode it as string if not # overridden through 'qtype' in pkt # No user hint, let's use 'qtype' value for that purpose @@ -2274,13 +2274,13 @@ class NIReplyDataField(StrField): return s + "".join(map(lambda (x,y): struct.pack("!I", x)+inet_pton(socket.AF_INET, y), tmp)) else: return s + tmp - + def getfield(self, pkt, s): code = getattr(pkt, "code") if code != 0: return s, (0, "") - qtype = getattr(pkt, "qtype") + qtype = getattr(pkt, "qtype") if qtype == 0: # NOOP return s, (0, "") @@ -2303,7 +2303,7 @@ class NIReplyDataField(StrField): elif qtype == 4: # IPv4 addresses with TTLs # XXX TODO : get the real length res = [] - while len(s) >= 8: # 4 + 4 + while len(s) >= 8: # 4 + 4 ttl = struct.unpack("!I", s[:4])[0] ip = inet_ntop(socket.AF_INET, s[4:8]) res.append((ttl, ip)) @@ -2316,7 +2316,7 @@ class NIReplyDataField(StrField): def i2repr(self, pkt, x): if x is None: return "[]" - + if type(x) is tuple and len(x) == 2: t, val = x if t == 2: # DNS names @@ -2328,27 +2328,27 @@ class NIReplyDataField(StrField): return repr(val) return repr(x) # XXX should not happen -# By default, sent responses have code set to 0 (successful) -class ICMPv6NIReplyNOOP(_ICMPv6NIAnswers, _ICMPv6NIHashret, _ICMPv6): +# By default, sent responses have code set to 0 (successful) +class ICMPv6NIReplyNOOP(_ICMPv6NIAnswers, _ICMPv6NIHashret, _ICMPv6): name = "ICMPv6 Node Information Reply - NOOP Reply" fields_desc = [ ByteEnumField("type", 140, icmp6types), ByteEnumField("code", 0, _nireply_code), XShortField("cksum", None), ShortEnumField("qtype", 0, icmp6_niqtypes), BitField("unused", 0, 10), - FlagsField("flags", 0, 6, "TACLSG"), + FlagsField("flags", 0, 6, "TACLSG"), NonceField("nonce", None), NIReplyDataField("data", None)] -class ICMPv6NIReplyName(ICMPv6NIReplyNOOP): +class ICMPv6NIReplyName(ICMPv6NIReplyNOOP): name = "ICMPv6 Node Information Reply - Node Names" qtype = 2 -class ICMPv6NIReplyIPv6(ICMPv6NIReplyNOOP): +class ICMPv6NIReplyIPv6(ICMPv6NIReplyNOOP): name = "ICMPv6 Node Information Reply - IPv6 addresses" qtype = 3 -class ICMPv6NIReplyIPv4(ICMPv6NIReplyNOOP): +class ICMPv6NIReplyIPv4(ICMPv6NIReplyNOOP): name = "ICMPv6 Node Information Reply - IPv4 addresses" qtype = 4 @@ -2405,7 +2405,7 @@ class ICMPv6HAADRequest(_ICMPv6): def hashret(self): return struct.pack("!H",self.id)+self.payload.hashret() -class ICMPv6HAADReply(_ICMPv6): +class ICMPv6HAADReply(_ICMPv6): name = 'ICMPv6 Home Agent Address Discovery Reply' fields_desc = [ ByteEnumField("type", 145, icmp6types), ByteField("code", 0), @@ -2420,9 +2420,9 @@ class ICMPv6HAADReply(_ICMPv6): def answers(self, other): if not isinstance(other, ICMPv6HAADRequest): return 0 - return self.id == other.id + return self.id == other.id -class ICMPv6MPSol(_ICMPv6): +class ICMPv6MPSol(_ICMPv6): name = 'ICMPv6 Mobile Prefix Solicitation' fields_desc = [ ByteEnumField("type", 146, icmp6types), ByteField("code", 0), @@ -2438,11 +2438,11 @@ class ICMPv6MPAdv(_ICMPv6NDGuessPayload, _ICMPv6): ByteField("code", 0), XShortField("cksum", None), XShortField("id", None), - BitEnumField("flags", 2, 2, {2: 'M', 1:'O'}), + BitEnumField("flags", 2, 2, {2: 'M', 1:'O'}), XBitField("res", 0, 14) ] def hashret(self): return struct.pack("!H",self.id) - + def answers(self, other): return isinstance(other, ICMPv6MPSol) @@ -2455,7 +2455,7 @@ _mobopttypes = { 2: "Binding Refresh Advice", 5: "Binding Authorization Data", 6: "Mobile Network Prefix (RFC3963)", 7: "Link-Layer Address (RFC4068)", - 8: "Mobile Node Identifier (RFC4283)", + 8: "Mobile Node Identifier (RFC4283)", 9: "Mobility Message Authentication (RFC4285)", 10: "Replay Protection (RFC4285)", 11: "CGA Parameters Request (RFC4866)", @@ -2466,11 +2466,11 @@ _mobopttypes = { 2: "Binding Refresh Advice", 16: "Care-of Test (RFC4866)" } -class _MIP6OptAlign: - """ Mobile IPv6 options have alignment requirements of the form x*n+y. - This class is inherited by all MIPv6 options to help in computing the - required Padding for that option, i.e. the need for a Pad1 or PadN - option before it. They only need to provide x and y as class +class _MIP6OptAlign: + """ Mobile IPv6 options have alignment requirements of the form x*n+y. + This class is inherited by all MIPv6 options to help in computing the + required Padding for that option, i.e. the need for a Pad1 or PadN + option before it. They only need to provide x and y as class parameters. (x=0 and y=0 are used when no alignment is required)""" def alignment_delta(self, curpos): x = self.x ; y = self.y @@ -2478,13 +2478,13 @@ class _MIP6OptAlign: return 0 delta = x*((curpos - y + x - 1)/x) + y - curpos return delta - + class MIP6OptBRAdvice(_MIP6OptAlign, Packet): - name = 'Mobile IPv6 Option - Binding Refresh Advice' + name = 'Mobile IPv6 Option - Binding Refresh Advice' fields_desc = [ ByteEnumField('otype', 2, _mobopttypes), ByteField('olen', 2), - ShortField('rinter', 0) ] + ShortField('rinter', 0) ] x = 2 ; y = 0# alignment requirement: 2n class MIP6OptAltCoA(_MIP6OptAlign, Packet): @@ -2494,7 +2494,7 @@ class MIP6OptAltCoA(_MIP6OptAlign, Packet): IP6Field("acoa", "::") ] x = 8 ; y = 6 # alignment requirement: 8n+6 -class MIP6OptNonceIndices(_MIP6OptAlign, Packet): +class MIP6OptNonceIndices(_MIP6OptAlign, Packet): name = 'MIPv6 Option - Nonce Indices' fields_desc = [ ByteEnumField('otype', 4, _mobopttypes), ByteField('olen', 16), @@ -2502,14 +2502,14 @@ class MIP6OptNonceIndices(_MIP6OptAlign, Packet): ShortField('coni', 0) ] x = 2 ; y = 0 # alignment requirement: 2n -class MIP6OptBindingAuthData(_MIP6OptAlign, Packet): +class MIP6OptBindingAuthData(_MIP6OptAlign, Packet): name = 'MIPv6 Option - Binding Authorization Data' fields_desc = [ ByteEnumField('otype', 5, _mobopttypes), ByteField('olen', 16), BitField('authenticator', 0, 96) ] x = 8 ; y = 2 # alignment requirement: 8n+2 -class MIP6OptMobNetPrefix(_MIP6OptAlign, Packet): # NEMO - RFC 3963 +class MIP6OptMobNetPrefix(_MIP6OptAlign, Packet): # NEMO - RFC 3963 name = 'NEMO Option - Mobile Network Prefix' fields_desc = [ ByteEnumField("otype", 6, _mobopttypes), ByteField("olen", 18), @@ -2537,8 +2537,8 @@ class MIP6OptMNID(_MIP6OptAlign, Packet): # RFC 4283 length_from = lambda pkt: pkt.olen-1) ] x = 0 ; y = 0 # alignment requirement: none -# We only support decoding and basic build. Automatic HMAC computation is -# too much work for our current needs. It is left to the user (I mean ... +# We only support decoding and basic build. Automatic HMAC computation is +# too much work for our current needs. It is left to the user (I mean ... # you). --arno class MIP6OptMsgAuth(_MIP6OptAlign, Packet): # RFC 4285 (Sect. 5) name = "MIPv6 Option - Mobility Message Authentication" @@ -2553,8 +2553,8 @@ class MIP6OptMsgAuth(_MIP6OptAlign, Packet): # RFC 4285 (Sect. 5) x = 4 ; y = 1 # alignment requirement: 4n+1 # Extracted from RFC 1305 (NTP) : -# NTP timestamps are represented as a 64-bit unsigned fixed-point number, -# in seconds relative to 0h on 1 January 1900. The integer part is in the +# NTP timestamps are represented as a 64-bit unsigned fixed-point number, +# in seconds relative to 0h on 1 January 1900. The integer part is in the # first 32 bits and the fraction part in the last 32 bits. class NTPTimestampField(LongField): epoch = (1900, 1, 1, 0, 0, 0, 5, 1, 0) @@ -2562,7 +2562,7 @@ class NTPTimestampField(LongField): if x < ((50*31536000)<<32): return "Some date a few decades ago (%d)" % x - # delta from epoch (= (1900, 1, 1, 0, 0, 0, 5, 1, 0)) to + # delta from epoch (= (1900, 1, 1, 0, 0, 0, 5, 1, 0)) to # January 1st 1970 : delta = -2209075761 i = int(x >> 32) @@ -2587,7 +2587,7 @@ class MIP6OptCGAParamsReq(_MIP6OptAlign, Packet): # RFC 4866 (Sect. 5.6) x = 0 ; y = 0 # alignment requirement: none # XXX TODO: deal with CGA param fragmentation and build of defragmented -# XXX version. Passing of a big CGAParam structure should be +# XXX version. Passing of a big CGAParam structure should be # XXX simplified. Make it hold packets, by the way --arno class MIP6OptCGAParams(_MIP6OptAlign, Packet): # RFC 4866 (Sect. 5.1) name = "MIPv6 option - CGA Parameters" @@ -2643,7 +2643,7 @@ moboptcls = { 0: Pad1, 5: MIP6OptBindingAuthData, 6: MIP6OptMobNetPrefix, 7: MIP6OptLLAddr, - 8: MIP6OptMNID, + 8: MIP6OptMNID, 9: MIP6OptMsgAuth, 10: MIP6OptReplayProtection, 11: MIP6OptCGAParamsReq, @@ -2668,7 +2668,7 @@ mhtypes = { 0: 'BRR', 9: 'Fast BA', 10: 'Fast NA' } -# From http://www.iana.org/assignments/mobility-parameters +# From http://www.iana.org/assignments/mobility-parameters bastatus = { 0: 'Binding Update accepted', 1: 'Accepted but prefix discovery necessary', 128: 'Reason unspecified', @@ -2725,14 +2725,14 @@ class MIP6MH_Generic(_MobilityHeader): # Mainly for decoding of unknown msg length_from = lambda pkt: 8*pkt.len-6) ] - + # TODO: make a generic _OptionsField class _MobilityOptionsField(PacketListField): __slots__ = ["curpos"] def __init__(self, name, default, cls, curpos, count_from=None, length_from=None): self.curpos = curpos PacketListField.__init__(self, name, default, cls, count_from=count_from, length_from=length_from) - + def getfield(self, pkt, s): l = self.length_from(pkt) return s[l:],self.m2i(pkt, s[:l]) @@ -2765,7 +2765,7 @@ class _MobilityOptionsField(PacketListField): autopad = getattr(pkt, "autopad") # Hack : 'autopad' phantom field except: autopad = 1 - + if not autopad: return "".join(map(str, x)) @@ -2781,7 +2781,7 @@ class _MobilityOptionsField(PacketListField): pstr = str(p) curpos += len(pstr) s += pstr - + # Let's make the class including our option field # a multiple of 8 octets long d = curpos % 8 @@ -2791,7 +2791,7 @@ class _MobilityOptionsField(PacketListField): if d == 1: s += str(Pad1()) elif d != 0: - s += str(PadN(optdata='\x00'*(d-2))) + s += str(PadN(optdata='\x00'*(d-2))) return s @@ -2802,15 +2802,15 @@ class MIP6MH_BRR(_MobilityHeader): name = "IPv6 Mobility Header - Binding Refresh Request" fields_desc = [ ByteEnumField("nh", 59, ipv6nh), ByteField("len", None), - ByteEnumField("mhtype", 0, mhtypes), + ByteEnumField("mhtype", 0, mhtypes), ByteField("res", None), XShortField("cksum", None), - ShortField("res2", None), + ShortField("res2", None), _PhantomAutoPadField("autopad", 1), # autopad activated by default _MobilityOptionsField("options", [], MIP6OptUnknown, 8, length_from = lambda pkt: 8*pkt.len) ] overload_fields = { IPv6: { "nh": 135 } } - def hashret(self): + def hashret(self): # Hack: BRR, BU and BA have the same hashret that returns the same # value "\x00\x08\x09" (concatenation of mhtypes). This is # because we need match BA with BU and BU with BRR. --arno @@ -2820,9 +2820,9 @@ class MIP6MH_HoTI(_MobilityHeader): name = "IPv6 Mobility Header - Home Test Init" fields_desc = [ ByteEnumField("nh", 59, ipv6nh), ByteField("len", None), - ByteEnumField("mhtype", 1, mhtypes), + ByteEnumField("mhtype", 1, mhtypes), ByteField("res", None), - XShortField("cksum", None), + XShortField("cksum", None), StrFixedLenField("reserved", "\x00"*2, 2), StrFixedLenField("cookie", "\x00"*8, 8), _PhantomAutoPadField("autopad", 1), # autopad activated by default @@ -2842,9 +2842,9 @@ class MIP6MH_HoT(_MobilityHeader): name = "IPv6 Mobility Header - Home Test" fields_desc = [ ByteEnumField("nh", 59, ipv6nh), ByteField("len", None), - ByteEnumField("mhtype", 3, mhtypes), + ByteEnumField("mhtype", 3, mhtypes), ByteField("res", None), - XShortField("cksum", None), + XShortField("cksum", None), ShortField("index", None), StrFixedLenField("cookie", "\x00"*8, 8), StrFixedLenField("token", "\x00"*8, 8), @@ -2895,7 +2895,7 @@ class MIP6MH_BU(_MobilityHeader): def hashret(self): # Hack: see comment in MIP6MH_BRR.hashret() return "\x00\x08\x09" - def answers(self, other): + def answers(self, other): if isinstance(other, MIP6MH_BRR): return 1 return 0 @@ -2967,7 +2967,7 @@ class AS_resolver6(AS_resolver_riswhois): def _resolve_one(self, ip): """ overloaded version to provide a Whois resolution on the - embedded IPv4 address if the address is 6to4 or Teredo. + embedded IPv4 address if the address is 6to4 or Teredo. Otherwise, the native IPv6 address is passed. """ @@ -2978,10 +2978,10 @@ class AS_resolver6(AS_resolver_riswhois): addr = teredoAddrExtractInfo(ip)[2] else: addr = ip - + _, asn, desc = AS_resolver_riswhois._resolve_one(self, addr) - return ip,asn,desc + return ip,asn,desc class TracerouteResult6(TracerouteResult): __slots__ = [] @@ -3002,8 +3002,8 @@ class TracerouteResult6(TracerouteResult): d = s[IPv6].dst if d not in trace: trace[d] = {} - - t = not (ICMPv6TimeExceeded in r or + + t = not (ICMPv6TimeExceeded in r or ICMPv6DestUnreach in r or ICMPv6PacketTooBig in r or ICMPv6ParamProblem in r) @@ -3023,8 +3023,8 @@ class TracerouteResult6(TracerouteResult): def graph(self, ASres=AS_resolver6(), **kargs): TracerouteResult.graph(self, ASres=ASres, **kargs) - -def traceroute6(target, dport=80, minttl=1, maxttl=30, sport=RandShort(), + +def traceroute6(target, dport=80, minttl=1, maxttl=30, sport=RandShort(), l4 = None, timeout=2, verbose=None, **kargs): """ Instant TCP traceroute using IPv6 : diff --git a/scapy/layers/ntp.py b/scapy/layers/ntp.py index 3a679d36..1d7bfd09 100644 --- a/scapy/layers/ntp.py +++ b/scapy/layers/ntp.py @@ -1786,7 +1786,7 @@ class NTPPrivate(NTP): # # Implementation number: The number of the implementation this request code # is defined by. An implementation number of zero is used - # for requst codes/data formats which all implementations + # for request codes/data formats which all implementations # agree on. Implementation number 255 is reserved (for # extensions, in case we run out). # diff --git a/scapy/layers/snmp.py b/scapy/layers/snmp.py index 37bcdfe1..e602e20b 100644 --- a/scapy/layers/snmp.py +++ b/scapy/layers/snmp.py @@ -130,7 +130,7 @@ SNMP_error = { 0: "no_error", 10: "wrong_value", 11: "no_creation", 12: "inconsistent_value", - 13: "ressource_unavailable", + 13: "resource_unavailable", 14: "commit_failed", 15: "undo_failed", 16: "authorization_error", diff --git a/scapy/layers/tls/tools.py b/scapy/layers/tls/tools.py index 921e669c..cdc5145e 100644 --- a/scapy/layers/tls/tools.py +++ b/scapy/layers/tls/tools.py @@ -169,7 +169,7 @@ def _tls_aead_auth_encrypt(alg, p, write_seq_num): for block and stream ciphers, for which the authentication step is done separately, AEAD alg does it simultaneously: this is the reason why write_seq_num is passed to the function, to be incorporated in - authenticated data. Note that it is the caller's responibility to increment + authenticated data. Note that it is the caller's responsibility to increment write_seq_num afterwards. """ P = str(p) diff --git a/scapy/packet.py b/scapy/packet.py index 04689acd..90f238ee 100644 --- a/scapy/packet.py +++ b/scapy/packet.py @@ -895,7 +895,7 @@ Creates an EPS file describing a packet. If filename is not provided a temporary def show(self, dump=False, indent=3, lvl="", label_lvl=""): """Prints or returns (when "dump" is true) a hierarchical view of the packet. "indent" gives the size of indentation for each layer.""" - return self._show_or_dump(dump, indent, lvl, label_lvl) + return self._show_or_dump(dump, indent, lvl, label_lvl) def show2(self, dump=False, indent=3, lvl="", label_lvl=""): """Prints or returns (when "dump" is true) a hierarchical view of an assembled version of the packet, so that automatic fields are calculated (checksums, etc.)""" diff --git a/scapy/route6.py b/scapy/route6.py index 58f64c2b..8a7cb1ad 100644 --- a/scapy/route6.py +++ b/scapy/route6.py @@ -41,15 +41,15 @@ class Route6: # TODO : At the moment, resync will drop existing Teredo routes # if any. Change that ... self.invalidate_cache() - self.routes = read_routes6() - if self.routes == []: - log_loading.info("No IPv6 support in kernel") - + self.routes = read_routes6() + if self.routes == []: + log_loading.info("No IPv6 support in kernel") + def __repr__(self): rtlst = [('Destination', 'Next Hop', "iface", "src candidates")] for net,msk,gw,iface,cset in self.routes: - rtlst.append(('%s/%i'% (net,msk), gw, (iface if isinstance(iface, basestring) else iface.name), ", ".join(cset))) + rtlst.append(('%s/%i'% (net,msk), gw, (iface if isinstance(iface, basestring) else iface.name), ", ".join(cset))) colwidth = map(lambda x: max(map(lambda y: len(y), x)), apply(zip, rtlst)) fmt = " ".join(map(lambda x: "%%-%ds"%x, colwidth)) @@ -59,7 +59,7 @@ class Route6: # Unlike Scapy's Route.make_route() function, we do not have 'host' and 'net' - # parameters. We only have a 'dst' parameter that accepts 'prefix' and + # parameters. We only have a 'dst' parameter that accepts 'prefix' and # 'prefix/prefixlen' values. # WARNING: Providing a specific device will at the moment not work correctly. def make_route(self, dst, gw=None, dev=None): @@ -75,13 +75,13 @@ class Route6: else: # TODO: do better than that # replace that unique address by the list of all addresses - lifaddr = in6_getifaddr() + lifaddr = in6_getifaddr() devaddrs = filter(lambda x: x[2] == dev, lifaddr) ifaddr = construct_source_candidate_set(prefix, plen, devaddrs, LOOPBACK_NAME) return (prefix, plen, gw, dev, ifaddr) - + def add(self, *args, **kargs): """Ex: add(dst="2001:db8:cafe:f000::/56") @@ -93,10 +93,10 @@ class Route6: def delt(self, dst, gw=None): - """ Ex: - delt(dst="::/0") - delt(dst="2001:db8:cafe:f000::/56") - delt(dst="2001:db8:cafe:f000::/56", gw="2001:db8:deca::1") + """ Ex: + delt(dst="::/0") + delt(dst="2001:db8:cafe:f000::/56") + delt(dst="2001:db8:cafe:f000::/56", gw="2001:db8:deca::1") """ tmp = dst+"/128" dst, plen = tmp.split('/')[:2] @@ -114,7 +114,7 @@ class Route6: i=self.routes.index(l[0]) self.invalidate_cache() del(self.routes[i]) - + def ifchange(self, iff, addr): the_addr, the_plen = (addr.split("/")+["128"])[:2] the_plen = int(the_plen) @@ -122,7 +122,7 @@ class Route6: naddr = inet_pton(socket.AF_INET6, the_addr) nmask = in6_cidr2mask(the_plen) the_net = inet_ntop(socket.AF_INET6, in6_and(nmask,naddr)) - + for i, route in enumerate(self.routes): net,plen,gw,iface,addr = route if iface != iff: @@ -147,8 +147,8 @@ class Route6: def ifadd(self, iff, addr): """ Add an interface 'iff' with provided address into routing table. - - Ex: ifadd('eth0', '2001:bd8:cafe:1::1/64') will add following entry into + + Ex: ifadd('eth0', '2001:bd8:cafe:1::1/64') will add following entry into Scapy6 internal routing table: Destination Next Hop iface Def src @ @@ -168,7 +168,7 @@ class Route6: def route(self, dst, dev=None): """ - Provide best route to IPv6 destination address, based on Scapy6 + Provide best route to IPv6 destination address, based on Scapy6 internal routing table content. When a set of address is passed (e.g. 2001:db8:cafe:*::1-5) an address @@ -183,14 +183,14 @@ class Route6: """ # Transform "2001:db8:cafe:*::1-5:0/120" to one IPv6 address of the set dst = dst.split("/")[0] - savedst = dst # In case following inet_pton() fails + savedst = dst # In case following inet_pton() fails dst = dst.replace("*","0") l = dst.find("-") while l >= 0: m = (dst[l:]+":").find(":") dst = dst[:l]+dst[l+m:] l = dst.find("-") - + try: inet_pton(socket.AF_INET6, dst) except socket.error: @@ -207,7 +207,7 @@ class Route6: pathes = [] # TODO : review all kinds of addresses (scope and *cast) to see - # if we are able to cope with everything possible. I'm convinced + # if we are able to cope with everything possible. I'm convinced # it's not the case. # -- arnaud for p, plen, gw, iface, cset in self.routes: @@ -217,7 +217,7 @@ class Route6: pathes.append((plen, (iface, cset, gw))) elif (in6_ismlladdr(dst) and in6_islladdr(p) and in6_islladdr(cset[0])): pathes.append((plen, (iface, cset, gw))) - + if not pathes: warning("No route found for IPv6 destination %s (no default route?)" % dst) return (LOOPBACK_NAME, "::", "::") # XXX Linux specific @@ -240,8 +240,8 @@ class Route6: return (LOOPBACK_NAME, "::", "::") # XXX Linux specific # Symptom : 2 routes with same weight (our weight is plen) - # Solution : - # - dst is unicast global. Check if it is 6to4 and we have a source + # Solution : + # - dst is unicast global. Check if it is 6to4 and we have a source # 6to4 address in those available # - dst is link local (unicast or multicast) and multiple output # interfaces are available. Take main one (conf.iface6) @@ -261,7 +261,7 @@ class Route6: if tmp: res = tmp - + # Fill the cache (including dev-specific request) k = dst if dev is not None: diff --git a/scapy/sendrecv.py b/scapy/sendrecv.py index e5eecbba..1271b130 100644 --- a/scapy/sendrecv.py +++ b/scapy/sendrecv.py @@ -570,7 +570,7 @@ sniff([count=0,] [prn=None,] [store=1,] [offline=None,] [lfilter=None,] + L2ListenSocket args) -> list of packets count: number of packets to capture. 0 means infinity - store: wether to store sniffed packets or discard them + store: whether to store sniffed packets or discard them prn: function to apply to each packet. If something is returned, it is displayed. Ex: ex: prn = lambda x: x.summary() @@ -667,7 +667,7 @@ bridge_and_sniff([count=0,] [prn=None,] [store=1,] [offline=None,] [lfilter=None,] + L2Socket args) -> list of packets count: number of packets to capture. 0 means infinity - store: wether to store sniffed packets or discard them + store: whether to store sniffed packets or discard them prn: function to apply to each packet. If something is returned, it is displayed. Ex: ex: prn = lambda x: x.summary() diff --git a/test/dnssecRR.uts b/test/dnssecRR.uts index 7414302b..b9c0ac89 100644 --- a/test/dnssecRR.uts +++ b/test/dnssecRR.uts @@ -1,4 +1,4 @@ -# DNSSEC Ressource Record unit tests +# DNSSEC Resource Record unit tests # # Type the following command to launch start the tests: # $ sudo bash test/run_tests -t test/dnssecRR.uts -F diff --git a/test/edns0.uts b/test/edns0.uts index 21a834c7..f9589adb 100644 --- a/test/edns0.uts +++ b/test/edns0.uts @@ -1,4 +1,4 @@ -# DNS OPT Ressource Record unit tests +# DNS OPT Resource Record unit tests # # Type the following command to launch start the tests: # $ sudo bash test/run_tests -t test/edns0.uts -F -- GitLab