diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-11-18 13:29:57 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2015-11-18 13:29:57 -0800 |
commit | e075e9915008d5d0f30582b3a75936e58a9bc731 (patch) | |
tree | ac88530d4d21d3cf8cdd9b6afd0e83f01b4230fe | |
parent | d6aacc676d8540f31d1df72b12b43fc9cde93df6 (diff) | |
download | tcpdump-e075e9915008d5d0f30582b3a75936e58a9bc731.tar.gz |
We only handle 4-part addresses.
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.
-rw-r--r-- | strtoaddr.c | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/strtoaddr.c b/strtoaddr.c index 2c370618..f325401c 100644 --- a/strtoaddr.c +++ b/strtoaddr.c @@ -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); |