-
Notifications
You must be signed in to change notification settings - Fork 2
API kr_search
JoungKyun Kim edited this page Jul 17, 2016
·
6 revisions
kr_search - Search information of krisp database about given ip address.
#include <krisp.h>
typedef struct netinfos {
char err[1024]; // get error messages
char ip[256]; // given address
char icode[64]; // ISP code
char iname[64]; // ISP full name
char ccode[4]; // Country code
char cname[64]; // Country full name
ulong netmask; // network mask of range
ulong start; // start of range
ulong end; // end of range
bool verbose; // verbose option
} KRNET_API;
int kr_search (KRNET_API * isp, KR_API * db);
kr_search api searches information about given ip or domain name. Basically kr_search API searches on krisp table of database.
If you want to other table name, you can use kr_search_ex api.
see also ‘man 3 kr_search_ex‘
.
Before call the kr_search api, ip member of KRNET_API struct is must initialized.
strcpy (isp.ip, ipaddress);
kr_search (&isp, db);
On success, return 0 and otherwise return 1. No search result is regared as success. Only DB error is regarded as failure.
#include <krisp.h>
int main (void) {
KR_API * db;
KRNET_API isp;
char * addr = "kns.kornet.net";
char * database = NULL;
char err[1024];
if ( kr_open (&db, database, err) == false ) {
fprintf (stderr, "ERROR Connect: %s\n", err);
return 1;
}
isp.verbose = false;
// defined safecpy_256 in krispapi.h
safecpy_256 (isp.ip, addr);
if ( kr_search (&isp, db) ) {
printf ("ERROR: %s\n", isp.err);
kr_close (&db);
return 1;
}
kr_close (&db);
/*
* long2ip is include libipcalc.
* https://github.com/Joungkyun/libipcalc/wiki/API-long2ip
* long2ip is returned in a statically allocated buffer, which
* subsequent calls will overwrite. For thread safe, use long2ip_r.
*/
printf ("%-15s %-15s %-20s", ip, isp.ip, isp.icode);
printf ("%-15s ", long2ip (isp.start));
printf ("%-15s %s", long2ip (isp.end), isp.iname);
return 0;
}
JoungKyun.Kim <http://joungkyun.github.com>
Report to https://github.com/Joungkyun/libkrisp/issues
Copyright (c) 2016 JoungKyun.Kim <http://oops.org>
This api is follows LGPL 2.1