Packet.handle now takes a chunk, chunk.display shows length in hex

This commit is contained in:
Neale Pickett 2008-06-18 21:36:43 -06:00
parent aa8810409a
commit 60291721c8
1 changed files with 18 additions and 17 deletions

27
ip.py
View File

@ -140,10 +140,11 @@ class Chunk:
def __repr__(self): def __repr__(self):
if self.first: if self.first:
return '<Chunk %s:%d -> %s:%d length %d>' % (self.first.src_addr, return '<Chunk %s:%d -> %s:%d length %d (0x%x)>' % (self.first.src_addr,
self.first.sport, self.first.sport,
self.first.dst_addr, self.first.dst_addr,
self.first.dport, self.first.dport,
len(self),
len(self)) len(self))
else: else:
return '<Chunk (no frames)>' return '<Chunk (no frames)>'
@ -359,8 +360,8 @@ class Packet(UserDict.DictMixin):
opcodes = {} opcodes = {}
def __init__(self, frame=None): def __init__(self, firstframe=None):
self.frame = frame self.firstframe = firstframe
self.opcode = None self.opcode = None
self.opcode_desc = None self.opcode_desc = None
self.parts = [] self.parts = []
@ -410,12 +411,12 @@ class Packet(UserDict.DictMixin):
print '%s %3s: %s' % (self.__class__.__name__, print '%s %3s: %s' % (self.__class__.__name__,
self.opcode, self.opcode,
self.opcode_desc) self.opcode_desc)
if self.frame: if self.firstframe:
print ' %s:%d -> %s:%d (%s)' % (self.frame.src_addr, print ' %s:%d -> %s:%d (%s)' % (self.firstframe.src_addr,
self.frame.sport, self.firstframe.sport,
self.frame.dst_addr, self.firstframe.dst_addr,
self.frame.dport, self.firstframe.dport,
time.ctime(self.frame.time)) time.ctime(self.firstframe.time))
if self.parts: if self.parts:
dl = len(self.parts[-1]) dl = len(self.parts[-1])
@ -467,16 +468,16 @@ class Session:
# Override this, duh # Override this, duh
Packet = Packet Packet = Packet
def handle(self, frame, data): def handle(self, chunk):
"""Handle a data burst. """Handle a data burst.
Pass in a representative frame--earlier is better--and a hunk of Pass in a chunk.
data--possibly a GapString.
""" """
data = chunk.gapstr()
while data: while data:
p = self.Packet(frame) p = self.Packet(chunk.first)
data = p.handle(data) data = p.handle(data)
self.process(p) self.process(p)