umount -> unmount
[unix-history] / usr / src / sbin / routed / routed.c
index 03b3790..46e8264 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)routed.c   4.20 82/06/21";
+static char sccsid[] = "@(#)routed.c   4.25 %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -15,6 +15,7 @@ static char sccsid[] = "@(#)routed.c  4.20 82/06/21";
 #include <nlist.h>
 #include <signal.h>
 #include <time.h>
 #include <nlist.h>
 #include <signal.h>
 #include <time.h>
+#include <netdb.h>
 #define        RIPCMDS
 #include "rip.h"
 #include "router.h"
 #define        RIPCMDS
 #include "rip.h"
 #include "router.h"
@@ -33,8 +34,8 @@ struct nlist nl[] = {
        0,
 };
 
        0,
 };
 
-struct sockaddr_in routingaddr = { AF_INET, IPPORT_ROUTESERVER };
-struct sockaddr_in noroutingaddr = { AF_INET, IPPORT_ROUTESERVER+1 };
+struct sockaddr_in routingaddr = { AF_INET };
+struct sockaddr_in noroutingaddr = { AF_INET };
 
 int    s;
 int    snoroute;               /* socket with no routing */
 
 int    s;
 int    snoroute;               /* socket with no routing */
@@ -55,7 +56,7 @@ FILE  *ftrace;
 char   packet[MAXPACKETSIZE+1];
 struct rip *msg = (struct rip *)packet;
 
 char   packet[MAXPACKETSIZE+1];
 struct rip *msg = (struct rip *)packet;
 
-struct in_addr if_makeaddr();
+struct in_addr inet_makeaddr();
 struct interface *if_ifwithaddr(), *if_ifwithnet();
 extern char *malloc(), *sys_errlist[];
 extern int errno, exit();
 struct interface *if_ifwithaddr(), *if_ifwithnet();
 extern char *malloc(), *sys_errlist[];
 extern int errno, exit();
