summaryrefslogtreecommitdiff
path: root/usr.sbin/tcpdrop
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2023-02-06 18:14:11 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2023-02-06 18:14:11 +0000
commit0914769a7753cbf69c0c95c31608c8dff78f0602 (patch)
treebd74b200f15b893754e2436f8f4e090f73461063 /usr.sbin/tcpdrop
parent6a782d5611425deac74f9d1cffeb29b4da2b2bde (diff)
Accept netstat-style address.port syntax too.
OK bluhm@ deraadt@ jmc@
Diffstat (limited to 'usr.sbin/tcpdrop')
-rw-r--r--usr.sbin/tcpdrop/tcpdrop.821
-rw-r--r--usr.sbin/tcpdrop/tcpdrop.c13
2 files changed, 25 insertions, 9 deletions
diff --git a/usr.sbin/tcpdrop/tcpdrop.8 b/usr.sbin/tcpdrop/tcpdrop.8
index dbe7ef1ab2b..54efa706cc4 100644
--- a/usr.sbin/tcpdrop/tcpdrop.8
+++ b/usr.sbin/tcpdrop/tcpdrop.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tcpdrop.8,v 1.13 2014/08/28 08:22:42 jmc Exp $
+.\" $OpenBSD: tcpdrop.8,v 1.14 2023/02/06 18:14:10 millert Exp $
.\"
.\" Copyright (c) 2004 Markus Friedl <markus@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: August 28 2014 $
+.Dd $Mdocdate: February 6 2023 $
.Dt TCPDROP 8
.Os
.Sh NAME
@@ -26,9 +26,6 @@
.Ar local-port
.Ar remote-addr
.Ar remote-port
-.Nm tcpdrop
-.Ar local-addr : Ns Ar local-port
-.Ar remote-addr : Ns Ar remote-port
.Sh DESCRIPTION
The
.Nm
@@ -41,6 +38,18 @@ and the foreign address
port
.Ar remote-port .
Addresses and ports can be specified by name or numeric value.
+.Pp
+To simplify dropping TCP connections using the output of
+.Xr fstat 1
+and
+.Xr netstat 1 ,
+.Nm
+also supports a two-argument form where the address and port are
+separated by a colon
+.Pq Sq \&:
+or dot
+.Pq Sq \&.
+character.
.Sh EXAMPLES
If a connection to
.Xr httpd 8
@@ -57,6 +66,8 @@ Either of the following commands will drop the connection:
# tcpdrop 192.168.5.41 80 192.168.5.1 26747
# 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 70feea0a995..a3b3e999859 100644
--- a/usr.sbin/tcpdrop/tcpdrop.c
+++ b/usr.sbin/tcpdrop/tcpdrop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcpdrop.c,v 1.20 2021/07/12 15:09:21 beck Exp $ */
+/* $OpenBSD: tcpdrop.c,v 1.21 2023/02/06 18:14:10 millert Exp $ */
/*
* Copyright (c) 2004 Markus Friedl <markus@openbsd.org>
@@ -44,9 +44,6 @@ usage(void)
fprintf(stderr,
"usage: %s local-addr local-port remote-addr remote-port\n",
__progname);
- fprintf(stderr,
- " %s local-addr:local-port remote-addr:remote-port\n",
- __progname);
exit(1);
}
@@ -76,10 +73,15 @@ main(int argc, char **argv)
hints.ai_socktype = SOCK_STREAM;
if (argc == 3) {
+ char *dot;
+
laddr1 = addr1 = strdup(argv[1]);
if (!addr1)
err(1, "strdup");
port1 = strrchr(addr1, ':');
+ dot = strrchr(addr1, '.');
+ if (dot > port1)
+ port1 = dot;
if (port1)
*port1++ = '\0';
else
@@ -89,6 +91,9 @@ main(int argc, char **argv)
if (!addr2)
err(1, "strdup");
port2 = strrchr(addr2, ':');
+ dot = strrchr(addr2, '.');
+ if (dot > port2)
+ port2 = dot;
if (port2)
*port2++ = '\0';
else