Add leak_detector_c
This commit is contained in:
21
libipset.c
21
libipset.c
@@ -208,6 +208,27 @@ int get_ip_count_in_ipset(char *set_name)
|
||||
return ip_count;
|
||||
}
|
||||
|
||||
|
||||
void add_iptables_rule(const char *rule_name)
|
||||
{
|
||||
char iptables_command[256];
|
||||
|
||||
// 使用 snprintf 避免溢出
|
||||
int written = snprintf(iptables_command, sizeof(iptables_command),
|
||||
"iptables -I INPUT -m set --match-set %s src -j DROP", rule_name);
|
||||
|
||||
if (written < 0 || written >= sizeof(iptables_command)) {
|
||||
fprintf(stderr, "Error: iptables command is too long.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// 执行命令并检查返回值
|
||||
int ret = system(iptables_command);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "Failed to execute iptables command: %s\n", iptables_command);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
int main()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user