ipaddr icon indicating copy to clipboard operation
ipaddr copied to clipboard

Make correct mask when converting IPv4 <=> IPv6

Open Tietew opened this issue 5 years ago • 3 comments

When converting IPv4 to/from IPv6, IPAddr#set generates incorrect mask value. This causes IPAddr#include? returns incorrect result.

ip4 = IPAddr.new('::ffff:127.0.0.1').native
p [ip4.to_s, ip4.prefix]
ip6 = IPAddr.new('127.0.0.1').ipv4_mapped
p [ip6.to_s, ip6.prefix]

Expected

["127.0.0.1", 32]
["::ffff:127.0.0.1", 128]

Actual

["127.0.0.1", -96]       # @mask_addr == 0xFFFFFFFFFFFFFFFF
["::ffff:127.0.0.1", 0]  # @mask_addr == 0x000000000000FFFF

Tietew avatar Jun 24 '19 08:06 Tietew

@Tietew can you rebase on master.

ioquatix avatar Jul 09 '19 11:07 ioquatix

@ioquatix done.

Tietew avatar Jul 10 '19 04:07 Tietew

Can you please squash typo fix.

ioquatix avatar Jul 10 '19 04:07 ioquatix