leth/PHP-IPAddress

IPv6 address compression not working as expected

robwdwd opened this issue · 1 comments

Using the following IPv6 address for example

2001:0504:0000:0001:0000:0003:1898:0001

When returning the string representation with it returns this as the compressed address.

2001:504::1:0:3:1898:1

But it should actually be this without compressing the first 0000 hextet in the example. You should only be compressing 2 or more 0000s in a row. Handling One 16-Bit 0 Field - RFC-5952

2001:504:0:1:0:3:1898:1

I believe inet_ntop will return compressed ipv6 address string :)

For example

$ip = IPAddress::factory('2001:0504:0000:0001:0000:0003:1898:0001');

// 2001:504::1:0:3:1898:1
(string) $ip

// 2001:504:0:1:0:3:1898:1
inet_ntop(inet_pton((string) $ip))

leth commented

Thanks for raising this!