@@ -69,6 +70,7 @@ main(argc, argv)
 {
        int cc;
        struct sockaddr from;
 {
        int cc;
        struct sockaddr from;
+       struct servent *sp;
        
        argv0 = argv;
 #ifndef DEBUG
        
        argv0 = argv;
 #ifndef DEBUG
@@ -103,10 +105,13 @@ main(argc, argv)
         * able to specify ``don't route'' as an option
         * to send, but until then we utilize a second port.
         */
         * able to specify ``don't route'' as an option
         * to send, but until then we utilize a second port.
         */
-#ifdef vax || pdp11
-       routingaddr.sin_port = htons(routingaddr.sin_port);
-       noroutingaddr.sin_port = htons(noroutingaddr.sin_port);
-#endif
+       sp = getservbyname("router", "udp");
+       if (sp == 0) {
+               fprintf(stderr, "routed: udp/router: unknown service\n");
+               exit(1);
+       }
+       routingaddr.sin_port = htons(sp->s_port);
+       noroutingaddr.sin_port = htons(sp->s_port + 1);
 again:
        s = socket(SOCK_DGRAM, 0, &routingaddr, 0);
        if (s < 0) {
 again:
        s = socket(SOCK_DGRAM, 0, &routingaddr, 0);
        if (s < 0) {
@@ -284,7 +289,7 @@ addrouteforif(ifp)
        else {
                bzero((char *)&net, sizeof (net));
                net.sin_family = AF_INET;
        else {
                bzero((char *)&net, sizeof (net));
                net.sin_family = AF_INET;
-               net.sin_addr = if_makeaddr(ifp->int_net, INADDR_ANY);
+               net.sin_addr = inet_makeaddr(ifp->int_net, INADDR_ANY);
                dst = (struct sockaddr *)&net;
        }
        rt = rtlookup(dst);
                dst = (struct sockaddr *)&net;
        }
        rt = rtlookup(dst);
@@ -311,33 +316,56 @@ gwkludge()
 {
        struct sockaddr_in dst, gate;
        FILE *fp;
 {
        struct sockaddr_in dst, gate;
        FILE *fp;
-       char buf[BUFSIZ];
+       char *type, *dname, *gname, *qual, buf[BUFSIZ];
        struct interface *ifp;
        int metric;
 
        fp = fopen("/etc/gateways", "r");
        if (fp == NULL)
                return;
        struct interface *ifp;
        int metric;
 
        fp = fopen("/etc/gateways", "r");
        if (fp == NULL)
                return;
+       qual = buf;
+       dname = buf + 64;
+       gname = buf + ((BUFSIZ - 64) / 3);
+       type = buf + (((BUFSIZ - 64) * 2) / 3);
        bzero((char *)&dst, sizeof (dst));
        bzero((char *)&gate, sizeof (gate));
        dst.sin_family = gate.sin_family = AF_INET;
        bzero((char *)&dst, sizeof (dst));
        bzero((char *)&gate, sizeof (gate));
        dst.sin_family = gate.sin_family = AF_INET;
-       /* format: dst XX gateway XX metric DD [passive]\n */
+       /* format: {net | host} XX gateway XX metric DD [passive]\n */
 #define        readentry(fp) \
 #define        readentry(fp) \
-       fscanf((fp), "dst %x gateway %x metric %d %s\n", \
-       &dst.sin_addr.s_addr, &gate.sin_addr.s_addr, &metric, buf)
+       fscanf((fp), "%s %s gateway %s metric %d %s\n", \
+               type, dname, gname, &metric, qual)
        for (;;) {
        for (;;) {
+               struct hostent *host;
+               struct netent *net;
+
                if (readentry(fp) == EOF)
                        break;
                if (readentry(fp) == EOF)
                        break;
+               if (strcmp(type, "net") == 0) {
+                       net = getnetbyname(dname);
+                       if (net == 0 || net->n_addrtype != AF_INET)
+                               continue;
+                       dst.sin_addr = inet_makeaddr(net->n_net, INADDR_ANY);
+               } else if (strcmp(type, "host") == 0) {
+                       host = gethostbyname(dname);
+                       if (host == 0)
+                               continue;
+                       bcopy(host->h_addr, &dst.sin_addr, host->h_length);
+               } else
+                       continue;
+               host = gethostbyname(gname);
+               if (host == 0)
+                       continue;
+               bcopy(host->h_addr, &gate.sin_addr, host->h_length);
                ifp = (struct interface *)malloc(sizeof (*ifp));
                bzero((char *)ifp, sizeof (*ifp));
                ifp->int_flags = IFF_REMOTE;
                /* can't identify broadcast capability */
                ifp = (struct interface *)malloc(sizeof (*ifp));
                bzero((char *)ifp, sizeof (*ifp));
                ifp->int_flags = IFF_REMOTE;
                /* can't identify broadcast capability */
-               ifp->int_net = IN_NETOF(dst.sin_addr);
-               if ((*afswitch[dst.sin_family].af_checkhost)(&dst)) {
+               ifp->int_net = inet_netof(dst.sin_addr);
+               if (strcmp(type, "host") == 0) {
                        ifp->int_flags |= IFF_POINTOPOINT;
                        ifp->int_dstaddr = *((struct sockaddr *)&dst);
                }
                        ifp->int_flags |= IFF_POINTOPOINT;
                        ifp->int_dstaddr = *((struct sockaddr *)&dst);
                }
-               if (strcmp(buf, "passive") == 0)
+               if (strcmp(qual, "passive") == 0)
                        ifp->int_flags |= IFF_PASSIVE;
                else
                        /* assume no duplicate entries */
                        ifp->int_flags |= IFF_PASSIVE;
                else
                        /* assume no duplicate entries */
@@ -873,21 +901,3 @@ if_ifwithnet(addr)
        }
        return (ifp);
 }
        }
        return (ifp);
 }
-
-struct in_addr
-if_makeaddr(net, host)
-       int net, host;
-{
-       u_long addr;
-
-       if (net < 128)
-               addr = (net << 24) | host;
-       else if (net < 65536)
-               addr = (net << 16) | host;
-       else
-               addr = (net << 8) | host;
-#ifdef vax
-       addr = htonl(addr);
-#endif
-       return (*(struct in_addr *)&addr);
-}