X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/e2982e7f6f0b624a773ec5a58885ee80fab46d34..2e6a03c3f1c64ee0455b191cc58b78ea984aa1cb:/print-zephyr.c diff --git a/print-zephyr.c b/print-zephyr.c index 2addd388..7f60f1fd 100644 --- a/print-zephyr.c +++ b/print-zephyr.c @@ -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 * All rights reserved. @@ -23,16 +23,19 @@ /* \summary: Zephyr printer */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif -#include +#include "netdissect-stdinc.h" #include #include #include +#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); }