新版本采用libipset库操作ipset集合,采用libpcap、libcap抓包获取源IP
This commit is contained in:
@@ -52,7 +52,8 @@ int qqwry_match(char *pattern, char *subject)
|
||||
return ret;
|
||||
}
|
||||
|
||||
iconv_t initialize_iconv(const char *target, const char *src) {
|
||||
iconv_t initialize_iconv(const char *target, const char *src)
|
||||
{
|
||||
// 创建转换描述符
|
||||
iconv_t iconvDesc = iconv_open(target, src);
|
||||
|
||||
@@ -60,9 +61,8 @@ iconv_t initialize_iconv(const char *target, const char *src) {
|
||||
if (iconvDesc == (iconv_t) - 1) {
|
||||
// 如果失败,打印错误信息并返回 NULL
|
||||
fprintf(stderr, "Error: Conversion from '%s' to '%s' is not available.\n", src, target);
|
||||
return (iconv_t)NULL;
|
||||
return (iconv_t) NULL;
|
||||
}
|
||||
|
||||
// 成功时返回 iconv_t 描述符
|
||||
return iconvDesc;
|
||||
}
|
||||
@@ -165,23 +165,18 @@ void qqwry_back(unsigned int byte)
|
||||
qqwry_seek(currPos - byte);
|
||||
}
|
||||
|
||||
|
||||
char *long2ip(int ip) {
|
||||
char *long2ip(int ip)
|
||||
{
|
||||
// 分配16字节内存用于存储IP字符串
|
||||
char *ip_str = malloc(16 * sizeof(char));
|
||||
|
||||
|
||||
if (ip_str == NULL) {
|
||||
// 如果内存分配失败,返回NULL
|
||||
fprintf(stderr, "Memory allocation failed\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 将IP转换为字符串
|
||||
snprintf(ip_str, 16, "%d.%d.%d.%d",
|
||||
(ip >> 24) & 0xFF,
|
||||
(ip >> 16) & 0xFF,
|
||||
(ip >> 8) & 0xFF,
|
||||
ip & 0xFF);
|
||||
snprintf(ip_str, 16, "%d.%d.%d.%d", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF);
|
||||
|
||||
return ip_str;
|
||||
}
|
||||
@@ -341,24 +336,15 @@ int get_location(char *ip)
|
||||
unsigned int offset = search_record(ip);
|
||||
unsigned int tmp_offset;
|
||||
qqwry_seek(offset + 4); // skip 4 byte to get the offset value pointing to record data
|
||||
readvalue(3, (int *)(&tmp_offset)); // the offset pointing to the data
|
||||
readvalue(3, (int *)(&tmp_offset)); // the offset pointing to the data
|
||||
get_data(tmp_offset);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *qqwry_(char *ip)
|
||||
char *qqwry_(char *dat, char *ip)
|
||||
{
|
||||
char *qqdb_path = "qqwry.dat";
|
||||
if (access(qqdb_path, F_OK) == -1) { // 判断 ip2region 地址定位库是否存在
|
||||
qqdb_path = "qqwry/qqwry.dat";
|
||||
if (access(qqdb_path, F_OK) == -1) {
|
||||
printf("qqwry.dat DOESN'T EXIST!\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
qqwry_init(qqdb_path);
|
||||
|
||||
qqwry_init(dat);
|
||||
|
||||
get_location(ip);
|
||||
//printf("%s-%s %d\n", ip_defaults.parent_data, ip_defaults.child_data, ip_defaults.isp);
|
||||
|
||||
Reference in New Issue
Block a user