diff options
author | Bob Dunlop <bob.dunlop@xyzzy.org.uk> | 2010-10-27 02:12:29 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-27 02:12:29 +0200 |
commit | 55a046b4dbca9df876e9bb67a16dde2ee3d9adb0 (patch) | |
tree | 349e943fbe9440b0a66e2f53d9b122370b11dcb4 | |
parent | 4fa07bd8fafdd5eb64dfe11f43bb420aec5b5f50 (diff) | |
download | busybox-w32-55a046b4dbca9df876e9bb67a16dde2ee3d9adb0.tar.gz busybox-w32-55a046b4dbca9df876e9bb67a16dde2ee3d9adb0.tar.bz2 busybox-w32-55a046b4dbca9df876e9bb67a16dde2ee3d9adb0.zip |
netstat: fix -r display in usage text
Signed-off-by: Bob Dunlop <bob.dunlop@xyzzy.org.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/usage.src.h | 21 | ||||
-rw-r--r-- | networking/netstat.c | 78 |
2 files changed, 50 insertions, 49 deletions
diff --git a/include/usage.src.h b/include/usage.src.h index f5ddd7ba5..2f44eaf81 100644 --- a/include/usage.src.h +++ b/include/usage.src.h | |||
@@ -2721,27 +2721,6 @@ INSERT | |||
2721 | " or\n" \ | 2721 | " or\n" \ |
2722 | "$ nameif -c /etc/my_mactab_file\n" \ | 2722 | "$ nameif -c /etc/my_mactab_file\n" \ |
2723 | 2723 | ||
2724 | #define netstat_trivial_usage \ | ||
2725 | "[-laentuwxr"IF_FEATURE_NETSTAT_WIDE("W")IF_FEATURE_NETSTAT_PRG("p")"]" | ||
2726 | #define netstat_full_usage "\n\n" \ | ||
2727 | "Display networking information\n" \ | ||
2728 | "\nOptions:" \ | ||
2729 | "\n -l Display listening server sockets" \ | ||
2730 | "\n -a Display all sockets (default: connected)" \ | ||
2731 | "\n -e Display other/more information" \ | ||
2732 | "\n -n Don't resolve names" \ | ||
2733 | "\n -t Tcp sockets" \ | ||
2734 | "\n -u Udp sockets" \ | ||
2735 | "\n -w Raw sockets" \ | ||
2736 | "\n -x Unix sockets" \ | ||
2737 | "\n -r Display routing table" \ | ||
2738 | IF_FEATURE_NETSTAT_WIDE( \ | ||
2739 | "\n -W Display with no column truncation" \ | ||
2740 | ) \ | ||
2741 | IF_FEATURE_NETSTAT_PRG( \ | ||
2742 | "\n -p Display PID/Program name for sockets" \ | ||
2743 | ) | ||
2744 | |||
2745 | #define nmeter_trivial_usage \ | 2724 | #define nmeter_trivial_usage \ |
2746 | "format_string" | 2725 | "format_string" |
2747 | #define nmeter_full_usage "\n\n" \ | 2726 | #define nmeter_full_usage "\n\n" \ |
diff --git a/networking/netstat.c b/networking/netstat.c index 3114a3902..4fd8728ce 100644 --- a/networking/netstat.c +++ b/networking/netstat.c | |||
@@ -17,16 +17,37 @@ | |||
17 | #include "libbb.h" | 17 | #include "libbb.h" |
18 | #include "inet_common.h" | 18 | #include "inet_common.h" |
19 | 19 | ||
20 | //usage:#define netstat_trivial_usage | ||
21 | //usage: "[-"IF_ROUTE("r")"al] [-tuwx] [-en"IF_FEATURE_NETSTAT_WIDE("W")IF_FEATURE_NETSTAT_PRG("p")"]" | ||
22 | //usage:#define netstat_full_usage "\n\n" | ||
23 | //usage: "Display networking information\n" | ||
24 | //usage: "\nOptions:" | ||
25 | //usage: IF_ROUTE( | ||
26 | //usage: "\n -r Routing table" | ||
27 | //usage: ) | ||
28 | //usage: "\n -a All sockets" | ||
29 | //usage: "\n -l Listening sockets" | ||
30 | //usage: "\n Else: connected sockets" | ||
31 | //usage: "\n -t TCP sockets" | ||
32 | //usage: "\n -u UDP sockets" | ||
33 | //usage: "\n -w Raw sockets" | ||
34 | //usage: "\n -x Unix sockets" | ||
35 | //usage: "\n Else: all socket types" | ||
36 | //usage: "\n -e Other/more information" | ||
37 | //usage: "\n -n Don't resolve names" | ||
38 | //usage: IF_FEATURE_NETSTAT_WIDE( | ||
39 | //usage: "\n -W Wide display" | ||
40 | //usage: ) | ||
41 | //usage: IF_FEATURE_NETSTAT_PRG( | ||
42 | //usage: "\n -p Show PID/program name for sockets" | ||
43 | //usage: ) | ||
44 | |||
20 | #define NETSTAT_OPTS "laentuwx" \ | 45 | #define NETSTAT_OPTS "laentuwx" \ |
21 | IF_ROUTE( "r") \ | 46 | IF_ROUTE( "r") \ |
22 | IF_FEATURE_NETSTAT_WIDE("W") \ | 47 | IF_FEATURE_NETSTAT_WIDE("W") \ |
23 | IF_FEATURE_NETSTAT_PRG( "p") | 48 | IF_FEATURE_NETSTAT_PRG( "p") |
24 | 49 | ||
25 | enum { | 50 | enum { |
26 | OPTBIT_KEEP_OLD = 7, | ||
27 | IF_ROUTE( OPTBIT_ROUTE,) | ||
28 | IF_FEATURE_NETSTAT_WIDE(OPTBIT_WIDE ,) | ||
29 | IF_FEATURE_NETSTAT_PRG( OPTBIT_PRG ,) | ||
30 | OPT_sock_listen = 1 << 0, // l | 51 | OPT_sock_listen = 1 << 0, // l |
31 | OPT_sock_all = 1 << 1, // a | 52 | OPT_sock_all = 1 << 1, // a |
32 | OPT_extended = 1 << 2, // e | 53 | OPT_extended = 1 << 2, // e |
@@ -35,6 +56,10 @@ enum { | |||
35 | OPT_sock_udp = 1 << 5, // u | 56 | OPT_sock_udp = 1 << 5, // u |
36 | OPT_sock_raw = 1 << 6, // w | 57 | OPT_sock_raw = 1 << 6, // w |
37 | OPT_sock_unix = 1 << 7, // x | 58 | OPT_sock_unix = 1 << 7, // x |
59 | OPTBIT_x = 7, | ||
60 | IF_ROUTE( OPTBIT_ROUTE,) | ||
61 | IF_FEATURE_NETSTAT_WIDE(OPTBIT_WIDE ,) | ||
62 | IF_FEATURE_NETSTAT_PRG( OPTBIT_PRG ,) | ||
38 | OPT_route = IF_ROUTE( (1 << OPTBIT_ROUTE)) + 0, // r | 63 | OPT_route = IF_ROUTE( (1 << OPTBIT_ROUTE)) + 0, // r |
39 | OPT_wide = IF_FEATURE_NETSTAT_WIDE((1 << OPTBIT_WIDE )) + 0, // W | 64 | OPT_wide = IF_FEATURE_NETSTAT_WIDE((1 << OPTBIT_WIDE )) + 0, // W |
40 | OPT_prg = IF_FEATURE_NETSTAT_PRG( (1 << OPTBIT_PRG )) + 0, // p | 65 | OPT_prg = IF_FEATURE_NETSTAT_PRG( (1 << OPTBIT_PRG )) + 0, // p |
@@ -220,7 +245,7 @@ static long extract_socket_inode(const char *lname) | |||
220 | 245 | ||
221 | static int FAST_FUNC file_act(const char *fileName, | 246 | static int FAST_FUNC file_act(const char *fileName, |
222 | struct stat *statbuf UNUSED_PARAM, | 247 | struct stat *statbuf UNUSED_PARAM, |
223 | void *userData, | 248 | void *pid_slash_progname, |
224 | int depth UNUSED_PARAM) | 249 | int depth UNUSED_PARAM) |
225 | { | 250 | { |
226 | char *linkname; | 251 | char *linkname; |
@@ -231,7 +256,7 @@ static int FAST_FUNC file_act(const char *fileName, | |||
231 | inode = extract_socket_inode(linkname); | 256 | inode = extract_socket_inode(linkname); |
232 | free(linkname); | 257 | free(linkname); |
233 | if (inode >= 0) | 258 | if (inode >= 0) |
234 | prg_cache_add(inode, (char *)userData); | 259 | prg_cache_add(inode, (char *)pid_slash_progname); |
235 | } | 260 | } |
236 | return TRUE; | 261 | return TRUE; |
237 | } | 262 | } |
@@ -241,16 +266,16 @@ static int FAST_FUNC dir_act(const char *fileName, | |||
241 | void *userData UNUSED_PARAM, | 266 | void *userData UNUSED_PARAM, |
242 | int depth) | 267 | int depth) |
243 | { | 268 | { |
244 | const char *shortName; | 269 | const char *pid; |
245 | char *p, *q; | 270 | char *p, *pid_slash_progname; |
246 | char cmdline_buf[512]; | 271 | char cmdline_buf[512]; |
247 | int i; | 272 | int i; |
248 | 273 | ||
249 | if (depth == 0) /* "/proc" itself */ | 274 | if (depth == 0) /* "/proc" itself */ |
250 | return TRUE; /* continue looking one level below /proc */ | 275 | return TRUE; /* continue looking one level below /proc */ |
251 | 276 | ||
252 | shortName = fileName + sizeof("/proc/")-1; /* point after "/proc/" */ | 277 | pid = fileName + sizeof("/proc/")-1; /* point after "/proc/" */ |
253 | if (!isdigit(shortName[0])) /* skip /proc entries whic aren't processes */ | 278 | if (!isdigit(pid[0])) /* skip /proc entries which aren't processes */ |
254 | return SKIP; | 279 | return SKIP; |
255 | 280 | ||
256 | p = concat_path_file(fileName, "cmdline"); /* "/proc/PID/cmdline" */ | 281 | p = concat_path_file(fileName, "cmdline"); /* "/proc/PID/cmdline" */ |
@@ -259,20 +284,19 @@ static int FAST_FUNC dir_act(const char *fileName, | |||
259 | if (i < 0) | 284 | if (i < 0) |
260 | return FALSE; | 285 | return FALSE; |
261 | cmdline_buf[i] = '\0'; | 286 | cmdline_buf[i] = '\0'; |
262 | q = concat_path_file(shortName, bb_basename(cmdline_buf)); /* "PID/argv0" */ | ||
263 | 287 | ||
264 | /* go through all files in /proc/PID/fd */ | 288 | /* go through all files in /proc/PID/fd */ |
289 | pid_slash_progname = concat_path_file(pid, bb_basename(cmdline_buf)); /* "PID/argv0" */ | ||
265 | p = concat_path_file(fileName, "fd"); | 290 | p = concat_path_file(fileName, "fd"); |
266 | i = recursive_action(p, ACTION_RECURSE | ACTION_QUIET, | 291 | i = recursive_action(p, ACTION_RECURSE | ACTION_QUIET, |
267 | file_act, NULL, (void *)q, 0); | 292 | file_act, NULL, (void *)pid_slash_progname, 0); |
268 | |||
269 | free(p); | 293 | free(p); |
270 | free(q); | 294 | free(pid_slash_progname); |
271 | 295 | ||
272 | if (!i) | 296 | if (!i) |
273 | return FALSE; /* signal permissions error to caller */ | 297 | return FALSE; /* signal permissions error to caller */ |
274 | 298 | ||
275 | return SKIP; /* caller should not recurse further into this dir. */ | 299 | return SKIP; /* caller should not recurse further into this dir */ |
276 | } | 300 | } |
277 | 301 | ||
278 | static void prg_cache_load(void) | 302 | static void prg_cache_load(void) |
@@ -624,25 +648,23 @@ int netstat_main(int argc UNUSED_PARAM, char **argv) | |||
624 | 648 | ||
625 | /* Option string must match NETSTAT_xxx constants */ | 649 | /* Option string must match NETSTAT_xxx constants */ |
626 | opt = getopt32(argv, NETSTAT_OPTS); | 650 | opt = getopt32(argv, NETSTAT_OPTS); |
627 | if (opt & 0x1) { // -l | 651 | if (opt & OPT_sock_listen) { // -l |
628 | flags &= ~NETSTAT_CONNECTED; | 652 | flags &= ~NETSTAT_CONNECTED; |
629 | flags |= NETSTAT_LISTENING; | 653 | flags |= NETSTAT_LISTENING; |
630 | } | 654 | } |
631 | if (opt & 0x2) flags |= NETSTAT_LISTENING | NETSTAT_CONNECTED; // -a | 655 | if (opt & OPT_sock_all) flags |= NETSTAT_LISTENING | NETSTAT_CONNECTED; // -a |
632 | //if (opt & 0x4) // -e | 656 | //if (opt & OPT_extended) // -e |
633 | if (opt & 0x8) flags |= NETSTAT_NUMERIC; // -n | 657 | if (opt & OPT_noresolve) flags |= NETSTAT_NUMERIC; // -n |
634 | //if (opt & 0x10) // -t: NETSTAT_TCP | 658 | //if (opt & OPT_sock_tcp) // -t: NETSTAT_TCP |
635 | //if (opt & 0x20) // -u: NETSTAT_UDP | 659 | //if (opt & OPT_sock_udp) // -u: NETSTAT_UDP |
636 | //if (opt & 0x40) // -w: NETSTAT_RAW | 660 | //if (opt & OPT_sock_raw) // -w: NETSTAT_RAW |
637 | //if (opt & 0x80) // -x: NETSTAT_UNIX | 661 | //if (opt & OPT_sock_unix) // -x: NETSTAT_UNIX |
638 | if (opt & OPT_route) { // -r | ||
639 | #if ENABLE_ROUTE | 662 | #if ENABLE_ROUTE |
663 | if (opt & OPT_route) { // -r | ||
640 | bb_displayroutes(flags & NETSTAT_NUMERIC, !(opt & OPT_extended)); | 664 | bb_displayroutes(flags & NETSTAT_NUMERIC, !(opt & OPT_extended)); |
641 | return 0; | 665 | return 0; |
642 | #else | ||
643 | bb_show_usage(); | ||
644 | #endif | ||
645 | } | 666 | } |
667 | #endif | ||
646 | if (opt & OPT_wide) { // -W | 668 | if (opt & OPT_wide) { // -W |
647 | net_conn_line = PRINT_NET_CONN_WIDE; | 669 | net_conn_line = PRINT_NET_CONN_WIDE; |
648 | net_conn_line_header = PRINT_NET_CONN_HEADER_WIDE; | 670 | net_conn_line_header = PRINT_NET_CONN_HEADER_WIDE; |