]> git.saurik.com Git - apple/network_cmds.git/blobdiff - route.tproj/route.c
network_cmds-245.tar.gz
[apple/network_cmds.git] / route.tproj / route.c
index 4e8b4ee6a699dd0f8e93ea807a1c4a6b865fb680..42d4c4524a24c86e82b6976a3d2deaba03ba2725 100644 (file)
@@ -65,7 +65,7 @@ static const char copyright[] =
 static char sccsid[] = "@(#)route.c    8.3 (Berkeley) 3/19/94";
 #endif
 static const char rcsid[] =
-       "$Id: route.c,v 1.2 2002/03/05 20:35:16 lindak Exp $";
+       "$Id: route.c,v 1.3 2003/01/07 21:03:05 bbraun Exp $";
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -790,6 +790,16 @@ newroute(argc, argv)
                flags |= RTF_HOST;
        if (iflag == 0)
                flags |= RTF_GATEWAY;
+       if (so_mask.sin.sin_family == AF_INET) {
+               // make sure the mask is contiguous
+               long i;
+               for (i = 0; i < 32; i++)
+                       if (((so_mask.sin.sin_addr.s_addr) & ntohl((1 << i))) != 0)
+                               break;
+               for (; i < 32; i++)
+                       if (((so_mask.sin.sin_addr.s_addr) & ntohl((1 << i))) == 0)
+                               errx(EX_NOHOST, "invalid mask: %s", inet_ntoa(so_mask.sin.sin_addr));
+       }
        for (attempts = 1; ; attempts++) {
                errno = 0;
                if ((ret = rtmsg(*cmd, flags)) == 0)