gzip cleanup part #8
[oweals/busybox.git] / networking / netstat.c
index cadcb0e3102039859ba0199b40da6276ae52de39..3dad57a40e97071ced3f6c91814893836ff173d2 100644 (file)
@@ -21,7 +21,7 @@ extern void displayroutes(int noresolve, int netstatfmt);
 #define NETSTAT_CONNECTED       0x01
 #define NETSTAT_LISTENING       0x02
 #define NETSTAT_NUMERIC         0x04
-/* Must match getopt_ulflags option string */
+/* Must match getopt32 option string */
 #define NETSTAT_TCP             0x10
 #define NETSTAT_UDP             0x20
 #define NETSTAT_RAW             0x40
@@ -496,7 +496,6 @@ static void unix_do_one(int nr, const char *line)
 
 static void do_info(const char *file, const char *name, void (*proc)(int, const char *))
 {
-       char buffer[8192];
        int lnr = 0;
        FILE *procinfo;
 
@@ -505,12 +504,15 @@ static void do_info(const char *file, const char *name, void (*proc)(int, const
                if (errno != ENOENT) {
                        perror(file);
                } else {
-               bb_error_msg("no support for `%s' on this system", name);
+                       bb_error_msg("no support for '%s' on this system", name);
                }
        } else {
                do {
-                       if (fgets(buffer, sizeof(buffer), procinfo))
+                       char *buffer = xmalloc_fgets(procinfo);
+                       if (buffer) {
                                (proc)(lnr++, buffer);
+                               free(buffer);
+                       }
                } while (!feof(procinfo));
                fclose(procinfo);
        }
@@ -526,7 +528,7 @@ int netstat_main(int argc, char **argv)
                OPT_extended = 0x4,
                OPT_showroute = 0x100,
        };
-       unsigned long opt;
+       unsigned opt;
 #ifdef CONFIG_FEATURE_IPV6
        int inet = 1;
        int inet6 = 1;
@@ -536,7 +538,7 @@ int netstat_main(int argc, char **argv)
 #endif
 
        /* Option string must match NETSTAT_xxx constants */
-       opt = bb_getopt_ulflags(argc, argv, "laentuwxr");
+       opt = getopt32(argc, argv, "laentuwxr");
        if (opt & 0x1) { // -l
                flags &= ~NETSTAT_CONNECTED;
                flags |= NETSTAT_LISTENING;
@@ -573,7 +575,7 @@ int netstat_main(int argc, char **argv)
                        else
                                printf("(w/o servers)");
                }
-               printf("\nProto Recv-Q Send-Q Local Address           Foreign Address         State      \n");
+               printf("\nProto Recv-Q Send-Q Local Address           Foreign Address         State\n");
        }
        if (inet && flags&NETSTAT_TCP)
                do_info(_PATH_PROCNET_TCP,"AF INET (tcp)",tcp_do_one);