20250423
This commit is contained in:
@@ -86,14 +86,12 @@ int create_ipset(char *set_name)
|
||||
ipset_fini(ipset);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 设置自定义错误和输出处理函数
|
||||
if (ipset_custom_printf(ipset, custom_error_handler, NULL, custom_output_handler_, NULL) != 0) {
|
||||
fprintf(stderr, "设置自定义打印函数失败。\n");
|
||||
ipset_fini(ipset);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 创建集合
|
||||
char *args[] = { "ipset", "create", set_name, "hash:ip", NULL };
|
||||
if (ipset_parse_argv(ipset, 4, args) != 0) {
|
||||
@@ -101,7 +99,6 @@ int create_ipset(char *set_name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ipset_fini(ipset);
|
||||
|
||||
return 0;
|
||||
@@ -135,14 +132,12 @@ int add_ip_to_ipset(char *set_name, char *ip)
|
||||
ipset_fini(ipset);
|
||||
return -1; // 返回 -1,但不退出
|
||||
}
|
||||
|
||||
// 设置自定义错误和输出处理函数
|
||||
if (ipset_custom_printf(ipset, custom_error_handler, NULL, custom_output_handler_, NULL) != 0) {
|
||||
fprintf(stderr, "设置自定义打印函数失败。\n");
|
||||
ipset_fini(ipset);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 将ip添加到集合
|
||||
char *args[] = { "ipset", "add", set_name, ip, NULL };
|
||||
if (ipset_parse_argv(ipset, 4, args) != 0) {
|
||||
@@ -150,7 +145,6 @@ int add_ip_to_ipset(char *set_name, char *ip)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ipset_fini(ipset);
|
||||
|
||||
return 0; // 始终返回 0,表示执行成功
|
||||
@@ -173,7 +167,6 @@ int flush_ipset(char *set_name)
|
||||
ipset_fini(ipset);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 清空集合
|
||||
char *args[] = { "ipset", "flush", set_name, NULL };
|
||||
if (ipset_parse_argv(ipset, 3, args) != 0) {
|
||||
@@ -204,14 +197,12 @@ int get_ip_count_in_ipset(char *set_name)
|
||||
ipset_fini(ipset);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 列出集合
|
||||
char *args[] = { "ipset", "list", set_name, NULL };
|
||||
if (ipset_parse_argv(ipset, 3, args) != 0) {
|
||||
ipset_fini(ipset);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 释放资源
|
||||
ipset_fini(ipset);
|
||||
return ip_count;
|
||||
|
||||
Reference in New Issue
Block a user