Another update from Larry:
[oweals/busybox.git] / route.c
diff --git a/route.c b/route.c
index 9bd4e91d207cefef4d9147e409e625314b9e1894..d571fc5a3a770065792777d3662c9b547dd535a1 100644 (file)
--- a/route.c
+++ b/route.c
  * Foundation;  either  version 2 of the License, or  (at
  * your option) any later version.
  *
- * $Id: route.c,v 1.5 2001/02/15 23:31:40 markw Exp $
+ * $Id: route.c,v 1.10 2001/03/21 07:34:26 andersen Exp $
  *
  * displayroute() code added by Vladimir N. Oleynik <dzo@simtreas.ru>
- * busybox style adjustments by Larry Doolittle  <LRDoolittle@lbl.gov>
- * displayroute() format now matches net-tools-1.57/lib/inet_gr.c line 173.
+ * adjustments by Larry Doolittle  <LRDoolittle@lbl.gov>
  */
 
-#include "busybox.h"
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
@@ -38,6 +36,7 @@
 #include <getopt.h>
 #include <unistd.h>
 #include <ctype.h>
+#include "busybox.h"
 
 #define _(x) x
 
 static int
 INET_resolve(char *name, struct sockaddr *sa)
 {
-       struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+       struct sockaddr_in *s_in = (struct sockaddr_in *)sa;
        
-       sin->sin_family = AF_INET;
-       sin->sin_port = 0;
+       s_in->sin_family = AF_INET;
+       s_in->sin_port = 0;
 
        /* Default is special, meaning 0.0.0.0. */
        if (strcmp(name, "default")==0) {
-               sin->sin_addr.s_addr = INADDR_ANY;
+               s_in->sin_addr.s_addr = INADDR_ANY;
                return 1;
        }
        /* Look to see if it's a dotted quad. */
-       if (inet_aton(name, &sin->sin_addr)) {
+       if (inet_aton(name, &s_in->sin_addr)) {
                return 0;
        }
        /* guess not.. */
@@ -347,7 +346,7 @@ INET_setroute(int action, int options, char **args)
        return EXIT_SUCCESS;
 }
 
-void displayroutes(void)
+static void displayroutes(void)
 {
        char buff[256];
        int  nl = 0 ;
@@ -361,11 +360,8 @@ void displayroutes(void)
        char sdest[16], sgw[16];
 
 
-       FILE *fp = fopen("/proc/net/route", "r");
+       FILE *fp = xfopen("/proc/net/route", "r");
 
-       if(fp==0) {
-               perror_msg_and_die("/proc/net/route");
-       }
        while( fgets(buff, sizeof(buff), fp) != NULL ) {
                if(nl) {
                        int ifl = 0;
@@ -376,9 +372,6 @@ void displayroutes(void)
                           &d, &g, &flgs, &ref, &use, &metric, &m)!=7) {
                                error_msg_and_die( "Unsuported kernel route format\n");
                        }
-                       dest.s_addr = d;
-                       gw.s_addr   = g;
-                       mask.s_addr = m;
                        if(nl==1) {
                 printf("Kernel IP routing table\n"
 "Destination     Gateway         Genmask         Flags Metric Ref    Use Iface\n");
@@ -393,11 +386,14 @@ void displayroutes(void)
                        if(flgs&4)
                                flags[ifl++]='H';
                        flags[ifl]=0;
+                       dest.s_addr = d;
+                       gw.s_addr   = g;
+                       mask.s_addr = m;
                        strcpy(sdest,  (dest.s_addr==0 ? "default" :
                                        inet_ntoa(dest)));
                        strcpy(sgw,    (gw.s_addr==0   ? "*"       :
                                        inet_ntoa(gw)));
-                       printf("%-15s %-15s %-15s %-5s %-6d %-2d %7d %s\n",
+                       printf("%-16s%-16s%-16s%-6s%-6d %-2d %7d %s\n",
                                sdest, sgw,
                                inet_ntoa(mask),
                                flags, metric, ref, use, buff);
@@ -415,7 +411,7 @@ int route_main(int argc, char **argv)
 
        if (*argv == NULL) {
                displayroutes();
-               exit(EXIT_SUCCESS);
+               return EXIT_SUCCESS;
        } else {
                /* check verb */
                if (strcmp(*argv, "add")==0)