Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > media > main-release > by-pkgid > db93d7191b12a3d5ce887da46fc79bf1 > files > 48

python-twisted-core-doc-2.5.0-3mdv2008.1.x86_64.rpm

from twisted.internet import reactor, protocol
from twisted.pair import ethernet, rawudp, ip
from twisted.pair import tuntap

class MyProto(protocol.DatagramProtocol):
    def datagramReceived(self, *a, **kw):
        print a, kw

p_udp = rawudp.RawUDPProtocol()
p_udp.addProto(42, MyProto())
p_ip = ip.IPProtocol()
p_ip.addProto(17, p_udp)
p_eth = ethernet.EthernetProtocol()
p_eth.addProto(0x800, p_ip)

reactor.listenWith(tuntap.TuntapPort,
                   interface='tap0', proto=p_eth, reactor=reactor)
reactor.run()