From 1d70f7d6e2ed720e75d2d503c994348687e2ccb7 Mon Sep 17 00:00:00 2001 From: pi-rho Date: Fri, 8 Jun 2012 08:02:21 -0500 Subject: [PATCH] include an example implementation of netarch.ip, "start-here.py" --- extra/start-here.py | 84 +++++++++++++++++++++++++++++++++++++++++++++ setup.py | 3 ++ 2 files changed, 87 insertions(+) create mode 100644 extra/start-here.py diff --git a/extra/start-here.py b/extra/start-here.py new file mode 100644 index 0000000..03f5e5c --- /dev/null +++ b/extra/start-here.py @@ -0,0 +1,84 @@ +#!/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. self.parts[:-1] is highlighted when + printed iff the value == length(self.payload) + + self.payload - non-header packet data + + self.opcode - an integer that triggers additional parsing, or special + display + + ''' + self.parts = unpack(" 1: + s = None + reseq = ip.Dispatch(*sys.argv[1:]) + for h, d in reseq: + srv, first, chunk = d + if not s: + s = StinkyPinkySession(first) + s.handle(srv, first, chunk, reseq.last) diff --git a/setup.py b/setup.py index f03a9f5..d19d99f 100644 --- a/setup.py +++ b/setup.py @@ -18,4 +18,7 @@ setup( "Topic :: System :: Networking" ], packages=['netarch'], + data_files=[ + ('share/netarch/examples', ['extra/start-here.py']), + ] )