Пример #1
0
                      None,
                      length_of="CGA_PARAMS",
                      fmt="B",
                      adjust=lambda pkt, x:
                      (x + pkt.padlength + 4) // 8),  # noqa: E501
        FieldLenField("padlength", 0, length_of="padding", fmt="B"),
        ByteField("reserved", 0),
        PacketLenField("CGA_PARAMS",
                       "",
                       CGA_Params,
                       length_from=lambda pkt: pkt.len * 8 - pkt.padlength - 4
                       ),  # noqa: E501
        StrLenField("padding", "", length_from=lambda pkt: pkt.padlength)
    ]  # noqa: E501

    def post_build(self, p, pay):
        l_ = len(self.CGA_PARAMS)
        tmp_len = -(4 + l_) % 8  # Pad to 8 bytes
        p = p[:1] + chb((4 + l_ + tmp_len) // 8) + chb(tmp_len) + p[3:4 + l_]
        p += b"\x00" * tmp_len + pay
        return p


send_icmp6ndoptscls = {
    11: ICMPv6NDOptCGA,
    12: ICMPv6NDOptRsaSig,
    13: ICMPv6NDOptTmstp,
    14: ICMPv6NDOptNonce
}
icmp6ndoptscls.update(send_icmp6ndoptscls)
Пример #2
0
    name = "CGA Parameters data structure"
    fields_desc = [StrFixedLenField("modifier", RandBin(size=16), length=16),
                   StrFixedLenField("subprefix", "", length=8),
                   ByteField("cc", 0),
                   PacketField("pubkey", X509_SubjectPublicKeyInfo(),
                               X509_SubjectPublicKeyInfo)]


class ICMPv6NDOptCGA(_ICMPv6NDGuessPayload, Packet):
    name = "ICMPv6NDOptCGA"
    fields_desc = [ByteField("type", 11),
                   FieldLenField("len", None, length_of="CGA_PARAMS", fmt="B", adjust=lambda pkt, x: (x + pkt.padlength + 4) // 8),  # noqa: E501
                   FieldLenField("padlength", 0, length_of="padding", fmt="B"),
                   ByteField("reserved", 0),
                   PacketLenField("CGA_PARAMS", "", CGA_Params, length_from=lambda pkt: pkt.len * 8 - pkt.padlength - 4),  # noqa: E501
                   StrLenField("padding", "", length_from=lambda pkt: pkt.padlength)]  # noqa: E501

    def post_build(self, p, pay):
        l_ = len(self.CGA_PARAMS)
        l = -(4 + l_) % 8  # Pad to 8 bytes
        p = p[:1] + chb((4 + l_ + l) // 8) + chb(l) + p[3:4 + l_] + b"\x00" * l + pay  # noqa: E501
        return p


send_icmp6ndoptscls = {11: ICMPv6NDOptCGA,
                       12: ICMPv6NDOptRsaSig,
                       13: ICMPv6NDOptTmstp,
                       14: ICMPv6NDOptNonce
                       }
icmp6ndoptscls.update(send_icmp6ndoptscls)