Skip to content

Instantly share code, notes, and snippets.

@friek
Created May 27, 2016 13:24
Show Gist options
  • Save friek/4c7805702bc7df5e5d4653802e9f841f to your computer and use it in GitHub Desktop.
Save friek/4c7805702bc7df5e5d4653802e9f841f to your computer and use it in GitHub Desktop.
Convert a non-compressed IPv6 address to an octal string (for use in djbdns' data format)
sub ipv6OctString
{
my $v6Addr = shift;
my $res = '';
foreach $_ (split(/:/, $v6Addr))
{
if (/^([0-9a-f]{2})([0-9a-f]{2})$/)
{
$res .= sprintf("\\%03o\\%03o", hex($1), hex($2));
}
}
return $res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment