llc.py 783 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. from pypacker import pypacker
  2. import struct
  3. LLC_TYPE_IP = 0x0800 # IPv4 protocol
  4. LLC_TYPE_ARP = 0x0806 # address resolution protocol
  5. LLC_TYPE_IP6 = 0x86DD # IPv6 protocol
  6. class LLC(pypacker.Packet):
  7. __hdr__ = (
  8. ("dsap", "B", 0),
  9. ("ssap", "B", 0),
  10. ("ctrl", "B", 0),
  11. ("snap", "5s", b"\x00" * 5),
  12. )
  13. def _dissect(self, buf):
  14. # dsap = struct.unpack("B", buf[0])[0]
  15. if buf[0] == 170: # = 0xAA
  16. # SNAP is following ctrl
  17. htype = struct.unpack("H", buf[5:7])[0]
  18. self._init_handler(htype, buf[8:])
  19. else:
  20. # deactivate SNAP
  21. self.snap = None
  22. return 8
  23. # load handler
  24. from pypacker.layer12 import arp
  25. from pypacker.layer3 import ip, ip6
  26. pypacker.Packet.load_handler(LLC,
  27. {
  28. LLC_TYPE_IP: ip.IP,
  29. LLC_TYPE_ARP: arp.ARP,
  30. LLC_TYPE_IP6: ip6.IP6,
  31. }
  32. )