[patch] netstat -W (wide) option
Denis Vlasenko
vda.linux at googlemail.com
Wed May 16 15:25:06 PDT 2007
On Wednesday 16 May 2007 11:21, Cristian Ionescu-Idbohrn wrote:
> On Wed, 16 May 2007, Denis Vlasenko wrote:
>
> > Thanks! Applying, with attached patch on top
> > (further shringk by ~180 bytes + fix for bogus state
> > value for raw sockets)
>
> Thank you!
> Unfortunatelly, a small bug crept in :(
>
> At this point in the code 'opt' has one value:
>
> 532 if (opt & OPT_widedisplay) { // -W
>
> but 'opt' is modified on the way, and by the time it reaches this
> point:
>
> 550 printf((opt & OPT_widedisplay) ? PRINT_NET_CONN_HEADER_WIDE : PRINT_NET_CONN_HEADER,
>
> 'opt' has another value; '(opt & OPT_widedisplay)' evaluates to 0 and
> a short line (instead of a wide) is printed.
Yes. My bad.
> The attatched patch solves the problem, but it also adds 15 bytes :(
15 bytes is not a problem. I'd rather try to avoid having global variables
unless I have to. I will apply this to svn in a few minutes:
--- networking/netstat.c (revision 18636)
+++ networking/netstat.c (working copy)
@@ -499,6 +499,7 @@
int netstat_main(int argc, char **argv);
int netstat_main(int argc, char **argv)
{
+ const char *net_conn_line_header = PRINT_NET_CONN_HEADER;
unsigned opt;
#if ENABLE_FEATURE_IPV6
smallint inet = 1;
@@ -531,6 +532,7 @@
if (opt & OPT_widedisplay) { // -W
net_conn_line = PRINT_NET_CONN_WIDE;
+ net_conn_line_header = PRINT_NET_CONN_HEADER_WIDE;
}
opt &= NETSTAT_ALLPROTO;
@@ -547,8 +549,7 @@
printf("(only servers)");
else
printf("(w/o servers)");
- printf((opt & OPT_widedisplay) ? PRINT_NET_CONN_HEADER_WIDE : PRINT_NET_CONN_HEADER,
- "Local Address", "Foreign Address");
+ printf(net_conn_line_header, "Local Address", "Foreign Address");
}
if (inet && flags & NETSTAT_TCP)
do_info(_PATH_PROCNET_TCP, "AF INET (tcp)", tcp_do_one);
Thanks!
--
vda
More information about the busybox
mailing list