[Twisted-Python] Setting source address of outgoing datagrams

Itamar Turner-Trauring itamar at itamarst.org
Mon Oct 14 11:43:17 MDT 2013


On 10/12/2013 10:27 AM, Maciej Wasilak wrote:
>
> I deploy my protocol like that:
>
> reactor.listenUDP(5683, myapp.MyProtocol(), interface="::")
> reactor.run()
>
> The problem is:
> 1. My server receives a request from remote client (with destination 
> address being valid global IPv6 address)
> 2. The server sends a response, but uses different source address 
> (which is also valid and assigned to local wlan0 interface).
> 3. Remote host drops the response (destination address of the request 
> and source address of the response do not match).
>
> It is common for IPv6 interfaces to have multiple global IPv6 
> addresses - because of privacy reasons (both on Windows and Linux).
>
> My question is - can I read manually the destination address from the 
> incoming request datagram, and set it as a source address manually in 
> the outgoing response datagram?

If you pass a specific IP to the interface keyword argument instead of 
"::", the UDP port will bind to that specific IP and will only send 
datagrams on that IP. You can use netifaces package (e.g. find it on 
PyPI) to list all local IPs. So you could do the equivalent of "::" by 
binding multiple times, once for each IPv6 address.




More information about the Twisted-Python mailing list