From 30c8e5289adce18327d6d41a27d7fc6eadd74705 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Sat, 22 Aug 2020 16:02:31 +0200 Subject: [PATCH] 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: Stefan Schantl Signed-off-by: Michael Tremer --- src/perl/Location.xs | 23 +++++++++++++++++++++++ src/perl/t/Location.t | 7 +++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/perl/Location.xs b/src/perl/Location.xs index 3c347db..7afa3e7 100644 --- a/src/perl/Location.xs +++ b/src/perl/Location.xs @@ -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; diff --git a/src/perl/t/Location.t b/src/perl/t/Location.t index ec7f1e0..0d9a1a5 100644 --- a/src/perl/t/Location.t +++ b/src/perl/t/Location.t @@ -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."); -- 2.39.2