From 680107d30f3b40ef6df36806dc130a11079d170a Mon Sep 17 00:00:00 2001 From: itform-fr <131718750+itform-fr@users.noreply.github.com> Date: Sat, 23 Nov 2024 12:33:18 +0100 Subject: [PATCH] Improve CDPMsgIPPrefix : allow more than one IP address (#4585) * Update cdp.py for CDPIPPrefix if the length of IP addresses prefixes was more than one address all the following content wasn't interpreted (Raw payload). This seams to fix it * Update cdp.py A better approach with a list rather than packets * Update cdp.py case error on Prefix * Fix PEP8 formatting * Rename IPPrefix -> CDPPrefix --------- Co-authored-by: gpotter2 <10530980+gpotter2@users.noreply.github.com> --- scapy/contrib/cdp.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scapy/contrib/cdp.py b/scapy/contrib/cdp.py index a1532b78783..030b3b0772d 100644 --- a/scapy/contrib/cdp.py +++ b/scapy/contrib/cdp.py @@ -250,13 +250,23 @@ class CDPMsgIPGateway(CDPMsgGeneric): IPField("defaultgw", "192.168.0.1")] +class CDPIPPrefix(Packet): + fields_desc = [ + IPField("prefix", "192.168.0.1"), + ByteField("plen", 24), + ] + + def guess_payload_class(self, p): + return conf.padding_layer + + class CDPMsgIPPrefix(CDPMsgGeneric): name = "IP Prefix" type = 0x0007 fields_desc = [XShortEnumField("type", 0x0007, _cdp_tlv_types), ShortField("len", 9), - IPField("prefix", "192.168.0.1"), - ByteField("plen", 24)] + PacketListField("prefixes", [], CDPIPPrefix, + length_from=lambda p: p.len - 4)] class CDPMsgProtoHello(CDPMsgGeneric):