#!/usr/bin/python '''Example use of the netarch.ip framework Searching and replacing "StinkyPinky" with your protocol's name would be a good start. ''' import sys from netarch import ip from netarch import unpack class StinkyPinkyPacket(ip.Packet): ''' StinkyPinky Protocol ''' def parse(self, data): '''Parse Packet Data This method deals with data on a packet level. Its job in life is to set parts, payload, and opcode. If any data is passed to this method is deemed to not be part of the packet's data, it should be returned. Likewise, if the Packet needs more data, raise ip.NeedsMoreData self.parts - a magic bag of values; (!) when the value matches len(self.payload) self.payload - non-header packet data self.opcode - an integer that triggers additional parsing self.text - text to be displayed without prep (i.e. shell output) self.html - html information for logging return: If you need more data, raise ip.NeedMoreData() If you have excess data, return it from this function ''' self.parts = unpack(" 1: sessions = {} dp = ip.Dispatch(*sys.argv[1:]) for fhash, chunk in dp: is_srv, frame, gs = chunk if not frame: continue if fhash not in sessions: sessions[fhash] = StinkyPinkySession(frame) sessions[fhash].handle(is_srv, frame, gs, dp.last) for sess in sessions.itervalues(): sess.done()