Created
May 27, 2016 13:24
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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