[Twisted-Python] New user, help needed with raw UDP packets

Jp Calderone exarkun at divmod.com
Wed Apr 14 22:37:41 EDT 2004

Richard Taylor wrote:

>Hash: SHA1
>I am a completely new user of Twisted. I have read the tutorial and much o=
f =

>the manual and I have been searching the archives but I can't work out how=
 to =

>get started with my problem.
>I am writing a UDP proxy/relay that needs to make detailed changes to the =

>internals of the UDP packets as they pass through. I intend to use 'Impack=
et' =

>to access the packet internals. One of the things that I need is to 'fake' =

>the destination address of packets leaving the proxy so that they look lik=
e =

>they have come from the original sender, Impacket has methods to do this f=
or =

>'raw' udp packets.
>I think that I need to use a sub-class of ConnectedDatagramProtocol to sen=
d my =

>packets but the "self.transport.write" method takes only the packet payloa=
d =

>not the headers.
>  =

  You will need to create a new kind of transport for this to work.  I'm =

afraid you haven't picked a very easy task for which to start using =

Twisted :)

>I think that I need to use a sub-class of DatagramProtocol to receive my =

>packets but the datagramReceived method only gets the packet payload not t=
he =

>headers. =

>  =

  More likely you'll want either a RawUDPProtocol subclass, or something =

very much like one.  You'll also need to create a new transport class =

which works on raw sockets.  There isn't really any documentation for =

this, as it is something that needs to be done very infrequently.  There =

is one example of creating a new transport type in my sandbox:



It is for TCP/IPv6 only, but should mostly be applicable to your case.

>How can I get at the 'raw' udp packets for receiving and sending?
>Sorry if this is obvious.
>  =

  Certainly not.  :)  If you get it working (documented, tested,etc ;), =

it might be nice if you could contribute it back, since raw socket =

support is something that does get asked for every once in a while.  =

It'd be nice to be able to tell someone how to use existing support, =

instead of telling them they have to implement it.


More information about the Twisted-Python mailing list