53 lines
1.0 KiB
Python
Executable File
53 lines
1.0 KiB
Python
Executable File
#!/usr/bin/python
|
|
|
|
__author__ = "Daniel Egger"
|
|
__date__ = "22 March 2002"
|
|
__email__ = "egger@interearth.com"
|
|
__version__ = "$Revision: 1.1 $"[11:-2]
|
|
|
|
from tpdu import TPDU_CC, TPDU_CR, TPDU_DT
|
|
|
|
__all__ = ["decode_packet"]
|
|
|
|
|
|
def decode_cc (data):
|
|
from cc_tpdu import fromstring
|
|
return fromstring (data)
|
|
|
|
|
|
def decode_cr (data):
|
|
from cr_tpdu import fromstring
|
|
return fromstring (data)
|
|
|
|
|
|
def decode_dt (data):
|
|
from dt_tpdu import fromstring
|
|
return fromstring (data)
|
|
|
|
decoderlist = [
|
|
(TPDU_CC, decode_cc),
|
|
(TPDU_CR, decode_cr),
|
|
(TPDU_DT, decode_dt)
|
|
]
|
|
|
|
|
|
def decodepacket (data):
|
|
if not ord (data[0]) == 0x03:
|
|
print ("No valid tpkt header")
|
|
return
|
|
size = (ord (data[2]) << 8) | ord (data[3])
|
|
#print "TPKT size %d" % size
|
|
|
|
if len (data) < size:
|
|
print ("Packet too short! Is %d" % len (data))
|
|
return
|
|
|
|
type = (ord (data[5]) >> 4)
|
|
for i in decoderlist:
|
|
id, function = i
|
|
if id == type:
|
|
return function (data[4:size])
|
|
|
|
print "Undhandled packettype"
|
|
#raise Warning, "Undhandled packettype"
|