How to get original destination address of UDP packages in twisted when using iptables REDIRECT

Viewed 497

I am writing a proxy program that on the client side is supposed to take packages destined to arbitrary hosts and ports from the local machine and forward them to a receiving server that will process them further. All relevant traffic is redirected to the clients listening port using iptables.

On the client side, I need to log the original destination address and port of all connections intercepted by this program. This is no problem with TCP using this code (snapshot):

    class MyProtocol(Protocol, object):
        def dataReceived(self, data):
            dst_info = self.transport.socket.getsockopt(socket.SOL_IP, 80, 16)
            dst_port = sint(dst_info[2:4])
            dst_addr = socket.inet_ntoa(dst_info[4:8])

This method does however not work with UDP and it seams I am not proficient enough to figure this out. Can someone point me to how to get the original destination address of UDP datagrams using twisted? Some pointers or even code snippets would be greatly appreciated.

0 Answers
Related