source: branches/stable/mindi-busybox/networking/netstat.c @ 1770

Last change on this file since 1770 was 1770, checked in by Bruno Cornec, 13 years ago
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod? silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian? keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René? Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File size: 14.6 KB
Line 
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini netstat implementation(s) for busybox
4 * based in part on the netstat implementation from net-tools.
5 *
6 * Copyright (C) 2002 by Bart Visscher <magick@linux-fan.com>
7 *
8 * 2002-04-20
9 * IPV6 support added by Bart Visscher <magick@linux-fan.com>
10 *
11 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
12 */
13
14#include "libbb.h"
15#include "inet_common.h"
16
17enum {
18    OPT_extended = 0x4,
19    OPT_showroute = 0x100,
20    OPT_widedisplay = 0x200 * ENABLE_FEATURE_NETSTAT_WIDE,
21};
22# define NETSTAT_OPTS "laentuwxr"USE_FEATURE_NETSTAT_WIDE("W")
23
24#define NETSTAT_CONNECTED 0x01
25#define NETSTAT_LISTENING 0x02
26#define NETSTAT_NUMERIC   0x04
27/* Must match getopt32 option string */
28#define NETSTAT_TCP       0x10
29#define NETSTAT_UDP       0x20
30#define NETSTAT_RAW       0x40
31#define NETSTAT_UNIX      0x80
32#define NETSTAT_ALLPROTO  (NETSTAT_TCP|NETSTAT_UDP|NETSTAT_RAW|NETSTAT_UNIX)
33
34static smallint flags = NETSTAT_CONNECTED | NETSTAT_ALLPROTO;
35
36enum {
37    TCP_ESTABLISHED = 1,
38    TCP_SYN_SENT,
39    TCP_SYN_RECV,
40    TCP_FIN_WAIT1,
41    TCP_FIN_WAIT2,
42    TCP_TIME_WAIT,
43    TCP_CLOSE,
44    TCP_CLOSE_WAIT,
45    TCP_LAST_ACK,
46    TCP_LISTEN,
47    TCP_CLOSING /* now a valid state */
48};
49
50static const char *const tcp_state[] = {
51    "",
52    "ESTABLISHED",
53    "SYN_SENT",
54    "SYN_RECV",
55    "FIN_WAIT1",
56    "FIN_WAIT2",
57    "TIME_WAIT",
58    "CLOSE",
59    "CLOSE_WAIT",
60    "LAST_ACK",
61    "LISTEN",
62    "CLOSING"
63};
64
65typedef enum {
66    SS_FREE = 0,     /* not allocated                */
67    SS_UNCONNECTED,  /* unconnected to any socket    */
68    SS_CONNECTING,   /* in process of connecting     */
69    SS_CONNECTED,    /* connected to socket          */
70    SS_DISCONNECTING /* in process of disconnecting  */
71} socket_state;
72
73#define SO_ACCEPTCON (1<<16)    /* performed a listen           */
74#define SO_WAITDATA  (1<<17)    /* wait data to read            */
75#define SO_NOSPACE   (1<<18)    /* no space to write            */
76
77/* Standard printout size */
78#define PRINT_IP_MAX_SIZE           23
79#define PRINT_NET_CONN              "%s   %6ld %6ld %-23s %-23s %-12s\n"
80#define PRINT_NET_CONN_HEADER       "\nProto Recv-Q Send-Q %-23s %-23s State\n"
81
82/* When there are IPv6 connections the IPv6 addresses will be
83 * truncated to none-recognition. The '-W' option makes the
84 * address columns wide enough to accomodate for longest possible
85 * IPv6 addresses, i.e. addresses of the form
86 * xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:ddd.ddd.ddd.ddd
87 */
88#define PRINT_IP_MAX_SIZE_WIDE      51  /* INET6_ADDRSTRLEN + 5 for the port number */
89#define PRINT_NET_CONN_WIDE         "%s   %6ld %6ld %-51s %-51s %-12s\n"
90#define PRINT_NET_CONN_HEADER_WIDE  "\nProto Recv-Q Send-Q %-51s %-51s State\n"
91
92static const char *net_conn_line = PRINT_NET_CONN;
93
94
95#if ENABLE_FEATURE_IPV6
96static void build_ipv6_addr(char* local_addr, struct sockaddr_in6* localaddr)
97{
98    char addr6[INET6_ADDRSTRLEN];
99    struct in6_addr in6;
100
101    sscanf(local_addr, "%08X%08X%08X%08X",
102           &in6.s6_addr32[0], &in6.s6_addr32[1],
103           &in6.s6_addr32[2], &in6.s6_addr32[3]);
104    inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6));
105    inet_pton(AF_INET6, addr6, (struct sockaddr *) &localaddr->sin6_addr);
106
107    localaddr->sin6_family = AF_INET6;
108}
109#endif
110
111#if ENABLE_FEATURE_IPV6
112static void build_ipv4_addr(char* local_addr, struct sockaddr_in6* localaddr)
113#else
114static void build_ipv4_addr(char* local_addr, struct sockaddr_in* localaddr)
115#endif
116{
117    sscanf(local_addr, "%X",
118           &((struct sockaddr_in *) localaddr)->sin_addr.s_addr);
119    ((struct sockaddr *) localaddr)->sa_family = AF_INET;
120}
121
122static const char *get_sname(int port, const char *proto, int numeric)
123{
124    if (!port)
125        return "*";
126    if (!numeric) {
127        struct servent *se = getservbyport(port, proto);
128        if (se)
129            return se->s_name;
130    }
131    /* hummm, we may return static buffer here!! */
132    return itoa(ntohs(port));
133}
134
135static char *ip_port_str(struct sockaddr *addr, int port, const char *proto, int numeric)
136{
137    enum { salen = USE_FEATURE_IPV6(sizeof(struct sockaddr_in6)) SKIP_FEATURE_IPV6(sizeof(struct sockaddr_in)) };
138    char *host, *host_port;
139
140    /* Code which used "*" for INADDR_ANY is removed: it's ambiguous in IPv6,
141     * while "0.0.0.0" is not. */
142
143    host = numeric ? xmalloc_sockaddr2dotted_noport(addr)
144                   : xmalloc_sockaddr2host_noport(addr);
145
146    host_port = xasprintf("%s:%s", host, get_sname(htons(port), proto, numeric));
147    free(host);
148    return host_port;
149}
150
151static void tcp_do_one(int lnr, const char *line)
152{
153    char local_addr[64], rem_addr[64];
154    char more[512];
155    int num, local_port, rem_port, d, state, timer_run, uid, timeout;
156#if ENABLE_FEATURE_IPV6
157    struct sockaddr_in6 localaddr, remaddr;
158#else
159    struct sockaddr_in localaddr, remaddr;
160#endif
161    unsigned long rxq, txq, time_len, retr, inode;
162
163    if (lnr == 0)
164        return;
165
166    more[0] = '\0';
167    num = sscanf(line,
168            "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
169            &d, local_addr, &local_port,
170            rem_addr, &rem_port, &state,
171            &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
172
173    if (strlen(local_addr) > 8) {
174#if ENABLE_FEATURE_IPV6
175        build_ipv6_addr(local_addr, &localaddr);
176        build_ipv6_addr(rem_addr, &remaddr);
177#endif
178    } else {
179        build_ipv4_addr(local_addr, &localaddr);
180        build_ipv4_addr(rem_addr, &remaddr);
181    }
182
183    if (num < 10) {
184        bb_error_msg("warning, got bogus tcp line");
185        return;
186    }
187
188    if ((rem_port && (flags & NETSTAT_CONNECTED))
189     || (!rem_port && (flags & NETSTAT_LISTENING))
190    ) {
191        char *l = ip_port_str(
192                (struct sockaddr *) &localaddr, local_port,
193                "tcp", flags & NETSTAT_NUMERIC);
194        char *r = ip_port_str(
195                (struct sockaddr *) &remaddr, rem_port,
196                "tcp", flags & NETSTAT_NUMERIC);
197        printf(net_conn_line,
198            "tcp", rxq, txq, l, r, tcp_state[state]);
199        free(l);
200        free(r);
201    }
202}
203
204static void udp_do_one(int lnr, const char *line)
205{
206    char local_addr[64], rem_addr[64];
207    const char *state_str;
208    char more[512];
209    int num, local_port, rem_port, d, state, timer_run, uid, timeout;
210#if ENABLE_FEATURE_IPV6
211    struct sockaddr_in6 localaddr, remaddr;
212#else
213    struct sockaddr_in localaddr, remaddr;
214#endif
215    unsigned long rxq, txq, time_len, retr, inode;
216
217    if (lnr == 0)
218        return;
219
220    more[0] = '\0';
221    num = sscanf(line,
222            "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
223            &d, local_addr, &local_port,
224            rem_addr, &rem_port, &state,
225            &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
226
227    if (strlen(local_addr) > 8) {
228#if ENABLE_FEATURE_IPV6
229        /* Demangle what the kernel gives us */
230        build_ipv6_addr(local_addr, &localaddr);
231        build_ipv6_addr(rem_addr, &remaddr);
232#endif
233    } else {
234        build_ipv4_addr(local_addr, &localaddr);
235        build_ipv4_addr(rem_addr, &remaddr);
236    }
237
238    if (num < 10) {
239        bb_error_msg("warning, got bogus udp line");
240        return;
241    }
242    switch (state) {
243        case TCP_ESTABLISHED:
244            state_str = "ESTABLISHED";
245            break;
246        case TCP_CLOSE:
247            state_str = "";
248            break;
249        default:
250            state_str = "UNKNOWN";
251            break;
252    }
253
254#if ENABLE_FEATURE_IPV6
255# define notnull(A) ( \
256    ( (A.sin6_family == AF_INET6)                               \
257      && (A.sin6_addr.s6_addr32[0] | A.sin6_addr.s6_addr32[1] | \
258          A.sin6_addr.s6_addr32[2] | A.sin6_addr.s6_addr32[3])  \
259    ) || (                                                      \
260      (A.sin6_family == AF_INET)                                \
261      && ((struct sockaddr_in*)&A)->sin_addr.s_addr             \
262    )                                                           \
263)
264#else
265# define notnull(A) (A.sin_addr.s_addr)
266#endif
267    {
268        int have_remaddr = notnull(remaddr);
269        if ((have_remaddr && (flags & NETSTAT_CONNECTED))
270         || (!have_remaddr && (flags & NETSTAT_LISTENING))
271        ) {
272            char *l = ip_port_str(
273                (struct sockaddr *) &localaddr, local_port,
274                "udp", flags & NETSTAT_NUMERIC);
275            char *r = ip_port_str(
276                (struct sockaddr *) &remaddr, rem_port,
277                "udp", flags & NETSTAT_NUMERIC);
278            printf(net_conn_line,
279                "udp", rxq, txq, l, r, state_str);
280            free(l);
281            free(r);
282        }
283    }
284}
285
286static void raw_do_one(int lnr, const char *line)
287{
288    char local_addr[64], rem_addr[64];
289    char more[512];
290    int num, local_port, rem_port, d, state, timer_run, uid, timeout;
291#if ENABLE_FEATURE_IPV6
292    struct sockaddr_in6 localaddr, remaddr;
293#else
294    struct sockaddr_in localaddr, remaddr;
295#endif
296    unsigned long rxq, txq, time_len, retr, inode;
297
298    if (lnr == 0)
299        return;
300
301    more[0] = '\0';
302    num = sscanf(line,
303            "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
304            &d, local_addr, &local_port,
305            rem_addr, &rem_port, &state,
306            &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
307
308    if (strlen(local_addr) > 8) {
309#if ENABLE_FEATURE_IPV6
310        build_ipv6_addr(local_addr, &localaddr);
311        build_ipv6_addr(rem_addr, &remaddr);
312#endif
313    } else {
314        build_ipv4_addr(local_addr, &localaddr);
315        build_ipv4_addr(rem_addr, &remaddr);
316    }
317
318    if (num < 10) {
319        bb_error_msg("warning, got bogus raw line");
320        return;
321    }
322
323    {
324        int have_remaddr = notnull(remaddr);
325        if ((have_remaddr && (flags & NETSTAT_CONNECTED))
326         || (!have_remaddr && (flags & NETSTAT_LISTENING))
327        ) {
328            char *l = ip_port_str(
329                (struct sockaddr *) &localaddr, local_port,
330                "raw", flags & NETSTAT_NUMERIC);
331            char *r = ip_port_str(
332                (struct sockaddr *) &remaddr, rem_port,
333                "raw", flags & NETSTAT_NUMERIC);
334            printf(net_conn_line,
335                "raw", rxq, txq, l, r, itoa(state));
336            free(l);
337            free(r);
338        }
339    }
340}
341
342static void unix_do_one(int nr, const char *line)
343{
344    static smallint has_inode = 0;
345
346    char path[PATH_MAX], ss_flags[32];
347    const char *ss_proto, *ss_state, *ss_type;
348    int num, state, type, inode;
349    void *d;
350    unsigned long refcnt, proto, unix_flags;
351
352    if (nr == 0) {
353        if (strstr(line, "Inode"))
354            has_inode = 1;
355        return;
356    }
357    path[0] = '\0';
358    num = sscanf(line, "%p: %lX %lX %lX %X %X %d %s",
359            &d, &refcnt, &proto, &unix_flags, &type, &state, &inode, path);
360    if (num < 6) {
361        bb_error_msg("warning, got bogus unix line");
362        return;
363    }
364    if (!has_inode)
365        sprintf(path, "%d", inode);
366
367    if ((flags & (NETSTAT_LISTENING|NETSTAT_CONNECTED)) != (NETSTAT_LISTENING|NETSTAT_CONNECTED)) {
368        if ((state == SS_UNCONNECTED) && (unix_flags & SO_ACCEPTCON)) {
369            if (!(flags & NETSTAT_LISTENING))
370                return;
371        } else {
372            if (!(flags & NETSTAT_CONNECTED))
373                return;
374        }
375    }
376
377    switch (proto) {
378        case 0:
379            ss_proto = "unix";
380            break;
381        default:
382            ss_proto = "??";
383    }
384
385    switch (type) {
386        case SOCK_STREAM:
387            ss_type = "STREAM";
388            break;
389        case SOCK_DGRAM:
390            ss_type = "DGRAM";
391            break;
392        case SOCK_RAW:
393            ss_type = "RAW";
394            break;
395        case SOCK_RDM:
396            ss_type = "RDM";
397            break;
398        case SOCK_SEQPACKET:
399            ss_type = "SEQPACKET";
400            break;
401        default:
402            ss_type = "UNKNOWN";
403    }
404
405    switch (state) {
406        case SS_FREE:
407            ss_state = "FREE";
408            break;
409        case SS_UNCONNECTED:
410            /*
411             * Unconnected sockets may be listening
412             * for something.
413             */
414            if (unix_flags & SO_ACCEPTCON) {
415                ss_state = "LISTENING";
416            } else {
417                ss_state = "";
418            }
419            break;
420        case SS_CONNECTING:
421            ss_state = "CONNECTING";
422            break;
423        case SS_CONNECTED:
424            ss_state = "CONNECTED";
425            break;
426        case SS_DISCONNECTING:
427            ss_state = "DISCONNECTING";
428            break;
429        default:
430            ss_state = "UNKNOWN";
431    }
432
433    strcpy(ss_flags, "[ ");
434    if (unix_flags & SO_ACCEPTCON)
435        strcat(ss_flags, "ACC ");
436    if (unix_flags & SO_WAITDATA)
437        strcat(ss_flags, "W ");
438    if (unix_flags & SO_NOSPACE)
439        strcat(ss_flags, "N ");
440    strcat(ss_flags, "]");
441
442    printf("%-5s %-6ld %-11s %-10s %-13s ",
443           ss_proto, refcnt, ss_flags, ss_type, ss_state);
444    if (has_inode)
445        printf("%-6d ", inode);
446    else
447        printf("-      ");
448    puts(path);
449}
450
451#define _PATH_PROCNET_UDP "/proc/net/udp"
452#define _PATH_PROCNET_UDP6 "/proc/net/udp6"
453#define _PATH_PROCNET_TCP "/proc/net/tcp"
454#define _PATH_PROCNET_TCP6 "/proc/net/tcp6"
455#define _PATH_PROCNET_RAW "/proc/net/raw"
456#define _PATH_PROCNET_RAW6 "/proc/net/raw6"
457#define _PATH_PROCNET_UNIX "/proc/net/unix"
458
459static void do_info(const char *file, const char *name, void (*proc)(int, const char *))
460{
461    int lnr = 0;
462    FILE *procinfo;
463
464    procinfo = fopen(file, "r");
465    if (procinfo == NULL) {
466        if (errno != ENOENT) {
467            bb_perror_msg("%s", file);
468        } else {
469            bb_error_msg("no support for '%s' on this system", name);
470        }
471        return;
472    }
473    do {
474        char *buffer = xmalloc_fgets(procinfo);
475        if (buffer) {
476            (proc)(lnr++, buffer);
477            free(buffer);
478        }
479    } while (!feof(procinfo));
480    fclose(procinfo);
481}
482
483/*
484 * Our main function.
485 */
486
487int netstat_main(int argc, char **argv);
488int netstat_main(int argc, char **argv)
489{
490    const char *net_conn_line_header = PRINT_NET_CONN_HEADER;
491    unsigned opt;
492#if ENABLE_FEATURE_IPV6
493    smallint inet = 1;
494    smallint inet6 = 1;
495#else
496    enum { inet = 1, inet6 = 0 };
497#endif
498
499    /* Option string must match NETSTAT_xxx constants */
500    opt = getopt32(argv, NETSTAT_OPTS);
501    if (opt & 0x1) { // -l
502        flags &= ~NETSTAT_CONNECTED;
503        flags |= NETSTAT_LISTENING;
504    }
505    if (opt & 0x2) flags |= NETSTAT_LISTENING | NETSTAT_CONNECTED; // -a
506    //if (opt & 0x4) // -e
507    if (opt & 0x8) flags |= NETSTAT_NUMERIC; // -n
508    //if (opt & 0x10) // -t: NETSTAT_TCP
509    //if (opt & 0x20) // -u: NETSTAT_UDP
510    //if (opt & 0x40) // -w: NETSTAT_RAW
511    //if (opt & 0x80) // -x: NETSTAT_UNIX
512    if (opt & OPT_showroute) { // -r
513#if ENABLE_ROUTE
514        bb_displayroutes(flags & NETSTAT_NUMERIC, !(opt & OPT_extended));
515        return 0;
516#else
517        bb_show_usage();
518#endif
519    }
520
521    if (opt & OPT_widedisplay) { // -W
522        net_conn_line = PRINT_NET_CONN_WIDE;
523        net_conn_line_header = PRINT_NET_CONN_HEADER_WIDE;
524    }
525
526    opt &= NETSTAT_ALLPROTO;
527    if (opt) {
528        flags &= ~NETSTAT_ALLPROTO;
529        flags |= opt;
530    }
531    if (flags & (NETSTAT_TCP|NETSTAT_UDP|NETSTAT_RAW)) {
532        printf("Active Internet connections "); /* xxx */
533
534        if ((flags & (NETSTAT_LISTENING|NETSTAT_CONNECTED)) == (NETSTAT_LISTENING|NETSTAT_CONNECTED))
535            printf("(servers and established)");
536        else if (flags & NETSTAT_LISTENING)
537            printf("(only servers)");
538        else
539            printf("(w/o servers)");
540        printf(net_conn_line_header, "Local Address", "Foreign Address");
541    }
542    if (inet && flags & NETSTAT_TCP)
543        do_info(_PATH_PROCNET_TCP, "AF INET (tcp)", tcp_do_one);
544#if ENABLE_FEATURE_IPV6
545    if (inet6 && flags & NETSTAT_TCP)
546        do_info(_PATH_PROCNET_TCP6, "AF INET6 (tcp)", tcp_do_one);
547#endif
548    if (inet && flags & NETSTAT_UDP)
549        do_info(_PATH_PROCNET_UDP, "AF INET (udp)", udp_do_one);
550#if ENABLE_FEATURE_IPV6
551    if (inet6 && flags & NETSTAT_UDP)
552        do_info(_PATH_PROCNET_UDP6, "AF INET6 (udp)", udp_do_one);
553#endif
554    if (inet && flags & NETSTAT_RAW)
555        do_info(_PATH_PROCNET_RAW, "AF INET (raw)", raw_do_one);
556#if ENABLE_FEATURE_IPV6
557    if (inet6 && flags & NETSTAT_RAW)
558        do_info(_PATH_PROCNET_RAW6, "AF INET6 (raw)", raw_do_one);
559#endif
560    if (flags & NETSTAT_UNIX) {
561        printf("Active UNIX domain sockets ");
562        if ((flags & (NETSTAT_LISTENING|NETSTAT_CONNECTED)) == (NETSTAT_LISTENING|NETSTAT_CONNECTED))
563            printf("(servers and established)");
564        else if (flags & NETSTAT_LISTENING)
565            printf("(only servers)");
566        else
567            printf("(w/o servers)");
568        printf("\nProto RefCnt Flags       Type       State         I-Node Path\n");
569        do_info(_PATH_PROCNET_UNIX, "AF UNIX", unix_do_one);
570    }
571    return 0;
572}
Note: See TracBrowser for help on using the repository browser.