mwasilak / txThings

CoAP library for Twisted
94 stars 43 forks source link

IPv6 addresses not treated as equal if not in canonical representation #10

Closed adrian-nicolau closed 8 years ago

adrian-nicolau commented 8 years ago

Suppose we try to send a request to fd55:976b:4680:0000:0000:00ff:fe00:0400, which is not a canonical representation (RFC 5952), yet a valid IPv6 address. The response is not recognized because the address is in canonical form (fd55:976b:4680::ff:fe00:400). Even though fd55:976b:4680:0000:0000:00ff:fe00:0400 and fd55:976b:4680::ff:fe00:400 are not equal as strings, they are the same IPv6 address.

Snippet:

2016-04-14 14:23:12+0300 [-] Sending request - Token: 0000cea2, Host: fd55:976b:4680:0000:0000:00ff:fe00:0400, Port: 19789 [...] 2016-04-14 14:23:12+0300 [Coap (UDP)] Received Response, token: 0000cea2, host: fd55:976b:4680::ff:fe00:400, port: 19789 2016-04-14 14:23:12+0300 [Coap (UDP)] Response not recognized - sending RST.

mwasilak commented 8 years ago

IP addresses are currently compared as strings. It seems that proper approach is to use a module for IP address operations. Python 3 contains ipaddress module in its standard library. It has been backported to Python 2.7.

https://pypi.python.org/pypi/py2-ipaddress

I asked Twisted devs if there is some other suggested solution.

mwasilak commented 8 years ago

Fix added - version 0.2.0 . New dependency: py2-ipaddress