diff options
author | obrien <obrien@FreeBSD.org> | 2013-02-08 16:10:16 +0000 |
---|---|---|
committer | obrien <obrien@FreeBSD.org> | 2013-02-08 16:10:16 +0000 |
commit | 3028e3f8aba938dfd0bf9fda987b8a72140b8027 (patch) | |
tree | b2f038222ff8a70f687652441df00d2b564c8abe /usr.sbin/tcpdrop | |
parent | 952a6d5a7cd3d3f9007acfa06805262fc04a105f (diff) | |
parent | 1d08d5f677c1dfa810e381073590adbae19cc69f (diff) | |
download | FreeBSD-src-3028e3f8aba938dfd0bf9fda987b8a72140b8027.zip FreeBSD-src-3028e3f8aba938dfd0bf9fda987b8a72140b8027.tar.gz |
Sync with HEAD.
Diffstat (limited to 'usr.sbin/tcpdrop')
-rw-r--r-- | usr.sbin/tcpdrop/tcpdrop.8 | 5 | ||||
-rw-r--r-- | usr.sbin/tcpdrop/tcpdrop.c | 38 |
2 files changed, 39 insertions, 4 deletions
diff --git a/usr.sbin/tcpdrop/tcpdrop.8 b/usr.sbin/tcpdrop/tcpdrop.8 index 93bfe8e..9649dec 100644 --- a/usr.sbin/tcpdrop/tcpdrop.8 +++ b/usr.sbin/tcpdrop/tcpdrop.8 @@ -17,7 +17,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 24, 2009 +.Dd January 30, 2013 .Dt TCPDROP 8 .Os .Sh NAME @@ -62,6 +62,9 @@ will be dropped. .Pp Addresses and ports may be specified by name or numeric value. Both IPv4 and IPv6 address formats are supported. +.Pp +The addresses and ports may be separated by periods or colons +instead of spaces. .Sh EXIT STATUS .Ex -std .Sh EXAMPLES diff --git a/usr.sbin/tcpdrop/tcpdrop.c b/usr.sbin/tcpdrop/tcpdrop.c index dce6c6d..ef3f6bd 100644 --- a/usr.sbin/tcpdrop/tcpdrop.c +++ b/usr.sbin/tcpdrop/tcpdrop.c @@ -50,6 +50,7 @@ struct host_service { static bool tcpdrop_list_commands = false; +static char *findport(const char *); static struct xinpgen *getxpcblist(const char *); static void sockinfo(const struct sockaddr *, struct host_service *); static bool tcpdrop(const struct sockaddr *, const struct sockaddr *); @@ -65,6 +66,7 @@ static void usage(void); int main(int argc, char *argv[]) { + char *lport, *fport; bool dropall; int ch; @@ -93,15 +95,43 @@ main(int argc, char *argv[]) exit(0); } - if (argc != 4 || tcpdrop_list_commands) + if ((argc != 2 && argc != 4) || tcpdrop_list_commands) usage(); - if (!tcpdropbyname(argv[0], argv[1], argv[2], argv[3])) + if (argc == 2) { + lport = findport(argv[0]); + fport = findport(argv[1]); + if (lport == NULL || lport[1] == '\0' || fport == NULL || + fport[1] == '\0') + usage(); + *lport++ = '\0'; + *fport++ = '\0'; + if (!tcpdropbyname(argv[0], lport, argv[1], fport)) + exit(1); + } else if (!tcpdropbyname(argv[0], argv[1], argv[2], argv[3])) exit(1); exit(0); } +static char * +findport(const char *arg) +{ + char *dot, *colon; + + /* A strrspn() or strrpbrk() would be nice. */ + dot = strrchr(arg, '.'); + colon = strrchr(arg, ':'); + if (dot == NULL) + return (colon); + if (colon == NULL) + return (dot); + if (dot < colon) + return (colon); + else + return (dot); +} + static struct xinpgen * getxpcblist(const char *name) { @@ -237,7 +267,7 @@ tcpdropbyname(const char *lhost, const char *lport, const char *fhost, error = getaddrinfo(fhost, fport, &hints, &foreign); if (error != 0) { freeaddrinfo(local); /* XXX gratuitous */ - errx(1, "getaddrinfo: %s port %s: %s", lhost, lport, + errx(1, "getaddrinfo: %s port %s: %s", fhost, fport, gai_strerror(error)); } @@ -318,6 +348,8 @@ usage(void) { fprintf(stderr, "usage: tcpdrop local-address local-port foreign-address foreign-port\n" +" tcpdrop local-address:local-port foreign-address:foreign-port\n" +" tcpdrop local-address.local-port foreign-address.foreign-port\n" " tcpdrop [-l] -a\n"); exit(1); } |