| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Copyright (C) 2020-2026 Free Software Foundation, Inc. |
| 4 |
# |
| 5 |
# This file is part of GNU Inetutils. |
| 6 |
# |
| 7 |
# GNU Inetutils is free software: you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation, either version 3 of the License, or (at |
| 10 |
# your option) any later version. |
| 11 |
# |
| 12 |
# GNU Inetutils is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
# General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with this program. If not, see `http://www.gnu.org/licenses/'. |
| 19 |
|
| 20 |
use strict; |
| 21 |
use warnings; |
| 22 |
|
| 23 |
# Accepted format of entry line: |
| 24 |
# |
| 25 |
# hex:hex::/num ripe # comments |
| 26 |
# hex:hex::/num whois.arin.net |
| 27 |
# |
| 28 |
# where HEX are hexadecimal numbers of at most four significant digits, |
| 29 |
# and NUM are decimal numbers in the range 1 to 32, inclusive. |
| 30 |
|
| 31 |
my $prefix = qr/^([[:xdigit:]]{1,4}:[[:xdigit:]]{1,4})::\/(\d+)\s+([\w\.]+)$/; |
| 32 |
|
| 33 |
while (<>) { |
| 34 |
# Sanitize input: strip comments after hash character, |
| 35 |
# discard leading and ending space, drop empty lines. |
| 36 |
chomp; |
| 37 |
|
| 38 |
s/^\s*(.*)\s*$/$1/; |
| 39 |
s/\s*#.*$//; |
| 40 |
|
| 41 |
next if /^$/; |
| 42 |
|
| 43 |
# Check for acceptable data format. |
| 44 |
die "Prefix is not parseable: \"$_\".\n" |
| 45 |
unless (/$prefix/); |
| 46 |
|
| 47 |
my ($i1, $i2) = (0, 0); |
| 48 |
|
| 49 |
($i1, $i2) = split /:/, $1; # Prefix components, two double-octets. |
| 50 |
|
| 51 |
my $masklen = $2; # Prefix length |
| 52 |
my $server = $3; # Delegation target |
| 53 |
|
| 54 |
die "Illegal prefix length: $masklen used in \"$1/$masklen\".\n" |
| 55 |
if $masklen == 0 or $masklen > 32; |
| 56 |
|
| 57 |
print "{ " . ((oct("0x" . $i1) << 16) + oct("0x" . $i2)) . "UL, " . |
| 58 |
(0xffffffff^(0xffffffff >> $masklen)) . "UL, \""; |
| 59 |
|
| 60 |
if ($server =~ /\./) { |
| 61 |
print "$server"; |
| 62 |
} else { |
| 63 |
print "whois.$server.net"; |
| 64 |
} |
| 65 |
|
| 66 |
print "\" },\n"; |
| 67 |
} |