telize

High performance JSON IP and GeoIP REST API (IP Geolocation)
Log | Files | Refs | README | LICENSE

commit 71a43b4e44c9eb1335f8adaed056ac6f1c212dd4
parent 1b8b2051e841e7341f1af8ef8b6e3f131ab993db
Author: Frederic Cambus <fred@statdns.com>
Date:   Fri,  5 Oct 2018 09:51:29 +0200

Perform GeoLite2 ASN lookup and add 'asn' and 'organization' fields to the payload

Diffstat:
Msrc/location.c | 13+++++++++++++
1 file changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/location.c b/src/location.c @@ -128,6 +128,19 @@ location(struct http_request *req) json_object_set_new(output, "offset", json_integer(info->tm_gmtoff)); } + /* GeoLite2 ASN lookup */ + lookup = MMDB_lookup_string(&asn, ip, &gai_error, &mmdb_error); + + MMDB_get_value(&lookup.entry, &entry_data, "autonomous_system_number", NULL); + if (entry_data.has_data) { + json_object_set_new(output, "asn", json_integer(entry_data.uint32)); + } + + MMDB_get_value(&lookup.entry, &entry_data, "autonomous_system_organization", NULL); + if (entry_data.has_data) { + json_object_set_new(output, "organization", json_string(strndup(entry_data.utf8_string, entry_data.data_size))); + } + json = json_dumps(output, JSON_INDENT(3)); if (http_argument_get_string(req, "callback", &callback)) {