summaryrefslogtreecommitdiffstats
path: root/usr.sbin/tcpdrop
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2004-04-27 17:52:21 +0000
committerotto <otto@openbsd.org>2004-04-27 17:52:21 +0000
commit2a47af06b95b5f7d39181957ff7395cf877f6418 (patch)
tree983a6651fb72e5b6b2dd05f55e7c68ddb770f79b /usr.sbin/tcpdrop
parentRequire NULL oldp when dropping a connection. (diff)
downloadwireguard-openbsd-2a47af06b95b5f7d39181957ff7395cf877f6418.tar.xz
wireguard-openbsd-2a47af06b95b5f7d39181957ff7395cf877f6418.zip
Set oldp en oldlenp to NULL; provide feedback; set exit status.
ok markus@
Diffstat (limited to 'usr.sbin/tcpdrop')
-rw-r--r--usr.sbin/tcpdrop/tcpdrop.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/usr.sbin/tcpdrop/tcpdrop.c b/usr.sbin/tcpdrop/tcpdrop.c
index 5cd62842ba1..b2b919c18e0 100644
--- a/usr.sbin/tcpdrop/tcpdrop.c
+++ b/usr.sbin/tcpdrop/tcpdrop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcpdrop.c,v 1.1 2004/04/26 19:51:20 markus Exp $ */
+/* $OpenBSD: tcpdrop.c,v 1.2 2004/04/27 17:52:21 otto Exp $ */
/*
* Copyright (c) 2004 Markus Friedl <markus@openbsd.org>
@@ -26,10 +26,10 @@
#include <netinet/tcp_timer.h>
#include <netinet/tcp_var.h>
+#include <err.h>
#include <stdio.h>
#include <string.h>
#include <netdb.h>
-#include <err.h>
extern char *__progname;
@@ -40,10 +40,12 @@ int
main(int argc, char **argv)
{
struct addrinfo hints, *ail, *aif, *laddr, *faddr;
- struct tcp_ident_mapping tir, dummy;
+ struct tcp_ident_mapping tir;
int mib[] = { CTL_NET, PF_INET, IPPROTO_TCP, TCPCTL_DROP };
int gaierr;
- size_t i = 1;
+ char fhbuf[NI_MAXHOST], fsbuf[NI_MAXSERV];
+ char lhbuf[NI_MAXHOST], lsbuf[NI_MAXSERV];
+ int rval = 0;
if (argc != 5) {
fprintf(stderr, "usage: %s laddr lport faddr fport\n",
@@ -71,14 +73,30 @@ main(int argc, char **argv)
continue;
memcpy(&tir.faddr, aif->ai_addr, aif->ai_addrlen);
memcpy(&tir.laddr, ail->ai_addr, ail->ai_addrlen);
- i = sizeof (tir);
- if (sysctl(mib, sizeof (mib) / sizeof (int), &dummy,
- &i, &tir, i) == -1)
- warn(NULL);
+
+ if (getnameinfo(aif->ai_addr, aif->ai_addrlen,
+ fhbuf, sizeof(fhbuf),
+ fsbuf, sizeof(fsbuf),
+ NI_NUMERICHOST | NI_NUMERICSERV) == -1)
+ err(1, "getnameinfo");
+ if (getnameinfo(ail->ai_addr, ail->ai_addrlen,
+ lhbuf, sizeof(lhbuf),
+ lsbuf, sizeof(lsbuf),
+ NI_NUMERICHOST | NI_NUMERICSERV) == -1)
+ err(1, "getnameinfo");
+
+ if (sysctl(mib, sizeof (mib) / sizeof (int), NULL,
+ NULL, &tir, sizeof(tir)) == -1) {
+ rval = 1;
+ warn("%s %s %s %s", lhbuf, lsbuf, fhbuf, fsbuf);
+ } else
+ printf("%s %s %s %s: dropped\n",
+ lhbuf, lsbuf, fhbuf, fsbuf);
+
}
}
freeaddrinfo(laddr);
freeaddrinfo(faddr);
- exit(0);
+ exit(rval);
}