]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Zephyr: Modernize packet parsing style.
authorDenis Ovsienko <[email protected]>
Thu, 15 Oct 2020 22:48:36 +0000 (23:48 +0100)
committerDenis Ovsienko <[email protected]>
Fri, 16 Oct 2020 12:47:31 +0000 (13:47 +0100)
Replace a custom packet buffer end guard with a GET_U_1() and remove the
associated props. Add and use a standard invalid packet label. Update a
test.

print-zephyr.c
tests/zephyr-oobr.out

index 8d199b56bdee0f2a9588acdeba85cdaac7b221c2..7f60f1fdc207d0370bccae7e21be79a1294156c0 100644 (file)
@@ -35,6 +35,7 @@
 #include "netdissect-ctype.h"
 
 #include "netdissect.h"
+#include "extract.h"
 
 struct z_packet {
     const char *version;
@@ -85,7 +86,7 @@ static const struct tok z_types[] = {
 static char z_buf[256];
 
 static const char *
-parse_field(netdissect_options *ndo, const char **pptr, int *len, int *truncated)
+parse_field(netdissect_options *ndo, const char **pptr, int *len)
 {
     const char *s;
 
@@ -97,12 +98,7 @@ parse_field(netdissect_options *ndo, const char **pptr, int *len, int *truncated
            /* Ran out of packet data without finding it */
            return NULL;
        }
-       if (!ND_TTEST_SIZE(*pptr)) {
-           /* Ran out of captured data without finding it */
-           *truncated = 1;
-           return NULL;
-       }
-       if (**pptr == '\0') {
+       if (GET_U_1(*pptr) == '\0') {
            /* Found it */
            break;
        }
@@ -169,14 +165,12 @@ zephyr_print(netdissect_options *ndo, const u_char *cp, int length)
     int parselen = length;
     const char *s;
     int lose = 0;
-    int truncated = 0;
 
     ndo->ndo_protocol = "zephyr";
     /* squelch compiler warnings */
 
 #define PARSE_STRING                                           \
-       s = parse_field(ndo, &parse, &parselen, &truncated);    \
-       if (truncated) goto trunc;                              \
+       s = parse_field(ndo, &parse, &parselen);        \
        if (!s) lose = 1;
 
 #define PARSE_FIELD_INT(field)                 \
@@ -188,7 +182,9 @@ zephyr_print(netdissect_options *ndo, const u_char *cp, int length)
        if (!lose) field = s;
 
     PARSE_FIELD_STR(z.version);
-    if (lose) return;
+    if (lose)
+        goto invalid;
+
     if (strncmp(z.version, "ZEPH", 4))
        return;
 
@@ -210,7 +206,7 @@ zephyr_print(netdissect_options *ndo, const u_char *cp, int length)
     PARSE_FIELD_STR(z.multi_uid);
 
     if (lose)
-        goto trunc;
+        goto invalid;
 
     ND_PRINT(" zephyr");
     if (strncmp(z.version+4, "0.2", 3)) {
@@ -344,6 +340,6 @@ zephyr_print(netdissect_options *ndo, const u_char *cp, int length)
        ND_PRINT(" op %s", z.opcode);
     return;
 
-trunc:
-    nd_print_trunc(ndo);
+invalid:
+    nd_print_invalid(ndo);
 }
index aefcf6725abbe3bce7c8c75a37feed7e68b0dfee..041400895f89e2d7431d85be168c620aff4f63d8 100644 (file)
@@ -1,2 +1,2 @@
     1  00:00:00.000000 00:16:ca:92:12:01 > 00:15:e8:97:b2:01, ethertype IPv4 (0x0800), length 65535: (tos 0x0, ttl 124, id 16059, offset 0, flags [none], proto UDP (17), length 65521)
-    167.155.6.190.2104 > 167.155.9.153.514: [udp sum ok] 
+    167.155.6.190.2104 > 167.155.9.153.514: [udp sum ok]  (invalid)