Browse Source

+ f2b_ipaddr_status()

master
Alex 'AdUser' Z 8 years ago
parent
commit
ea3a223268
  1. 9
      src/daemon.c
  2. 15
      src/ipaddr.c
  3. 1
      src/ipaddr.h

9
src/daemon.c

@ -157,14 +157,7 @@ f2b_cmsg_process(const f2b_cmsg_t *msg, char *res, size_t ressize) {
jail->incr_bantime, jail->incr_findtime,
jail->bancount, jail->matchcount);
} else if (msg->type == CMD_JAIL_IP_SHOW) {
fmt = "ipaddr: %s\n"
"banned: %s\n"
"bancount: %d\n"
"lastseen: %d\n"
"banned_at: %d\n"
"release_at: %d\n";
snprintf(res, ressize, fmt, addr->text, addr->banned ? "yes" : "no",
addr->bancount, addr->lastseen, addr->banned_at, addr->release_at);
f2b_ipaddr_status(addr, res, ressize);
} else if (msg->type == CMD_JAIL_IP_BAN) {
f2b_jail_ban(jail, addr);
strlcpy(res, "ok", ressize);

15
src/ipaddr.c

@ -44,6 +44,21 @@ f2b_ipaddr_destroy(f2b_ipaddr_t *ipaddr) {
free(ipaddr);
}
void
f2b_ipaddr_status(f2b_ipaddr_t *addr, char *res, size_t ressize) {
assert(addr != NULL);
assert(res != NULL);
const char *fmt =
"ipaddr: %s\n"
"banned: %s\n"
"bancount: %d\n"
"lastseen: %d\n"
"banned_at: %d\n"
"release_at: %d\n";
snprintf(res, ressize, fmt, addr->text, addr->banned ? "yes" : "no",
addr->bancount, addr->lastseen, addr->banned_at, addr->release_at);
}
f2b_ipaddr_t *
f2b_addrlist_append(f2b_ipaddr_t *list, f2b_ipaddr_t *ipaddr) {
assert(ipaddr != NULL);

1
src/ipaddr.h

@ -31,6 +31,7 @@ typedef struct f2b_ipaddr_t {
f2b_ipaddr_t * f2b_ipaddr_create (const char *addr, size_t max_matches);
void f2b_ipaddr_destroy(f2b_ipaddr_t *ipaddr);
void f2b_ipaddr_status (f2b_ipaddr_t *ipaddr, char *res, size_t ressize);
f2b_ipaddr_t * f2b_addrlist_append(f2b_ipaddr_t *list, f2b_ipaddr_t *ipaddr);
f2b_ipaddr_t * f2b_addrlist_lookup(f2b_ipaddr_t *list, const char *addr);

Loading…
Cancel
Save