It seems like it would be simple to decrement an IPv6 Address so I can get the previous address in series but I can't seem to figure it out.
I've found a code example to increment an IPv6 Address (in-fact it works for IPv4 too) but decrementing? it doesn't work no matter how I modify it and I don't have enough understanding of IPv6 to work it out myself really.
Here is the example I found which works for incrementing:
// Takes an IPv4/IPv6 address in string format, and increments it by given
function incrementIp($ip, $increment)
{
$addr = inet_pton ( $ip );
for ( $i = strlen ( $addr ) - 1; $increment > 0 && $i >= 0; --$i )
{
$val = ord($addr[$i]) + $increment;
$increment = $val / 256;
$addr[$i] = chr($val % 256);
}
return inet_ntop ( $addr );
}
Any help is greatly appreciated :)