aboutsummaryrefslogtreecommitdiffstats
path: root/bin/blacklistctl.c
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2019-11-06 14:09:52 +0000
committerEd Maste <emaste@FreeBSD.org>2019-11-06 14:09:52 +0000
commit758bdc240105f5918fc17502042b47f00a314272 (patch)
tree98a60fee0afb7933bc75187532aeebc151a7096e /bin/blacklistctl.c
parent52253412b1a4ba5050d6d44baaf6f40f3a5dd25f (diff)
downloadsrc-758bdc240105f5918fc17502042b47f00a314272.tar.gz
src-758bdc240105f5918fc17502042b47f00a314272.zip
Vendor import of NetBSD's external/bsd/blacklist @ 20191106vendor/NetBSD/blacklist/20191106vendor/NetBSD/blacklist
Sponsored by: The FreeBSD Foundation
Notes
Notes: svn path=/vendor/NetBSD/blacklist/dist/; revision=354388 svn path=/vendor/NetBSD/blacklist/20191106/; revision=354389; tag=vendor/NetBSD/blacklist/20191106
Diffstat (limited to 'bin/blacklistctl.c')
-rw-r--r--bin/blacklistctl.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/bin/blacklistctl.c b/bin/blacklistctl.c
index 8cef404d74bf..aebbf72acc5e 100644
--- a/bin/blacklistctl.c
+++ b/bin/blacklistctl.c
@@ -1,4 +1,4 @@
-/* $NetBSD: blacklistctl.c,v 1.21 2016/11/02 03:15:07 jnemeth Exp $ */
+/* $NetBSD: blacklistctl.c,v 1.23 2018/05/24 19:21:01 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: blacklistctl.c,v 1.21 2016/11/02 03:15:07 jnemeth Exp $");
+__RCSID("$NetBSD: blacklistctl.c,v 1.23 2018/05/24 19:21:01 christos Exp $");
#include <stdio.h>
#include <time.h>
@@ -67,6 +67,15 @@ usage(int c)
exit(EXIT_FAILURE);
}
+static const char *
+star(char *buf, size_t len, int val)
+{
+ if (val == -1)
+ return "*";
+ snprintf(buf, len, "%d", val);
+ return buf;
+}
+
int
main(int argc, char *argv[])
{
@@ -128,9 +137,10 @@ main(int argc, char *argv[])
"address", remain ? "remaining time" : "last access");
for (i = 1; state_iterate(db, &c, &dbi, i) != 0; i = 0) {
char buf[BUFSIZ];
+ char mbuf[64], pbuf[64];
if (!all) {
if (blocked) {
- if (dbi.count < c.c_nfail)
+ if (c.c_nfail == -1 || dbi.count < c.c_nfail)
continue;
} else {
if (dbi.count >= c.c_nfail)
@@ -138,13 +148,20 @@ main(int argc, char *argv[])
}
}
sockaddr_snprintf(buf, sizeof(buf), "%a", (void *)&c.c_ss);
- printf("%*.*s/%d:%d\t", wide, wide, buf, c.c_lmask, c.c_port);
- if (remain)
- fmtydhms(buf, sizeof(buf),
- c.c_duration - (ts.tv_sec - dbi.last));
- else
- fmttime(buf, sizeof(buf), dbi.last);
- printf("%s\t%d/%d\t%-s\n", dbi.id, dbi.count, c.c_nfail, buf);
+ printf("%*.*s/%s:%s\t", wide, wide, buf,
+ star(mbuf, sizeof(mbuf), c.c_lmask),
+ star(pbuf, sizeof(pbuf), c.c_port));
+ if (c.c_duration == -1) {
+ strlcpy(buf, "never", sizeof(buf));
+ } else {
+ if (remain)
+ fmtydhms(buf, sizeof(buf),
+ c.c_duration - (ts.tv_sec - dbi.last));
+ else
+ fmttime(buf, sizeof(buf), dbi.last);
+ }
+ printf("%s\t%d/%s\t%-s\n", dbi.id, dbi.count,
+ star(mbuf, sizeof(mbuf), c.c_nfail), buf);
}
state_close(db);
return EXIT_SUCCESS;