prettier display

This commit is contained in:
christos 2015-01-26 02:31:52 +00:00
parent b110ac9d5f
commit 3808a58b42
2 changed files with 29 additions and 9 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: blacklistctl.8,v 1.3 2015/01/25 23:07:16 wiz Exp $
.\" $NetBSD: blacklistctl.8,v 1.4 2015/01/26 02:31:52 christos Exp $
.\"
.\" Copyright (c) 2015 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd January 24, 2015
.Dd January 25, 2015
.Dt BLACKLISTCTL 8
.Os
.Sh NAME
@ -35,8 +35,13 @@
.Nd display and change the state of blacklistd
.Sh SYNOPSIS
.Nm
<<<<<<< blacklistctl.8
dump
.Op Fl abdnrw
=======
.Cm dump
.Op Fl abdr
>>>>>>> 1.3
.Sh DESCRIPTION
.Nm
is a program used to display the state of
@ -50,8 +55,14 @@ Show all database entries, by default it shows only the embryonic ones.
Show only the blocked entries.
.It Fl d
Increase debugging level.
.It Fl n
Don't display a header.
.It Fl r
Show the remaining blocked time instead of the last activity time.
.It Fl w
Normally the width of addresses is good for IPv4, the
.Fl w
flag, makes the display wide enough for IPv6 addresses.
.El
.Sh SEE ALSO
.Xr blacklistd 8

View File

@ -1,4 +1,4 @@
/* $NetBSD: blacklistctl.c,v 1.14 2015/01/24 15:33:03 christos Exp $ */
/* $NetBSD: blacklistctl.c,v 1.15 2015/01/26 02:31:52 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: blacklistctl.c,v 1.14 2015/01/24 15:33:03 christos Exp $");
__RCSID("$NetBSD: blacklistctl.c,v 1.15 2015/01/26 02:31:52 christos Exp $");
#include <stdio.h>
#include <time.h>
@ -60,7 +60,7 @@ usage(int c)
warnx("Missing/unknown command");
else
warnx("Unknown option `%c'", (char)c);
fprintf(stderr, "Usage: %s dump [-abdr]\n", getprogname());
fprintf(stderr, "Usage: %s dump [-abdnrw]\n", getprogname());
exit(EXIT_FAILURE);
}
@ -74,10 +74,10 @@ main(int argc, char *argv[])
struct dbinfo dbi;
unsigned int i;
struct timespec ts;
int all, blocked, remain;
int all, blocked, remain, wide, noheader;
int o;
blocked = all = remain = 0;
noheader = wide = blocked = all = remain = 0;
lfun = dlog;
if (argc == 1 || strcmp(argv[1], "dump") != 0)
@ -86,7 +86,7 @@ main(int argc, char *argv[])
argc--;
argv++;
while ((o = getopt(argc, argv, "abdr")) != -1)
while ((o = getopt(argc, argv, "abdrw")) != -1)
switch (o) {
case 'a':
all = 1;
@ -98,9 +98,14 @@ main(int argc, char *argv[])
case 'd':
debug++;
break;
case 'n':
noheader = 1;
case 'r':
remain = 1;
break;
case 'w':
wide = 1;
break;
default:
usage(o);
break;
@ -111,6 +116,10 @@ main(int argc, char *argv[])
err(EXIT_FAILURE, "Can't open `%s'", dbname);
clock_gettime(CLOCK_REALTIME, &ts);
wide = wide ? 8 * 4 + 7 : 4 * 3 + 3;
if (!noheader)
printf("%*.*s:port\tid\tnfail\t%s\n", wide, wide,
"address", remain ? "remaining time" : "last access");
for (i = 1; state_iterate(db, &ss, &c, &dbi, i) != 0; i = 0) {
char buf[BUFSIZ];
if (!all) {
@ -123,7 +132,7 @@ main(int argc, char *argv[])
}
}
sockaddr_snprintf(buf, sizeof(buf), "%a", (void *)&ss);
printf("%15.15s:%d\t", buf, c.c_port);
printf("%*.*s:%d\t", wide, wide, buf, c.c_port);
if (remain)
fmtydhms(buf, sizeof(buf),
c.c_duration - (ts.tv_sec - dbi.last));