# $Id: openbsd-tcpdrop_netstat_output.diff,v 1.1 2008/12/16 22:19:58 jcs Exp $ # # make tcpdrop(8) able to parse output from netstat(1), which # separates things by dots. # # jcs@openbsd.org # Index: tcpdrop.8 =================================================================== RCS file: /cvs/src/usr.sbin/tcpdrop/tcpdrop.8,v retrieving revision 1.10 diff -u -p -r1.10 tcpdrop.8 --- tcpdrop.8 2 Jul 2007 09:52:08 -0000 1.10 +++ tcpdrop.8 16 Dec 2008 22:14:49 -0000 @@ -52,11 +52,13 @@ www httpd 21307 3* internet 0xd1007ca8 192.168.5.41:80 \*(Lt-- 192.168.5.1:26747 .Ed .Pp -Either of the following commands will drop the connection: +Any 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 + +# tcpdrop 192.168.5.41.80 192.168.5.1.26747 .Ed .Sh SEE ALSO .Xr fstat 1 , Index: tcpdrop.c =================================================================== RCS file: /cvs/src/usr.sbin/tcpdrop/tcpdrop.c,v retrieving revision 1.7 diff -u -p -r1.7 tcpdrop.c --- tcpdrop.c 28 Mar 2007 17:04:03 -0000 1.7 +++ tcpdrop.c 16 Dec 2008 22:14:49 -0000 @@ -44,9 +44,9 @@ 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; + char *laddr1, *addr1, *port1, *laddr2, *addr2, *port2, *dot; struct tcp_ident_mapping tir; - int gaierr, rval = 0; + int dotc, gaierr, rval = 0; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; @@ -57,15 +57,39 @@ main(int argc, char **argv) port1 = strrchr(addr1, ':'); if (port1) *port1++ = '\0'; - else - goto fail; + else { + dotc = 0; + dot = strchr(laddr1, '.'); + while (dot) { + dotc++; + dot = strchr(dot + 1, '.'); + } + + if (dotc == 4) { + port1 = strrchr(addr1, '.'); + *port1++ = '\0'; + } else + goto fail; + } laddr2 = addr2 = strdup(argv[2]); port2 = strrchr(addr2, ':'); if (port2) *port2++ = '\0'; - else - goto fail; + else { + dotc = 0; + dot = strchr(laddr2, '.'); + while (dot) { + dotc++; + dot = strchr(dot + 1, '.'); + } + + if (dotc == 4) { + port2 = strrchr(addr2, '.'); + *port2++ = '\0'; + } else + goto fail; + } } else if (argc == 5) { laddr1 = addr1 = argv[1]; port1 = argv[2]; @@ -78,6 +102,9 @@ fail: __progname); fprintf(stderr, " %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); }