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

Source Code for Module dpkt.tns

 1  # $Id: tns.py 23 2006-11-08 15:45:33Z dugsong $ 
 2  # -*- coding: utf-8 -*- 
 3  """Transparent Network Substrate.""" 
 4  from __future__ import print_function 
 5  from __future__ import absolute_import 
 6   
 7  from . import dpkt 
 8   
 9   
10 -class TNS(dpkt.Packet):
11 """Transparent Network Substrate. 12 13 TODO: Longer class information.... 14 15 Attributes: 16 __hdr__: Header fields of TNS. 17 TODO. 18 """ 19 20 __hdr__ = ( 21 ('length', 'H', 0), 22 ('pktsum', 'H', 0), 23 ('type', 'B', 0), 24 ('rsvd', 'B', 0), 25 ('hdrsum', 'H', 0), 26 ('msg', '0s', ''), 27 ) 28
29 - def unpack(self, buf):
30 dpkt.Packet.unpack(self, buf) 31 n = self.length - self.__hdr_len__ 32 if n > len(self.data): 33 raise dpkt.NeedData('short message (missing %d bytes)' % 34 (n - len(self.data))) 35 self.msg = self.data[:n] 36 self.data = self.data[n:]
37 38
39 -def test_tns():
40 s = (b'\x00\x23\x00\x00\x01\x00\x00\x00\x01\x34\x01\x2c\x00\x00\x08\x00\x7f' 41 b'\xff\x4f\x98\x00\x00\x00\x01\x00\x01\x00\x22\x00\x00\x00\x00\x01\x01X') 42 t = TNS(s) 43 assert t.msg.startswith(b'\x01\x34') 44 45 # test a truncated packet 46 try: 47 t = TNS(s[:-10]) 48 except dpkt.NeedData: 49 pass
50 51 52 if __name__ == '__main__': 53 test_tns() 54 55 print('Tests Successful...') 56