-
Notifications
You must be signed in to change notification settings - Fork 2
API kr_search_ex
kr_search_ex - search user defined table name of krisp database.
#include <krisp.h>
typedef struct raw_netinfos {
char err[1024]; // get error meassages
char ip[16]; // given address
char ** dummy; // array of 3th field with pipe seperator of table
char * dummydata; // 3th field strings with pipe seperator of table
ulong start; // start of range
ulong end; // end of range
bool verbose; // verbose option. need initialize
short size; // size of dummy member
} KRNET_API_EX;
int kr_search_ex (KRNET_API_EX * u_isp, KR_API * db);
kr_search api searches onlly ‘krisp’ table, but kr_searhc_ex api is supported to search user defined table name. In other words, you can add other table on krisp database.
table scheme of user defined table is follow:
CREATE TABLE ‘user_table_name‘
(
start integer NOT NULL DEFAULT ‘0‘,
end integer NOT NULL DEFAULT ‘0‘,
data varchar,
PRIMARY KEY (start DESC),
UNIQUE (end)
);
All of libkrisp table scheme must have upper scheme.
Before call the kr_search_ex api, ip member of KR_API struct is must initialized just like kr_search api.
kr_search_ex api internally allocate memory to dummy and dummydata member of KRNET_API_EX struct, so after use KRNET_API_EX struct, you must call initStruct_ex api. On use loop, you must call per loop.
strcpy (u_isp.ip, ipaddress);
db->table = user_define_table;
kr_search_ex (&u_isp, db);
initStruct_ex (&u_isp, true);
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_EX u_isp;
char * addr[] = {"kns.kornet.net", "ns.dacom.co.kr"};
char * database = NULL;
char err[1024];
if ( kr_open (&db, database, err) == false ) {
fprintf (stderr, "ERROR Connect: %s\n", err);
return 1;
}
u_isp.verbose = false;
db->table = "geocipy";
for ( r=0; r<2; r++ ) {
// defined safecpy_256 in krispapi.h
safecpy_256 (isp.ip, addr);
if ( kr_search_ex (&u_isp, db) ) {
printf ("ERROR: %s\n", u_isp.err);
initStruct_ex (&u_isp, true);
kr_close (&db);
return 1;
}
/*
* 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, u_isp.dummy[0]);
printf ("%-15s ", long2ip (u_isp.start));
printf ("%-15s %s", long2ip (u_isp.end), u_isp.dummy[1]);
initStruct_ex (&u_isp, true);
}
kr_close (&db);
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