commit 73047abe7b97dd57838fc14c837c5803212e3907
parent a883697fbae730cdbae13b427aaea1d11f4abe83
Author: Naveen Narayanan <zerous@nocebo.space>
Date: Sun, 10 Oct 2021 00:39:02 +0200
Implement blacklist()
Diffstat:
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/attack.c b/attack.c
@@ -1,7 +1,9 @@
+#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
+#include <unistd.h>
#include "attack.h"
@@ -53,8 +55,17 @@ isexpire(struct attacker *a)
int
blacklist(struct attacker *a)
{
- /* stub */
- printf("%s blacklisted\n", a->ip);
+ char ip[16];
+ int len;
+
+ strcpy(ip, a->ip);
+ len = strlen(ip);
+ ip[len] = '\n';
+ a->list = BLACK;
+ if (write(fd_black, ip, len+1) != len+1) {
+ fprintf(stderr, "write failed: %s\n", strerror(errno));
+ return -1;
+ }
return 1;
}
diff --git a/attack.h b/attack.h
@@ -5,6 +5,9 @@
#include "queue.h"
+extern int fd_black;
+extern int fd_white;
+
enum list {
BLACK,
WHITE,