add proper return to savegateway() from Mike Muuss (mike@brl.mil)
[unix-history] / usr / src / old / htable / htable.c
index b43360a..02974e9 100644 (file)
@@ -1,6 +1,18 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1983 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)htable.c   4.10 (Berkeley) %G%";
-#endif
+static char sccsid[] = "@(#)htable.c   5.5 (Berkeley) %G%";
+#endif not lint
 
 /*
  * htable - convert NIC host table into a UNIX format.
 
 /*
  * htable - convert NIC host table into a UNIX format.
@@ -160,6 +172,8 @@ lower(str)
        while (*cp) {
                if (isupper(*cp))
                        *cp = tolower(*cp);
        while (*cp) {
                if (isupper(*cp))
                        *cp = tolower(*cp);
+               if (*cp == '.')
+                       break;
                cp++;
        }
        return (str);
                cp++;
        }
        return (str);
@@ -333,6 +347,7 @@ copygateways(f, filename)
        char dname[80];
        char gname[80];
        char junk[80];
        char dname[80];
        char gname[80];
        char junk[80];
+       char buf[500];
        u_long addr;
        int net, metric;
        extern int errno;
        u_long addr;
        int net, metric;
        extern int errno;
@@ -347,24 +362,23 @@ copygateways(f, filename)
                return;
        }
        /* format: {net | host} XX gateway XX metric DD [passive]\n */
                return;
        }
        /* format: {net | host} XX gateway XX metric DD [passive]\n */
-#define        readentry(fp) \
-       fscanf((fp), "%s %s gateway %s metric %d %s\n", \
-               type, dname, gname, &metric, junk)
        for (;;) {
                junk[0] = 0;
        for (;;) {
                junk[0] = 0;
-               if (readentry(lhf) == EOF)
+               if (fgets(buf, sizeof(buf), lhf) == (char *)NULL)
                        break;
                        break;
+               fputs(buf, gf);
+               if (buf[0] == '#' ||
+                   sscanf(buf, "%s %s gateway %s metric %d %s",
+                   type, dname, gname, &metric, junk) < 5)
+                       continue;
                if (strcmp(type, "net"))
                if (strcmp(type, "net"))
-                       goto dumpit;
+                       continue;
                if (!getnetaddr(dname, &net))
                if (!getnetaddr(dname, &net))
-                       goto dumpit;
+                       continue;
                if (!gethostaddr(gname, &addr))
                if (!gethostaddr(gname, &addr))
-                       goto dumpit;
+                       continue;
                nl = newname(gname);
                (void) savegateway(nl, net, addr, metric);
                nl = newname(gname);
                (void) savegateway(nl, net, addr, metric);
-dumpit:
-               fprintf(gf, "%s %s gateway %s metric %d %s\n",
-                       type, dname, gname, metric, junk);
        }
        fclose(lhf);
 }
        }
        fclose(lhf);
 }
@@ -511,6 +525,7 @@ savegateway(namelist, net, addr, metric)
        gp->g_metric = metric;
        if (metric == 1)
                gp->g_dst = gp;
        gp->g_metric = metric;
        if (metric == 1)
                gp->g_dst = gp;
+       return (gp);
 }
 
 connectedto(net)
 }
 
 connectedto(net)