ppp.py 800 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """Point-to-Point Protocol."""
  2. from pypacker import pypacker, triggerlist
  3. import logging
  4. import struct
  5. logger = logging.getLogger("pypacker")
  6. # http://www.iana.org/assignments/ppp-numbers
  7. PPP_IP = 0x21 # Internet Protocol
  8. PPP_IP6 = 0x57 # Internet Protocol v6
  9. # Protocol field compression
  10. PFC_BIT = 0x01
  11. class PPP(pypacker.Packet):
  12. __hdr__ = (
  13. ("p", None, triggerlist.TriggerList),
  14. )
  15. def _dissect(self, buf):
  16. offset = 1
  17. ppp_type = buf[0]
  18. if buf[0] & PFC_BIT == 0:
  19. ppp_type = struct.unpack(">H", buf[:2])[0]
  20. offset = 2
  21. self.p.append(buf[0:2])
  22. else:
  23. self.p.append(buf[0:1])
  24. self._init_handler(ppp_type, buf[offset:])
  25. return offset
  26. # load handler
  27. from pypacker.layer3 import ip, ip6
  28. pypacker.Packet.load_handler(PPP,
  29. {
  30. PPP_IP: ip.IP,
  31. PPP_IP6: ip6.IP6
  32. }
  33. )