]> The Tcpdump Group git mirrors - tcpdump/commitdiff
We only handle 4-part addresses.
authorGuy Harris <[email protected]>
Wed, 18 Nov 2015 21:29:57 +0000 (13:29 -0800)
committerGuy Harris <[email protected]>
Wed, 18 Nov 2015 21:29:57 +0000 (13:29 -0800)
Get rid of the code to handle everything else; that code was dead, as
Coverity noted.  Add some comments to clarify what's going on.

strtoaddr.c

index 2c37061879b0005598724ddf62ffb689a85bd606..f325401cdc86bea65b774f2da7f9431f73bdc50f 100644 (file)
@@ -114,39 +114,25 @@ strtoaddr(const char *src, void *dst)
        if (c != '\0' && !isspace(c))
                return (0);
        /*
-        * Concoct the address according to
-        * the number of parts specified.
+        * Find the number of parts specified.
+        * It must be 4; we only support dotted quads, we don't
+        * support shorthand.
         */
        n = pp - parts + 1;
-       /* Takes dotted-quad only.  it does not take shorthand. */
        if (n != 4)
                return (0);
-       switch (n) {
-
-       case 0:
-               return (0);             /* initial nondigit */
-
-       case 1:                         /* a -- 32 bits */
-               break;
-
-       case 2:                         /* a.b -- 8.24 bits */
-               if (parts[0] > 0xff || val > 0xffffff)
-                       return (0);
-               val |= parts[0] << 24;
-               break;
-
-       case 3:                         /* a.b.c -- 8.8.16 bits */
-               if ((parts[0] | parts[1]) > 0xff || val > 0xffff)
-                       return (0);
-               val |= (parts[0] << 24) | (parts[1] << 16);
-               break;
-
-       case 4:                         /* a.b.c.d -- 8.8.8.8 bits */
-               if ((parts[0] | parts[1] | parts[2] | val) > 0xff)
-                       return (0);
-               val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
-               break;
-       }
+       /*
+        * parts[0-2] were set to the first 3 parts of the address;
+        * val was set to the 4th part.
+        *
+        * Check if any part is bigger than 255.
+        */
+       if ((parts[0] | parts[1] | parts[2] | val) > 0xff)
+               return (0);
+       /*
+        * Add the other three parts to val.
+        */
+       val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
        if (dst) {
                val = htonl(val);
                memcpy(dst, &val, NS_INADDRSZ);