Filip Varga | eb60124 | 2018-10-31 07:58:05 +0100 | [diff] [blame] | 1 | diff --git a/scapy/contrib/cdp.py b/scapy/contrib/cdp.py |
| 2 | index c8b7f106..7b1ff64d 100644 |
| 3 | --- a/scapy/contrib/cdp.py |
| 4 | +++ b/scapy/contrib/cdp.py |
| 5 | @@ -102,7 +102,8 @@ def _CDPGuessPayloadClass(p, **kargs): |
| 6 | class CDPMsgGeneric(Packet): |
| 7 | name = "CDP Generic Message" |
| 8 | fields_desc = [ XShortEnumField("type", None, _cdp_tlv_types), |
| 9 | - FieldLenField("len", None, "val", "!H"), |
| 10 | + FieldLenField("len", None, "val", "!H", |
| 11 | + adjust=lambda pkt, x: x + 4), |
| 12 | StrLenField("val", "", length_from=lambda x:x.len - 4) ] |
| 13 | |
| 14 | |
Ole Troan | 2a884db | 2019-10-23 11:24:23 +0200 | [diff] [blame] | 15 | @@ -178,5 +179,6 @@ class CDPMsgAddr(CDPMsgGeneric): |
Filip Varga | eb60124 | 2018-10-31 07:58:05 +0100 | [diff] [blame] | 16 | class CDPMsgPortID(CDPMsgGeneric): |
| 17 | name = "Port ID" |
| 18 | fields_desc = [ XShortEnumField("type", 0x0003, _cdp_tlv_types), |
| 19 | - FieldLenField("len", None, "iface", "!H"), |
| 20 | + FieldLenField("len", None, "iface", "!H", |
| 21 | + adjust=lambda pkt, x: x + 4), |
| 22 | StrLenField("iface", "Port 1", length_from=lambda x:x.len - 4) ] |
Ole Troan | 2a884db | 2019-10-23 11:24:23 +0200 | [diff] [blame] | 23 | @@ -319,7 +319,7 @@ class _CDPChecksum: |
| 24 | This padding is only used for checksum computation. The original |
| 25 | packet should not be altered.""" |
| 26 | if len(pkt) % 2: |
| 27 | - last_chr = pkt[-1] |
| 28 | + last_chr = pkt[len(pkt)-1:] |
| 29 | if last_chr <= b'\x80': |
| 30 | return pkt[:-1] + b'\x00' + last_chr |
| 31 | else: |