1
2
3 """Point-to-Point Protocol."""
4 from __future__ import absolute_import
5
6 import struct
7
8 from . import dpkt
9
10
11
12
13 PPP_IP = 0x21
14 PPP_IP6 = 0x57
15
16
17 PFC_BIT = 0x01
18
19
20 -class PPP(dpkt.Packet):
21
22 """Point-to-Point Protocol.
23
24 TODO: Longer class information....
25
26 Attributes:
27 __hdr__: Header fields of PPP.
28 TODO.
29 """
30
31 __hdr__ = (
32 ('addr', 'B', 0xff),
33 ('cntrl', 'B', 3),
34 ('p', 'B', PPP_IP),
35 )
36 _protosw = {}
37
38 @classmethod
39 - def set_p(cls, p, pktclass):
41
42 @classmethod
45
59
67
70 g = globals()
71 for k, v in g.items():
72 if k.startswith('PPP_'):
73 name = k[4:]
74 modname = name.lower()
75 try:
76 mod = __import__(modname, g, level=1)
77 PPP.set_p(v, getattr(mod, name))
78 except (ImportError, AttributeError):
79 continue
80
86
89
90 s = b"\xff\x03\x21"
91 p = PPP(s)
92 assert p.p == 0x21
93
94 s = b"\xff\x03\x00\x21"
95 p = PPP(s)
96 assert p.p == 0x21
97
100 s = b"\xff\x03\x00"
101
102 import pytest
103 pytest.raises(dpkt.NeedData, PPP, s)
104
107 p = PPP()
108 assert p.pack_hdr() == b"\xff\x03\x21"
109
110 p.p = 0xc021
111 assert p.pack_hdr() == b"\xff\x03\xc0\x21"
112
113
114 if __name__ == '__main__':
115
116 test_ppp()
117