Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- 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;