From patchwork Wed Oct 2 17:10:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 2464 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 46k2hQ70Yxz3yqH for ; Wed, 2 Oct 2019 17:10:30 +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 46k2hQ66lwz3Ck; Wed, 2 Oct 2019 17:10:30 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 46k2hQ3xp1z2yZr; Wed, 2 Oct 2019 17:10:30 +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 46k2hP4gRXz2yLN; Wed, 2 Oct 2019 17:10:29 +0000 (UTC) Received: from tuxedo.stevee (213162068236.public.t-mobile.at [213.162.68.236]) (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 46k2hP20X4z2L5; Wed, 2 Oct 2019 17:10:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909rsa; t=1570036229; 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=l76A3tklf5ZSGgut0N4Pchp+tNOoIOkkNZqyTkVaDEk=; b=oWEXtNPFOxukbR/rbiVgbSD3ohxssA0+05MnPWDTdjIgR4PkRZagGY/KdC6osk4O8Y+ovC IwjrRhWmrz2WyrQyvgnHL2hSWObI3daa/NzZ6qmKxoJXxW+WyV/sRTccO0jaEM0Zklk1MI BvTcGDS1bVMCI8pY+HGyJsEUiRwXnfGWCwIZd52VXciPdubiNQmPS8wlU6+MTHkc2xvsgh Gzc2vSdclJ0EYF5sRnQ6mg9jpOU18p4J9iAuC5IadEEZVaa0tU/icj8B/cgV/7+WyqkLSD eGc5AHpu108b6gyZStBx0rAJx2j6LQAbItqIxck63aJuI9imav9WszIlCqsZ1Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909ed25519; t=1570036229; 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=l76A3tklf5ZSGgut0N4Pchp+tNOoIOkkNZqyTkVaDEk=; b=yk3g6SzNSdLoJiqChfLWaKes1Ge9COsRVu7gZq5LcJBHyQEi9nJj2Amt0U8RMBBr1lT+ZO NRVD34Lmz9TNE1Bw== From: Stefan Schantl To: development@lists.ipfire.org, location@lists.ipfire.org Subject: [PATCHv2] perl: Add function to perform AS number lookups. Date: Wed, 2 Oct 2019 19:10:21 +0200 Message-Id: <20191002171021.6857-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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/perl/Location.xs b/src/perl/Location.xs index cdbc7e7..b6c4dc5 100644 --- a/src/perl/Location.xs +++ b/src/perl/Location.xs @@ -113,6 +113,29 @@ lookup_country_code(db, address) OUTPUT: RETVAL +SV* +lookup_asn(db, address) + struct loc_database* db; + char* address; + + CODE: + RETVAL = &PL_sv_undef; + + // Lookup network + struct loc_network *network; + int err = loc_database_lookup_from_string(db, address, &network); + if (!err) { + // Extract the ASN + unsigned int as_number = loc_network_get_asn(network); + if (as_number > 0) { + RETVAL = newSViv(as_number); + } + + loc_network_unref(network); + } + OUTPUT: + RETVAL + void DESTROY(db) struct loc_database* db;