aboutsummaryrefslogtreecommitdiff
path: root/contrib/blocklist/test/srvtest.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/blocklist/test/srvtest.c')
-rw-r--r--contrib/blocklist/test/srvtest.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/contrib/blocklist/test/srvtest.c b/contrib/blocklist/test/srvtest.c
index 03a762ab81f2..4eb9468ed5fd 100644
--- a/contrib/blocklist/test/srvtest.c
+++ b/contrib/blocklist/test/srvtest.c
@@ -1,4 +1,4 @@
-/* $NetBSD: srvtest.c,v 1.10 2015/05/30 22:40:38 christos Exp $ */
+/* $NetBSD: srvtest.c,v 1.2 2025/02/11 17:43:16 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -32,8 +32,10 @@
#include "config.h"
#endif
+#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
-__RCSID("$NetBSD: srvtest.c,v 1.10 2015/05/30 22:40:38 christos Exp $");
+#endif
+__RCSID("$NetBSD: srvtest.c,v 1.2 2025/02/11 17:43:16 christos Exp $");
#include <sys/types.h>
#include <sys/socket.h>
@@ -48,7 +50,7 @@ __RCSID("$NetBSD: srvtest.c,v 1.10 2015/05/30 22:40:38 christos Exp $");
#include <poll.h>
#include <err.h>
-#include "blacklist.h"
+#include "blocklist.h"
#ifdef BLDEBUG
#include "bl.h"
static void *b;
@@ -71,9 +73,9 @@ process_tcp(int afd)
buffer[sizeof(buffer) - 1] = '\0';
printf("%s: sending %d %s\n", getprogname(), afd, buffer);
#ifdef BLDEBUG
- blacklist_r(b, 1, afd, buffer);
+ blocklist_r(b, 1, afd, buffer);
#else
- blacklist(1, afd, buffer);
+ blocklist(1, afd, buffer);
#endif
exit(0);
}
@@ -95,7 +97,7 @@ process_udp(int afd)
err(1, "recvfrom");
buffer[sizeof(buffer) - 1] = '\0';
printf("%s: sending %d %s\n", getprogname(), afd, buffer);
- blacklist_sa(1, afd, (void *)&ss, slen, buffer);
+ blocklist_sa(1, afd, (void *)&ss, slen, buffer);
exit(0);
}
static int
@@ -167,7 +169,11 @@ static __dead void
usage(int c)
{
warnx("Unknown option `%c'", (char)c);
- fprintf(stderr, "Usage: %s [-u] [-p <num>]\n", getprogname());
+ fprintf(stderr, "Usage: %s [-u] [-p <num>]"
+#ifdef BLDEBUG
+ " [-s <sockpath>]"
+#endif
+ "\n", getprogname());
exit(EXIT_FAILURE);
}
@@ -182,14 +188,16 @@ main(int argc, char *argv[])
struct pollfd pfd[NUMFD];
int type = SOCK_STREAM, c;
in_port_t port = 6161;
-
- signal(SIGCHLD, SIG_IGN);
-
#ifdef BLDEBUG
- b = bl_create(false, "blsock", vsyslog);
+ char *sockpath = "blsock";
+ const char *optstr = "up:s:";
+#else
+ const char *optstr = "up:";
#endif
- while ((c = getopt(argc, argv, "up:")) != -1)
+ signal(SIGCHLD, SIG_IGN);
+
+ while ((c = getopt(argc, argv, optstr)) != -1)
switch (c) {
case 'u':
type = SOCK_DGRAM;
@@ -197,10 +205,20 @@ main(int argc, char *argv[])
case 'p':
port = (in_port_t)atoi(optarg);
break;
+#ifdef BLDEBUG
+ case 's':
+ sockpath = (char *)optarg;
+ break;
+#endif
default:
usage(c);
}
+#ifdef BLDEBUG
+ b = bl_create(false, sockpath, vsyslog_r);
+#endif
+
+
pfd[0].fd = cr(AF_INET, type, port);
pfd[0].events = POLLIN;
#if NUMFD > 1