Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
41 lines (37 sloc) 1.28 KB
import dpkt
import tcp
import udp
class PacketDispatcher:
takes a series of dpkt.Packet's and calls callbacks based on their type
For each packet added, picks it apart into its transport-layer packet type
and adds it to an appropriate handler object. Automatically creates handler
objects for now.
* flowbuilder = tcp.FlowBuilder
* udp = udp.Processor
def __init__(self):
self.tcp = tcp.FlowBuilder()
self.udp = udp.Processor()
def add(self, ts, buf, eth):
ts = dpkt timestamp
buf = original packet data
eth = dpkt.ethernet.Ethernet, whether its real Ethernet or from SLL
#decide based on
# if it's IP...
if (isinstance(, dpkt.ip.IP) or
isinstance(, dpkt.ip6.IP6)):
ip =
# if it's TCP
if isinstance(, dpkt.tcp.TCP):
tcppkt = tcp.Packet(ts, buf, eth, ip,
# if it's UDP...
elif isinstance(, dpkt.udp.UDP):
def finish(self):
#This is a hack, until tcp.Flow no longer has to be `finish()`ed
Something went wrong with that request. Please try again.