Bug #14612


IPv6 address inconsistency (downcase vs. upcase)

Added by chucke (Tiago Cardoso) over 6 years ago. Updated almost 5 years ago.

Target version:


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("") #=> "2400:8902::f03c:91ff:fe69:a454"
puts Resolv.getaddresses("") #=> ["", "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.


resolv-ipv6-to_s.patch (1.48 KB) resolv-ipv6-to_s.patch hugopeixoto (Hugo Peixoto), 03/21/2018 02:27 PM
resolv-ipv6-lowercase.patch (1.82 KB) resolv-ipv6-lowercase.patch jeremyevans0 (Jeremy Evans), 06/20/2019 05:55 PM

Updated by shevegen (Robert A. Heiler) over 6 years ago

Is there a standard that mandates or prefers either variant?

If not then perhaps ruby should decide on which variant to

Updated by hugopeixoto (Hugo Peixoto) about 6 years 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:

The 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("") #=> ["", "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.

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

I agree that Ruby should consistently use lowercase for IPv6 addresses. However, I don't think we should introduce a dependency on ipaddr to resolv. For one, it changes how the IPv6 addresses with noncontiguous 0 components are displayed. Attached a simpler patch that just uses %x instead of %X in sprintf.

Actions #4

Updated by akr (Akira Tanaka) almost 5 years ago

  • Status changed from Assigned to Closed

Applied in changeset git|1da3a31a5f0211db121e0df4ca456838a437537f.

Use lowercase letters for IPv6 addresses.

Reported by chucke (Tiago Cardoso).
Patch by jeremyevans0 (Jeremy Evans).
[Bug #14612]


Also available in: Atom PDF