IPv6 address inconsistency (downcase vs. upcase)
I've noticed that sometimes ip addresses re shown using a-f characters in downcase, other times upcase. Here is a small script to show results:
require "resolv" require "socket" puts TCPSocket.getaddress("nghttp2.org") #=> "2400:8902::f03c:91ff:fe69:a454" puts Resolv.getaddresses("nghttp2.org") #=> ["188.8.131.52", "2400:8902::F03C:91FF:FE69:A454"]
Results might be system-dependent (I'm using Mac OS High Sierra).
This makes compare operations a bit harder.
Updated by hugopeixoto (Hugo Peixoto) about 1 year ago
shevegen (Robert A. Heiler) wrote:
Is there a standard that mandates or prefers either variant?
RFC 5952 recommends the usage of lower case letters: https://tools.ietf.org/html/rfc5952#section-4.3
Resolv module seems to be formatting the addresses in uppercase:
Resolv::IPv6.create("2400:8902::f03c:91ff:fe69:a454").to_s #=> "2400:8902::F03C:91FF:FE69:A454"
After the patch,
Resolv#getaddresses now formats addresses in lowercase:
Resolv.getaddresses("nghttp2.org") #=> ["184.108.40.206", "2400:8902::f03c:91ff:fe69:a454"]
I noticed there's an
ipaddr module that handles formatting as well, so in the attached patch I am using
IPAddr#new to reuse the existing code. I also added some tests.
I am not sure if adding the dependency here is the right way to do it.