Discussion:
[Twisted-Python] IPv6 comparison handling
Maciej Wasilak
2016-04-24 19:21:41 UTC
Permalink
Hello,

In my UDP Twisted based library there is a problem with IPv6 addresses
representation. Addresses are compared as simple strings, and it
sometimes causes mismatches:

"fe80::aaaa:bbff:fecc:dddd" should be equal to
"fe80:0000:0000:0000:aaaa:bbff:fecc:dddd"

I've noticed that Python 3 has nice new module "ipaddress" exactly for
this kind of problems, and it has been backported to Python 2.7.
Before I add it as a new dependency I wanted to ask if maybe Twisted
has some other suggested solution for this problem?

Best Regards
Maciej Wasilak
Glyph
2016-04-25 02:39:01 UTC
Permalink
Post by Maciej Wasilak
Hello,
In my UDP Twisted based library there is a problem with IPv6 addresses
representation. Addresses are compared as simple strings, and it
"fe80::aaaa:bbff:fecc:dddd" should be equal to
"fe80:0000:0000:0000:aaaa:bbff:fecc:dddd"
I've noticed that Python 3 has nice new module "ipaddress" exactly for
this kind of problems, and it has been backported to Python 2.7.
Before I add it as a new dependency I wanted to ask if maybe Twisted
has some other suggested solution for this problem?
You should probably use ipaddress. Twisted's facilities in this area are somewhat primitive, and should be improved; particularly, you _should_ be able to do:

a = IPv6Address("UDP", "fe80::", 0)
b = IPv6Address("UDP", "fe80::00:00", 0)
a == b

but right now that doesn't work.

A patch that fixes it would be much appreciated though!

-glyph

Loading...