Add leak_detector_c

This commit is contained in:
2025-04-24 10:01:18 +08:00
parent 1c28d55681
commit 6a4fb872f7
13 changed files with 337 additions and 9 deletions

View File

@@ -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()
{