From patchwork Tue Oct 1 06:16:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 2448 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) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 46j8Dl1196z3yqG for ; Tue, 1 Oct 2019 06:16:55 +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 46j8Dk70fNz2fd; Tue, 1 Oct 2019 06:16:54 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 46j8Dk6LtJz2yZx; Tue, 1 Oct 2019 06:16:54 +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) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 46j8Dj6J94z2yCr; Tue, 1 Oct 2019 06:16:53 +0000 (UTC) Received: from tuxedo.stevee (unknown [46.125.250.123]) (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 46j8Dj3T0nz2cP; Tue, 1 Oct 2019 06:16:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909rsa; t=1569910613; 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=mym1tkoUY8YTRhj8ULQ1PyKlUM14pZ6kLrbIX6/Cauk=; b=KCBt5glkpN2Z39P3UMsqa412j58Rt/Sqqk210rKXD9lyaaBXF4T5zkq1RFBjQQIDIr/4oo JoIxGu7zqqX+cZucVhagFaEM1r7nheayVtolT9zBcHOJcDJB2kIL26mmdVfdGO1PeTn6JL oRc6Afi9NEjW6mOrAXsMpK1yYz1dHSag1rQvOnqOzkfSEKm3cSYwBeoT5jTnjs0fuVITgt fR8xsYne7+dfpvnugbiPxVC3ZS3r8VT57OiriD9uZrZy4NlUNqbZRwgn5mRi01+YWWUSAp N5oprBuqTPYqSosZUUXDFh34TmmI8EhBzFnIuXgQcXHAn5uKESKWr1DipeZ/cg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909ed25519; t=1569910613; 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=mym1tkoUY8YTRhj8ULQ1PyKlUM14pZ6kLrbIX6/Cauk=; b=5CyrNQyQzHCg9sVahy02K9VIc/vTWYoqdY4rW/v8a9Apb3LWw+AM5r/TDAX3mDkx1Rtpju uto3XlONcp6aNuBA== From: Stefan Schantl To: development@lists.ipfire.org, location@lists.ipfire.org Subject: [PATCH] perl: Add function to perform AS number lookups. Date: Tue, 1 Oct 2019 08:16:51 +0200 Message-Id: <20191001061651.4737-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.auth=stevee 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: , Errors-To: location-bounces@lists.ipfire.org Sender: "Location" Signed-off-by: Stefan Schantl --- src/perl/Location.xs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/perl/Location.xs b/src/perl/Location.xs index ab27f0b..63410c4 100644 --- a/src/perl/Location.xs +++ b/src/perl/Location.xs @@ -117,6 +117,32 @@ lookup_country_code(db, address) OUTPUT: RETVAL +unsigned int +lookup_asn(db, address) + struct loc_database* db; + char* address; + + CODE: + // Lookup network + struct loc_network *network; + int err = loc_database_lookup_from_string(db, address, &network); + if (err) { + croak("Could not look up for %s\n", address); + } + + // Extract the ASN + unsigned int as_number = loc_network_get_asn(network); + loc_network_unref(network); + + if (as_number) { + RETVAL = as_number; + } else { + //RETVAL = NULL; + RETVAL = 0; + } + OUTPUT: + RETVAL + void DESTROY(db) struct loc_database* db;