2 * Decode and print Zephyr packets.
4 * http://web.mit.edu/zephyr/doc/protocol
6 * Copyright (c) 2001 Nickolai Zeldovich <kolya@MIT.EDU>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that: (1) source code
11 * distributions retain the above copyright notice and this paragraph
12 * in its entirety, and (2) distributions including binary code include
13 * the above copyright notice and this paragraph in its entirety in
14 * the documentation or other materials provided with the distribution.
15 * The name of the author(s) may not be used to endorse or promote
16 * products derived from this software without specific prior written
17 * permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 static const char rcsid[] _U_ =
25 "@(#) $Header: /tcpdump/master/tcpdump/print-zephyr.c,v 1.8.2.1 2005/04/21 06:51:24 guy Exp $";
34 #include <tcpdump-stdinc.h>
40 #include "interface.h"
55 const char *recipient;
60 /* Other fields follow here.. */
75 static struct tok z_types[] = {
76 { Z_PACKET_UNSAFE, "unsafe" },
77 { Z_PACKET_UNACKED, "unacked" },
78 { Z_PACKET_ACKED, "acked" },
79 { Z_PACKET_HMACK, "hm-ack" },
80 { Z_PACKET_HMCTL, "hm-ctl" },
81 { Z_PACKET_SERVACK, "serv-ack" },
82 { Z_PACKET_SERVNAK, "serv-nak" },
83 { Z_PACKET_CLIENTACK, "client-ack" },
84 { Z_PACKET_STAT, "stat" }
90 parse_field(char **pptr, int *len)
94 if (*len <= 0 || !pptr || !*pptr)
96 if (*pptr > (char *) snapend)
100 while (*pptr <= (char *) snapend && *len >= 0 && **pptr) {
106 if (*len < 0 || *pptr > (char *) snapend)
112 z_triple(char *class, char *inst, const char *recipient)
116 snprintf(z_buf, sizeof(z_buf), "<%s,%s,%s>", class, inst, recipient);
117 z_buf[sizeof(z_buf)-1] = '\0';
122 str_to_lower(char *string)
124 strncpy(z_buf, string, sizeof(z_buf));
125 z_buf[sizeof(z_buf)-1] = '\0';
129 *string = tolower((unsigned char)(*string));
137 zephyr_print(const u_char *cp, int length)
140 char *parse = (char *) cp;
141 int parselen = length;
145 #define PARSE_STRING \
146 s = parse_field(&parse, &parselen); \
149 #define PARSE_FIELD_INT(field) \
151 if (!lose) field = strtol(s, 0, 16);
153 #define PARSE_FIELD_STR(field) \
155 if (!lose) field = s;
157 PARSE_FIELD_STR(z.version);
159 if (strncmp(z.version, "ZEPH", 4))
162 PARSE_FIELD_INT(z.numfields);
163 PARSE_FIELD_INT(z.kind);
164 PARSE_FIELD_STR(z.uid);
165 PARSE_FIELD_INT(z.port);
166 PARSE_FIELD_INT(z.auth);
167 PARSE_FIELD_INT(z.authlen);
168 PARSE_FIELD_STR(z.authdata);
169 PARSE_FIELD_STR(z.class);
170 PARSE_FIELD_STR(z.inst);
171 PARSE_FIELD_STR(z.opcode);
172 PARSE_FIELD_STR(z.sender);
173 PARSE_FIELD_STR(z.recipient);
174 PARSE_FIELD_STR(z.format);
175 PARSE_FIELD_INT(z.cksum);
176 PARSE_FIELD_INT(z.multi);
177 PARSE_FIELD_STR(z.multi_uid);
180 printf(" [|zephyr] (%d)", length);
185 if (strncmp(z.version+4, "0.2", 3)) {
186 printf(" v%s", z.version+4);
190 printf(" %s", tok2str(z_types, "type %d", z.kind));
191 if (z.kind == Z_PACKET_SERVACK) {
192 /* Initialization to silence warnings */
193 char *ackdata = NULL;
194 PARSE_FIELD_STR(ackdata);
195 if (!lose && strcmp(ackdata, "SENT"))
196 printf("/%s", str_to_lower(ackdata));
198 if (*z.sender) printf(" %s", z.sender);
200 if (!strcmp(z.class, "USER_LOCATE")) {
201 if (!strcmp(z.opcode, "USER_HIDE"))
203 else if (!strcmp(z.opcode, "USER_UNHIDE"))
206 printf(" locate %s", z.inst);
210 if (!strcmp(z.class, "ZEPHYR_ADMIN")) {
211 printf(" zephyr-admin %s", str_to_lower(z.opcode));
215 if (!strcmp(z.class, "ZEPHYR_CTL")) {
216 if (!strcmp(z.inst, "CLIENT")) {
217 if (!strcmp(z.opcode, "SUBSCRIBE") ||
218 !strcmp(z.opcode, "SUBSCRIBE_NODEFS") ||
219 !strcmp(z.opcode, "UNSUBSCRIBE")) {
221 printf(" %ssub%s", strcmp(z.opcode, "SUBSCRIBE") ? "un" : "",
222 strcmp(z.opcode, "SUBSCRIBE_NODEFS") ? "" :
224 if (z.kind != Z_PACKET_SERVACK) {
225 /* Initialization to silence warnings */
226 char *c = NULL, *i = NULL, *r = NULL;
230 if (!lose) printf(" %s", z_triple(c, i, r));
235 if (!strcmp(z.opcode, "GIMME")) {
240 if (!strcmp(z.opcode, "GIMMEDEFS")) {
241 printf(" gimme-defs");
245 if (!strcmp(z.opcode, "CLEARSUB")) {
246 printf(" clear-subs");
250 printf(" %s", str_to_lower(z.opcode));
254 if (!strcmp(z.inst, "HM")) {
255 printf(" %s", str_to_lower(z.opcode));
259 if (!strcmp(z.inst, "REALM")) {
260 if (!strcmp(z.opcode, "ADD_SUBSCRIBE"))
261 printf(" realm add-subs");
262 if (!strcmp(z.opcode, "REQ_SUBSCRIBE"))
263 printf(" realm req-subs");
264 if (!strcmp(z.opcode, "RLM_SUBSCRIBE"))
265 printf(" realm rlm-sub");
266 if (!strcmp(z.opcode, "RLM_UNSUBSCRIBE"))
267 printf(" realm rlm-unsub");
272 if (!strcmp(z.class, "HM_CTL")) {
273 printf(" hm_ctl %s", str_to_lower(z.inst));
274 printf(" %s", str_to_lower(z.opcode));
278 if (!strcmp(z.class, "HM_STAT")) {
279 if (!strcmp(z.inst, "HMST_CLIENT") && !strcmp(z.opcode, "GIMMESTATS")) {
280 printf(" get-client-stats");
285 if (!strcmp(z.class, "WG_CTL")) {
286 printf(" wg_ctl %s", str_to_lower(z.inst));
287 printf(" %s", str_to_lower(z.opcode));
291 if (!strcmp(z.class, "LOGIN")) {
292 if (!strcmp(z.opcode, "USER_FLUSH")) {
293 printf(" flush_locs");
297 if (!strcmp(z.opcode, "NONE") ||
298 !strcmp(z.opcode, "OPSTAFF") ||
299 !strcmp(z.opcode, "REALM-VISIBLE") ||
300 !strcmp(z.opcode, "REALM-ANNOUNCED") ||
301 !strcmp(z.opcode, "NET-VISIBLE") ||
302 !strcmp(z.opcode, "NET-ANNOUNCED")) {
303 printf(" set-exposure %s", str_to_lower(z.opcode));
311 printf(" to %s", z_triple(z.class, z.inst, z.recipient));
313 printf(" op %s", z.opcode);