Re:Potholes to avoid when migrating to IPv6
by ggm on Monday December 31, 2018 @02:10AM
(#18793473)
I've taken to using python split(':')[:-1] and like constructs
[ Parent
| on HN ]
Re:Potholes to avoid when migrating to IPv6
by anderskaseorg on Monday December 31, 2018 @03:04AM
(#18793597)
See also rsplit(':', 1). But instead of either of those, you should really be using library functions that already understand the format in question instead of making up your own rules.
>>> u = urllib.parse.ParseResult('', '[2001:0db8:f00f::0553:1211:0088]:10443', '', '', '', '')
>>> u.hostname
'2001:0db8:f00f::0553:1211:0088'
>>> ipaddress.ip_address(u.hostname)
IPv6Address('2001:db8:f00f::553:1211:88')
>>> u.port
10443Urllib? There has to be a better choice than that. I've been using inet_ntop and pton to canonically convert bare IPs in to sane forms.
Re:Potholes to avoid when migrating to IPv6
by detaro on Monday December 31, 2018 @06:05AM
(#18794044)
What's the problem with urllib for this purpose?
Re:Potholes to avoid when migrating to IPv6
by Cpoll on Monday December 31, 2018 @03:11AM
(#18793615)
It'll fail you with port vs. no port.
1234::5678:9876 is ambiguous. Is 9876 a port or part of the address?
The common explicit format is [1234::5678]:9876/
If you don't know if it has a port or not in advance, how can you know the last :thing is not part of the IPv6 address deterministically? If you luck into a four digit port, and the address has :: maximal compression you're SOL.
I have exclusively done this :-1 knowing I had a port.
Not all sources (tcpdump) use your canonical form.
Re:Potholes to avoid when migrating to IPv6
by IgorPartola on Monday December 31, 2018 @06:23AM
(#18794075)
You should read TFA.
I did. It basically said to change your input stream to avoid the problem. Not all data sources can be changed. If you don't have canonically parsable inputs, then assumptions don't work and you can't predict if an add::d:ress is with or without the :port syntax, a priori unless you know the input stream.
Re:Potholes to avoid when migrating to IPv6
by IgorPartola on Tuesday January 01, 2019 @11:41AM
(#18800848)
So between your input and your parsing library you should put a bit of code to clean up the incoming data. Don’t create a library that processes incorrect data because at some point someone will absolutely try to use it to parse different input data and it will cause problems.