linuxcc.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. """
  2. Linux cooked capture format
  3. """
  4. from pypacker import pypacker
  5. import logging
  6. import struct
  7. # avoid unneeded references for performance reasons
  8. pack = struct.pack
  9. unpack = struct.unpack
  10. logger = logging.getLogger("pypacker")
  11. # Ethernet payload types - http://standards.ieee.org/regauth/ethertype
  12. LCC_TYPE_PUP = 0x0200 # PUP protocol
  13. LCC_TYPE_IP = 0x0800 # IPv4 protocol
  14. LCC_TYPE_ARP = 0x0806 # address resolution protocol
  15. LCC_TYPE_WOL = 0x0842 # Wake on LAN
  16. LCC_TYPE_CDP = 0x2000 # Cisco Discovery Protocol
  17. LCC_TYPE_DTP = 0x2004 # Cisco Dynamic Trunking Protocol
  18. LCC_TYPE_REVARP = 0x8035 # reverse addr resolution protocol
  19. LCC_TYPE_ETHTALK = 0x809B # Apple Talk
  20. LCC_TYPE_AARP = 0x80F3 # Appletalk Address Resolution Protocol
  21. LCC_TYPE_8021Q = 0x8100 # IEEE 802.1Q VLAN tagging
  22. LCC_TYPE_IPX = 0x8137 # Internetwork Packet Exchange
  23. LCC_TYPE_NOV = 0x8138 # Novell
  24. LCC_TYPE_IP6 = 0x86DD # IPv6 protocol
  25. LCC_TYPE_MPLS_UCAST = 0x8847 # MPLS unicast
  26. LCC_TYPE_MPLS_MCAST = 0x8848 # MPLS multicast
  27. LCC_TYPE_PPOE_DISC = 0x8863 # PPPoE Discovery
  28. LCC_TYPE_PPOE_SESS = 0x8864 # PPPoE Session
  29. LCC_TYPE_JUMBOF = 0x8870 # Jumbo Frames
  30. LCC_TYPE_PROFINET = 0x8892 # Realtime-Ethernet PROFINET
  31. LCC_TYPE_ATAOE = 0x88A2 # ATA other Ethernet
  32. LCC_TYPE_ETHERCAT = 0x88A4 # Realtime-Ethernet Ethercat
  33. LCC_TYPE_PBRIDGE = 0x88A8 # Provider Briding
  34. LCC_TYPE_POWERLINK = 0x88AB # Realtime Ethernet POWERLINK
  35. LCC_TYPE_LLDP = 0x88CC # Link Layer Discovery Protocol
  36. LCC_TYPE_SERCOS = 0x88CD # Realtime Ethernet SERCOS III
  37. LCC_TYPE_FIBRE_ETH = 0x8906 # Fibre Channel over Ethernet
  38. LCC_TYPE_FCOE = 0x8914 # FCoE Initialization Protocol (FIP)
  39. PACKET_DIR_TO_US = 0
  40. PACKET_DIR_FROM_US = 4
  41. class LinuxCC(pypacker.Packet):
  42. __hdr__ = (
  43. ("dir", "H", 4),
  44. ("addrtype", "H", 0),
  45. ("addrlen", "H", 0),
  46. ("info", "Q", 0), # TODO: Q available?
  47. ("type", "H", LCC_TYPE_IP)
  48. )
  49. def _dissect(self, buf):
  50. htype = unpack(">H", buf[14: 16])[0]
  51. # logger.debug("type: %X" % type)
  52. self._init_handler(htype, buf[16:])
  53. return 16
  54. # load handler
  55. from pypacker.layer12 import arp, dtp, pppoe
  56. from pypacker.layer3 import ip, ip6, ipx
  57. pypacker.Packet.load_handler(LinuxCC,
  58. {
  59. LCC_TYPE_IP: ip.IP,
  60. LCC_TYPE_ARP: arp.ARP,
  61. LCC_TYPE_DTP: dtp.DTP,
  62. LCC_TYPE_IPX: ipx.IPX,
  63. LCC_TYPE_IP6: ip6.IP6,
  64. LCC_TYPE_PPOE_DISC: pppoe.PPPoE,
  65. LCC_TYPE_PPOE_SESS: pppoe.PPPoE
  66. }
  67. )