From patchwork Sat Aug 22 14:02:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3391 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4BYg7l2ZzNz3x16 for ; Sat, 22 Aug 2020 14:02:43 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4BYg7l0M3bzsB; Sat, 22 Aug 2020 14:02:42 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4BYg7k5Xfnz2xxt; Sat, 22 Aug 2020 14:02:42 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4BYg7k16Jnz2xms; Sat, 22 Aug 2020 14:02:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 4BYg7j0bvPzk9; Sat, 22 Aug 2020 14:02:41 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1598104961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=bx4OL9NAThpKPIXkLpBDKIskY/b/IixxWhVMduSmKfc=; b=EQqaj+3ZKYKY7JjDq59843uKHdsNLqaB4AhmtJGtn1tA3QLOpvOcmdiwzzVglHHPDpVTbn zC1QGGqKmBL3jzAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1598104961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=bx4OL9NAThpKPIXkLpBDKIskY/b/IixxWhVMduSmKfc=; b=u6+vXmj9Z5e8Ui0rap720506bDuTQfw1xXcmmbi8URJIwloRsi2zdueXgp7bA4hYcE2LlP DoLG9h4FwTQRFPBGDb3XUhxE7I6NvJFc2EddO7WQMEs8LwffO7AQ7i9ksvTs9sQduLHpjZ ceeggSwyUtctbvjUuaXVaoNJrHD1DorLQOeABpQ9BNfkk4XkhEXlIkfTp+DnjczDECbub3 +FXZmOn7MJBVo4OhCJNcCMityEE5GdHGKBMIjSCBEjniQx3olNUBeGsl057bsS91KJOqz4 y5KQKk1MeMQ1ngp1YbyvpuKad78hsHKt+mHr2y9r+lKAcFElnjKwPkVyMY9O1w== From: Stefan Schantl To: location@lists.ipfire.org Subject: [PATCH] perl: Add get_as_name() Date: Sat, 22 Aug 2020 16:02:31 +0200 Message-Id: <20200822140231.3405-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: location@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: development@lists.ipfire.org Errors-To: location-bounces@lists.ipfire.org Sender: "Location" 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 --- 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.");