| # NOTE: This patch copied from https://github.com/secdev/scapy |
| # commit 3e6900776698cd5472c5405294414d5b672a3f18 |
| # |
| diff --git a/scapy/layers/ppp.py b/scapy/layers/ppp.py |
| index b5cd42b4..e0f4c593 100644 |
| --- a/scapy/layers/ppp.py |
| +++ b/scapy/layers/ppp.py |
| @@ -292,6 +292,14 @@ class _PPPProtoField(EnumField): |
| |
| See RFC 1661 section 2 |
| <https://tools.ietf.org/html/rfc1661#section-2> |
| + |
| + The generated proto field is two bytes when not specified, or when specified |
| + as an integer or a string: |
| + PPP() |
| + PPP(proto=0x21) |
| + PPP(proto="Internet Protocol version 4") |
| + To explicitly forge a one byte proto field, use the bytes representation: |
| + PPP(proto=b'\x21') |
| """ |
| def getfield(self, pkt, s): |
| if ord(s[:1]) & 0x01: |
| @@ -304,12 +312,18 @@ class _PPPProtoField(EnumField): |
| return super(_PPPProtoField, self).getfield(pkt, s) |
| |
| def addfield(self, pkt, s, val): |
| - if val < 0x100: |
| - self.fmt = "!B" |
| - self.sz = 1 |
| + if isinstance(val, bytes): |
| + if len(val) == 1: |
| + fmt, sz = "!B", 1 |
| + elif len(val) == 2: |
| + fmt, sz = "!H", 2 |
| + else: |
| + raise TypeError('Invalid length for PPP proto') |
| + val = struct.Struct(fmt).unpack(val)[0] |
| else: |
| - self.fmt = "!H" |
| - self.sz = 2 |
| + fmt, sz = "!H", 2 |
| + self.fmt = fmt |
| + self.sz = sz |
| self.struct = struct.Struct(self.fmt) |
| return super(_PPPProtoField, self).addfield(pkt, s, val) |