[libdnet-devel] patch to libdnet to support select/poll on descriptors
Status: Abandoned
Brought to you by:
dugsong
|
From: Sam R. <sro...@un...> - 2007-09-21 21:02:51
|
Hi there.
libdnet is pretty handy (as is dpkt). Thanks a bunch.
We're using twisted, so need to drive raw packet sends from the select
loop. This requires the underlying fd. Attached is my patch, I think it
would be useful to others.
Btw, I had a lot of trouble building the python binding. Turns out my
linux distro (ubuntu) has both python 2.4 and python 2.5 installed. This
seemed to cause problems. I manually got a build by making sure
/usr/bin/python (2.5) and associated tools were always used. That was a
bit painful, so I just uninstalled python 2.4, and now can build using
./configure --with-python;make;make install. Anyhow, someone who
understands autoconf+python's setup.py better than I might be able to
make this work out-of-the-box.
Thanks,
Sam
Example usage:
--------------
from twisted.internet import reactor
from twisted.internet.interfaces import IWriteDescriptor
from zope.interface import implements
import dpkt
import dnet
class Me:
implements(IWriteDescriptor)
def logPrefix(self):
return "meLogPrefix"
def __init__(self):
pass
def start(self):
self.net = dnet.eth("eth0")
reactor.addWriter(self)
return self
def fileno(self):
return self.net.fileno()
def doWrite(self):
print "doWrite"
# Get next from g.
self.net.send(str(dpkt.ethernet.Ethernet()))
reactor.removeWriter(self)
reactor.stop()
def connectionLost(self, reason):
print "connectionLost:"+repr(reason)
reactor.stop()
me = Me().start()
reactor.run()
|