Package dpkt :: Module sll
[hide private]
[frames] | no frames]

Source Code for Module dpkt.sll

 1  # $Id: sll.py 23 2006-11-08 15:45:33Z dugsong $ 
 2  # -*- coding: utf-8 -*- 
 3  """Linux libpcap "cooked" capture encapsulation.""" 
 4  from __future__ import absolute_import 
 5   
 6  from . import arp 
 7  from . import dpkt 
 8  from . import ethernet 
 9   
10   
11 -class SLL(dpkt.Packet):
12 """Linux libpcap "cooked" capture encapsulation. 13 14 TODO: Longer class information.... 15 16 Attributes: 17 __hdr__: Header fields of SLL. 18 TODO. 19 """ 20 21 __hdr__ = ( 22 ('type', 'H', 0), # 0: to us, 1: bcast, 2: mcast, 3: other, 4: from us 23 ('hrd', 'H', arp.ARP_HRD_ETH), 24 ('hlen', 'H', 6), # hardware address length 25 ('hdr', '8s', ''), # first 8 bytes of link-layer header 26 ('ethtype', 'H', ethernet.ETH_TYPE_IP), 27 ) 28 _typesw = ethernet.Ethernet._typesw 29
30 - def unpack(self, buf):
31 dpkt.Packet.unpack(self, buf) 32 try: 33 self.data = self._typesw[self.ethtype](self.data) 34 setattr(self, self.data.__class__.__name__.lower(), self.data) 35 except (KeyError, dpkt.UnpackError): 36 pass
37
38 -def test_sll():
39 slldata = b'\x00\x00\x00\x01\x00\x06\x00\x0b\xdb\x52\x0e\x08\xf6\x7f\x08\x00\x45\x00\x00\x34\xcc\x6c\x40\x00\x40\x06\x74\x08\x82\xd9\xfa\x8e\x82\xd9\xfa\x0d' 40 slltest = SLL(slldata) 41 assert slltest.type == 0 42 assert slltest.hrd == 1 43 assert slltest.hlen == 6 44 assert slltest.hdr == b'\x00\x0b\xdb\x52\x0e\x08\xf6\x7f' 45 assert slltest.ethtype == 0x0800 46 47 # give invalid ethtype of 0x1234 to make sure error is caught 48 slldata2 = b'\x00\x00\x00\x01\x00\x06\x00\x0b\xdb\x52\x0e\x08\xf6\x7f\x12\x34\x45\x00\x00\x34\xcc\x6c\x40\x00\x40\x06\x74\x08\x82\xd9\xfa\x8e\x82\xd9\xfa\x0d' 49 slltest = SLL(slldata2)
50