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.
1234::5678:9876 is ambiguous. Is 9876 a port or part of the address?
The common explicit format is [1234::5678]:9876/