Skip to content

Instantly share code, notes, and snippets.

@friek
Created May 27, 2016 13:23
Show Gist options
  • Save friek/e445af69234b726e680115cdfe79467d to your computer and use it in GitHub Desktop.
Save friek/e445af69234b726e680115cdfe79467d to your computer and use it in GitHub Desktop.
Poor man's ipv6 address expansion
sub expandIpv6Addr
{
my $addr = shift;
my @parts = split(/:/, $addr);
my $numParts = scalar @parts;
my @res;
my $i = 0;
foreach my $addrPart (@parts)
{
if (length($addrPart) == 0)
{
for (my $j = 0; $j <= (8 - $numParts); $j++)
{
$res[$i] = sprintf("%04x", 0);
$i++;
}
}
else
{
$res[$i] = sprintf("%04x", hex($addrPart));
$i++;
}
}
return join(':', @res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment