[PATCH] Allow tcpdrop to use non-space separators

John Baldwin jhb at freebsd.org
Wed Jan 30 16:30:46 UTC 2013


On Tuesday, January 29, 2013 6:17:03 pm Luigi Rizzo wrote:
> On Tue, Jan 29, 2013 at 3:11 PM, Andre Oppermann <andre at freebsd.org> wrote:
> 
> > On 29.01.2013 18:05, John Baldwin wrote:
> >
> >> A common use case I have at work is to find a busted connection using
> >> netstat
> >> -n or sockstat and then want to tcpdrop it.  However, tcpdrop requires
> >> spaces
> >> between the address and port so I can't simply cut and paste from one
> >> terminal
> >> window into another to generate the tcpdrop command.  This patch adds
> >> support
> >> for having a decimal (netstat output) or colon (sockstat output) between
> >> the
> >> address and port instead of a space.  It is careful to look for the last
> >> of
> >> these tokens to avoid parsing part of the address as the port.
> >>
> >
> > Excellent.  Can netstat be changed from decimal to colon output as well?
> > The decimal output is completely outdated and probably from a time when
> > not even dinosaurs were [created|evolved] yet.  Colon output for port
> > numbers is *the* standard all around.

I'd be nervous about breaking scripts if we change the netstat output.  Also, 
in the case of IPv6 the period is actually better than the colon for 
readability.

> i was going to say i'd really love to have the parsing code in some kind of
> library function. I find myself writing this code again and again (and
> presumably
> i am not the only one) each time with new bugs and features...
> 
> i know that non-standard library functions are a pain when porting software
> (see humanize_* stuff) but better than duplication.

Actually, if we had a reverse version of either strspn or strpbrk then it 
would be trivial to write this.

-- 
John Baldwin


More information about the freebsd-net mailing list