lab.nexedi.com will be down from Thursday, 20 March 2025, 07:30:00 UTC for a duration of approximately 2 hours

Commit 30c8e528 authored by Stefan Schantl's avatar Stefan Schantl Committed by Michael Tremer

perl: Add get_as_name()

This function can be use to give the numer of an Autonomous System and
get back the stored name from the used location database.
Signed-off-by: default avatarStefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent 084b5bf4
......@@ -229,6 +229,29 @@ get_continent_code(db, ccode)
OUTPUT:
RETVAL
SV*
get_as_name(db, as_number)
struct loc_database* db;
unsigned int as_number;
CODE:
RETVAL = &PL_sv_undef;
// Lookup AS.
struct loc_as *as;
int err = loc_database_get_as(db, &as, as_number);
if(!err) {
// Get the name of the given AS number.
const char* as_name = loc_as_get_name(as);
RETVAL = newSVpv(as_name, strlen(as_name));
loc_as_unref(as);
}
OUTPUT:
RETVAL
void
DESTROY(db)
struct loc_database* db;
......
......@@ -12,7 +12,7 @@ use warnings;
my $testdb = $ENV{'database'};
my $keyfile = $ENV{'keyfile'};
use Test::More tests => 8;
use Test::More tests => 9;
BEGIN { use_ok('Location') };
#########################
......@@ -57,5 +57,8 @@ if(defined($as_number)) { fail("Test 8 - Lookup Autonomous System Number for add
$as_number = &Location::lookup_asn($db, "a.b.c.d");
if(defined($as_number)) { fail("Test 9 - Lookup Autonomous System Number for invalid address.") }
my $as_name = &Location::get_as_name($db, "204867");
ok($as_name eq "Lightning Wire Labs GmbH", "Test 10 - Get name for AS204867.");
my @locations = &Location::database_countries($db);
ok(@locations != 0, "Test 10 - Get database countries.");
ok(@locations != 0, "Test 11 - Get database countries.");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment