Exemple #1
0
    name = "EIGRP"
    fields_desc = [ByteField("ver", 2),
                   ByteEnumField("opcode", 5, _EIGRP_OPCODES),
                   XShortField("chksum", None),
                   FlagsField("flags", 0, 32, _EIGRP_FLAGS),
                   IntField("seq", 0),
                   IntField("ack", 0),
                   IntField("asn", 100),
                   RepeatedTlvListField("tlvlist", [], _EIGRPGuessPayloadClass)
                   ]

    def post_build(self, p, pay):
        p += pay
        if self.chksum is None:
            c = checksum(p)
            p = p[:2] + chb((c >> 8) & 0xff) + chb(c & 0xff) + p[4:]
        return p

    def mysummary(self):
        summarystr = "EIGRP (AS=%EIGRP.asn% Opcode=%EIGRP.opcode%"
        if self.opcode == 5 and self.ack != 0:
            summarystr += " (ACK)"
        if self.flags != 0:
            summarystr += " Flags=%EIGRP.flags%"

        return self.sprintf(summarystr + ")")


bind_layers(IP, EIGRP, proto=88)
bind_layers(IPv6, EIGRP, nh=88)
Exemple #2
0
                  IGMPv3.is_valid_mcaddr(igmp.gaddr):
                ip.dst = igmp.gaddr

           # We do not need to fixup the ether layer, it is done by scapy
           #
           # if pkt.haslayer(Ether):
           #     eth = pkt.getlayer(Ether)
           #     ip_long = atol(ip.dst)
           #     ether.dst = '01:00:5e:%02x:%02x:%02x' % (
           #        (ip_long >> 16) & 0x7f, (ip_long >> 8) & 0xff,
           #        ip_long & 0xff )

        return pkt


bind_layers(IP,       IGMPv3,   frag=0, proto=2, ttl=1, tos=0xc0)
bind_layers(IGMPv3,   IGMPv3gr, frag=0, proto=2)
bind_layers(IGMPv3gr, IGMPv3gr, frag=0, proto=2)


if __name__ == "__main__":

    print "test float encoding"
    from math import log
    max_expected_error = 1.0 / (2<<3) # four bit precision
    p = IGMPv3()
    for v in range(0, 31745):
        c = p.encode_float(v)
        d = p.decode_float(c)
        rel_err = float(v-d)/v if v!=0 else 0.0
        assert rel_err <= max_expected_error
Exemple #3
0
    fields_desc = [
        ByteField("ver", 2),
        ByteEnumField("opcode", 5, _EIGRP_OPCODES),
        XShortField("chksum", None),
        FlagsField("flags", 0, 32, _EIGRP_FLAGS),
        IntField("seq", 0),
        IntField("ack", 0),
        IntField("asn", 100),
        PacketListField("tlvlist", [], _EIGRPGuessPayloadClass)
    ]

    def post_build(self, p, pay):
        p += pay
        if self.chksum is None:
            c = checksum(p)
            p = p[:2] + chb((c >> 8) & 0xff) + chb(c & 0xff) + p[4:]
        return p

    def mysummary(self):
        summarystr = "EIGRP (AS=%EIGRP.asn% Opcode=%EIGRP.opcode%"
        if self.opcode == 5 and self.ack != 0:
            summarystr += " (ACK)"
        if self.flags != 0:
            summarystr += " Flags=%EIGRP.flags%"

        return self.sprintf(summarystr + ")")


bind_layers(IP, EIGRP, proto=88)
bind_layers(IPv6, EIGRP, nh=88)
Exemple #4
0
                  IGMPv3.is_valid_mcaddr(igmp.gaddr):
                ip.dst = igmp.gaddr

        # We do not need to fixup the ether layer, it is done by scapy
        #
        # if pkt.haslayer(Ether):
        #     eth = pkt.getlayer(Ether)
        #     ip_long = atol(ip.dst)
        #     ether.dst = '01:00:5e:%02x:%02x:%02x' % (
        #        (ip_long >> 16) & 0x7f, (ip_long >> 8) & 0xff,
        #        ip_long & 0xff )

        return pkt


bind_layers(IP, IGMPv3, frag=0, proto=2, ttl=1, tos=0xc0)
bind_layers(IGMPv3, IGMPv3gr, frag=0, proto=2)
bind_layers(IGMPv3gr, IGMPv3gr, frag=0, proto=2)

if __name__ == "__main__":

    print "test float encoding"
    from math import log
    max_expected_error = 1.0 / (2 << 3)  # four bit precision
    p = IGMPv3()
    for v in range(0, 31745):
        c = p.encode_float(v)
        d = p.decode_float(c)
        rel_err = float(v - d) / v if v != 0 else 0.0
        assert rel_err <= max_expected_error