summaryrefslogtreecommitdiff
path: root/usr.sbin/tcpdrop
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2007-03-25 17:20:28 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2007-03-25 17:20:28 +0000
commit30dc9e31de293d613a88a45085166c1affa3da2e (patch)
tree9fd2d04b457908634c0f772324470cdaaf5ae8d9 /usr.sbin/tcpdrop
parentc5b5c5d184110417fa647c8da369d23213902d97 (diff)
support a 2 address format (addr:port addr:port) like fstat outputs.
also enhance ipv6 support by unpacking the [addr]:port format. ok beck, itojun, various others
Diffstat (limited to 'usr.sbin/tcpdrop')
-rw-r--r--usr.sbin/tcpdrop/tcpdrop.89
-rw-r--r--usr.sbin/tcpdrop/tcpdrop.c70
2 files changed, 60 insertions, 19 deletions
diff --git a/usr.sbin/tcpdrop/tcpdrop.8 b/usr.sbin/tcpdrop/tcpdrop.8
index a2f659594b0..63ccc627589 100644
--- a/usr.sbin/tcpdrop/tcpdrop.8
+++ b/usr.sbin/tcpdrop/tcpdrop.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tcpdrop.8,v 1.6 2006/01/03 14:52:17 jmc Exp $
+.\" $OpenBSD: tcpdrop.8,v 1.7 2007/03/25 17:20:27 deraadt Exp $
.\"
.\" Copyright (c) 2004 Markus Friedl <markus@openbsd.org>
.\"
@@ -26,6 +26,9 @@
.Ar lport
.Ar faddr
.Ar fport
+.Nm tcpdrop
+.Ar laddr : Ns Ar lport
+.Ar faddr : Ns Ar fport
.Sh DESCRIPTION
The
.Nm
@@ -49,9 +52,11 @@ www httpd 21307 3* internet stream tcp \e
0xd1007ca8 192.168.5.41:80 \*(Lt-- 192.168.5.1:26747
.Ed
.Pp
-The following command will drop the connection:
+Either of the following commands will drop the connection:
.Bd -literal -offset indent
# tcpdrop 192.168.5.41 80 192.168.5.1 26747
+
+# tcpdrop 192.168.5.41:80 192.168.5.1:26747
.Ed
.Sh SEE ALSO
.Xr fstat 1 ,
diff --git a/usr.sbin/tcpdrop/tcpdrop.c b/usr.sbin/tcpdrop/tcpdrop.c
index 5857446f0bb..578b69ae94c 100644
--- a/usr.sbin/tcpdrop/tcpdrop.c
+++ b/usr.sbin/tcpdrop/tcpdrop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcpdrop.c,v 1.5 2006/01/03 01:46:27 stevesk Exp $ */
+/* $OpenBSD: tcpdrop.c,v 1.6 2007/03/25 17:20:27 deraadt Exp $ */
/*
* Copyright (c) 2004 Markus Friedl <markus@openbsd.org>
@@ -44,26 +44,60 @@ main(int argc, char **argv)
struct addrinfo hints, *ail, *aif, *laddr, *faddr;
char fhbuf[NI_MAXHOST], fsbuf[NI_MAXSERV];
char lhbuf[NI_MAXHOST], lsbuf[NI_MAXSERV];
+ char *laddr1, *addr1, *port1, *laddr2, *addr2, *port2;
struct tcp_ident_mapping tir;
int gaierr, rval = 0;
- if (argc != 5) {
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+
+ if (argc == 3) {
+ laddr1 = addr1 = strdup(argv[1]);
+ port1 = strrchr(addr1, ':');
+ if (port1)
+ *port1++ = '\0';
+ else
+ goto fail;
+
+ laddr2 = addr2 = strdup(argv[2]);
+ port2 = strrchr(addr2, ':');
+ if (port2)
+ *port2++ = '\0';
+ else
+ goto fail;
+ } else if (argc == 5) {
+ laddr1 = addr1 = argv[1];
+ port1 = argv[2];
+ laddr2 = addr2 = argv[3];
+ port2 = argv[4];
+ } else {
+fail:
fprintf(stderr, "usage: %s laddr lport faddr fport\n",
__progname);
+ fprintf(stderr, " %s laddr:lport faddr:fport\n",
+ __progname);
exit(1);
}
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
+ if (addr1[0] == '[' && addr1[strlen(addr1) - 1] == ']') {
+ laddr1 = strdup(addr1);
+ laddr1[strlen(laddr1) - 1] = '\0';
+ laddr1++;
+ }
+ if (addr2[0] == '[' && addr2[strlen(addr2) - 1] == ']') {
+ laddr2 = strdup(addr2);
+ laddr2[strlen(laddr2) - 1] = '\0';
+ laddr2++;
+ }
- if ((gaierr = getaddrinfo(argv[1], argv[2], &hints, &laddr)) != 0)
- errx(1, "%s port %s: %s", argv[1], argv[2],
+ if ((gaierr = getaddrinfo(laddr1, port1, &hints, &laddr)) != 0)
+ errx(1, "%s port %s: %s", addr1, port1,
gai_strerror(gaierr));
- if ((gaierr = getaddrinfo(argv[3], argv[4], &hints, &faddr)) != 0) {
+ if ((gaierr = getaddrinfo(laddr2, port2, &hints, &faddr)) != 0) {
freeaddrinfo(laddr);
- errx(1, "%s port %s: %s", argv[3], argv[4],
+ errx(1, "%s port %s: %s", addr2, port2,
gai_strerror(gaierr));
}
@@ -75,13 +109,11 @@ main(int argc, char **argv)
memcpy(&tir.laddr, ail->ai_addr, ail->ai_addrlen);
if ((gaierr = getnameinfo(aif->ai_addr, aif->ai_addrlen,
- fhbuf, sizeof(fhbuf),
- fsbuf, sizeof(fsbuf),
+ fhbuf, sizeof(fhbuf), fsbuf, sizeof(fsbuf),
NI_NUMERICHOST | NI_NUMERICSERV)) != 0)
errx(1, "getnameinfo: %s", gai_strerror(gaierr));
if ((gaierr = getnameinfo(ail->ai_addr, ail->ai_addrlen,
- lhbuf, sizeof(lhbuf),
- lsbuf, sizeof(lsbuf),
+ lhbuf, sizeof(lhbuf), lsbuf, sizeof(lsbuf),
NI_NUMERICHOST | NI_NUMERICSERV)) != 0)
errx(1, "getnameinfo: %s", gai_strerror(gaierr));
@@ -89,10 +121,14 @@ main(int argc, char **argv)
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);
-
+ } else {
+ if (aif->ai_family == PF_INET6)
+ printf("[%s]:%s [%s]:%s dropped\n",
+ lhbuf, lsbuf, fhbuf, fsbuf);
+ else
+ printf("%s:%s %s:%s dropped\n",
+ lhbuf, lsbuf, fhbuf, fsbuf);
+ }
}
}
freeaddrinfo(laddr);