]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-zephyr.c
Add support for IPv6 agent in sFlow.
[tcpdump] / print-zephyr.c
index 2addd388cb3fd114a5dc85969ae6ba4292791506..7f60f1fdc207d0370bccae7e21be79a1294156c0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Decode and print Zephyr packets.
  *
- *     http://web.mit.edu/zephyr/doc/protocol
+ *     https://web.mit.edu/zephyr/doc/protocol
  *
  * Copyright (c) 2001 Nickolai Zeldovich <[email protected]>
  * All rights reserved.
 /* \summary: Zephyr printer */
 
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
-#include <netdissect-stdinc.h>
+#include "netdissect-stdinc.h"
 
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 
+#include "netdissect-ctype.h"
+
 #include "netdissect.h"
+#include "extract.h"
 
 struct z_packet {
     const char *version;
@@ -83,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;
 
@@ -95,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;
        }
@@ -134,7 +132,7 @@ str_to_lower(const char *string)
 
     zb_string = z_buf;
     while (*zb_string) {
-       *zb_string = tolower((unsigned char)(*zb_string));
+       *zb_string = ND_ASCII_TOLOWER(*zb_string);
        zb_string++;
     }
 
@@ -144,25 +142,35 @@ str_to_lower(const char *string)
 void
 zephyr_print(netdissect_options *ndo, const u_char *cp, int length)
 {
-    struct z_packet z;
+    struct z_packet z = {
+        NULL,  /* version */
+        0,     /* numfields */
+        0,     /* kind */
+        NULL,  /* uid */
+        0,     /* port */
+        0,     /* auth */
+        0,     /* authlen */
+        NULL,  /* authdata */
+        NULL,  /* class */
+        NULL,  /* inst */
+        NULL,  /* opcode */
+        NULL,  /* sender */
+        NULL,  /* recipient */
+        NULL,  /* format */
+        0,     /* cksum */
+        0,     /* multi */
+        NULL   /* multi_uid */
+    };
     const char *parse = (const char *) cp;
     int parselen = length;
     const char *s;
     int lose = 0;
-    int truncated = 0;
 
+    ndo->ndo_protocol = "zephyr";
     /* squelch compiler warnings */
 
-    z.kind = 0;
-    z.class = 0;
-    z.inst = 0;
-    z.opcode = 0;
-    z.sender = 0;
-    z.recipient = 0;
-
 #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)                 \
@@ -174,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;
 
@@ -196,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)) {
@@ -330,7 +340,6 @@ zephyr_print(netdissect_options *ndo, const u_char *cp, int length)
        ND_PRINT(" op %s", z.opcode);
     return;
 
-trunc:
-    ND_PRINT(" [|zephyr] (%d)", length);
-    return;
+invalid:
+    nd_print_invalid(ndo);
 }