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 $";
32 #include <tcpdump-stdinc.h>
38 #include "interface.h"
53 const char *recipient;
58 /* Other fields follow here.. */
73 static struct tok z_types[] = {
74 { Z_PACKET_UNSAFE, "unsafe" },
75 { Z_PACKET_UNACKED, "unacked" },
76 { Z_PACKET_ACKED, "acked" },
77 { Z_PACKET_HMACK, "hm-ack" },
78 { Z_PACKET_HMCTL, "hm-ctl" },
79 { Z_PACKET_SERVACK, "serv-ack" },
80 { Z_PACKET_SERVNAK, "serv-nak" },
81 { Z_PACKET_CLIENTACK, "client-ack" },
82 { Z_PACKET_STAT, "stat" }
88 parse_field(char **pptr, int *len)
92 if (*len <= 0 || !pptr || !*pptr)
94 if (*pptr > (char *) snapend)
98 while (*pptr <= (char *) snapend && *len >= 0 && **pptr) {
104 if (*len < 0 || *pptr > (char *) snapend)
110 z_triple(char *class, char *inst, const char *recipient)
114 snprintf(z_buf, sizeof(z_buf), "<%s,%s,%s>", class, inst, recipient);
115 z_buf[sizeof(z_buf)-1] = '\0';
120 str_to_lower(char *string)
122 strncpy(z_buf, string, sizeof(z_buf));
123 z_buf[sizeof(z_buf)-1] = '\0';
127 *string = tolower((unsigned char)(*string));
135 zephyr_print(const u_char *cp, int length)
138 char *parse = (char *) cp;
139 int parselen = length;
143 #define PARSE_STRING \
144 s = parse_field(&parse, &parselen); \
147 #define PARSE_FIELD_INT(field) \
149 if (!lose) field = strtol(s, 0, 16);
151 #define PARSE_FIELD_STR(field) \
153 if (!lose) field = s;
155 PARSE_FIELD_STR(z.version);
157 if (strncmp(z.version, "ZEPH", 4))
160 PARSE_FIELD_INT(z.numfields);
161 PARSE_FIELD_INT(z.kind);
162 PARSE_FIELD_STR(z.uid);
163 PARSE_FIELD_INT(z.port);
164 PARSE_FIELD_INT(z.auth);
165 PARSE_FIELD_INT(z.authlen);
166 PARSE_FIELD_STR(z.authdata);
167 PARSE_FIELD_STR(z.class);
168 PARSE_FIELD_STR(z.inst);
169 PARSE_FIELD_STR(z.opcode);
170 PARSE_FIELD_STR(z.sender);
171 PARSE_FIELD_STR(z.recipient);
172 PARSE_FIELD_STR(z.format);
173 PARSE_FIELD_INT(z.cksum);
174 PARSE_FIELD_INT(z.multi);
175 PARSE_FIELD_STR(z.multi_uid);
178 printf(" [|zephyr] (%d)", length);
183 if (strncmp(z.version+4, "0.2", 3)) {
184 printf(" v%s", z.version+4);
188 printf(" %s", tok2str(z_types, "type %d", z.kind));
189 if (z.kind == Z_PACKET_SERVACK) {
190 /* Initialization to silence warnings */
191 char *ackdata = NULL;
192 PARSE_FIELD_STR(ackdata);
193 if (!lose && strcmp(ackdata, "SENT"))
194 printf("/%s", str_to_lower(ackdata));
196 if (*z.sender) printf(" %s", z.sender);
198 if (!strcmp(z.class, "USER_LOCATE")) {
199 if (!strcmp(z.opcode, "USER_HIDE"))
201 else if (!strcmp(z.opcode, "USER_UNHIDE"))
204 printf(" locate %s", z.inst);
208 if (!strcmp(z.class, "ZEPHYR_ADMIN")) {
209 printf(" zephyr-admin %s", str_to_lower(z.opcode));
213 if (!strcmp(z.class, "ZEPHYR_CTL")) {
214 if (!strcmp(z.inst, "CLIENT")) {
215 if (!strcmp(z.opcode, "SUBSCRIBE") ||
216 !strcmp(z.opcode, "SUBSCRIBE_NODEFS") ||
217 !strcmp(z.opcode, "UNSUBSCRIBE")) {
219 printf(" %ssub%s", strcmp(z.opcode, "SUBSCRIBE") ? "un" : "",
220 strcmp(z.opcode, "SUBSCRIBE_NODEFS") ? "" :
222 if (z.kind != Z_PACKET_SERVACK) {
223 /* Initialization to silence warnings */
224 char *c = NULL, *i = NULL, *r = NULL;
228 if (!lose) printf(" %s", z_triple(c, i, r));
233 if (!strcmp(z.opcode, "GIMME")) {
238 if (!strcmp(z.opcode, "GIMMEDEFS")) {
239 printf(" gimme-defs");
243 if (!strcmp(z.opcode, "CLEARSUB")) {
244 printf(" clear-subs");
248 printf(" %s", str_to_lower(z.opcode));
252 if (!strcmp(z.inst, "HM")) {
253 printf(" %s", str_to_lower(z.opcode));
257 if (!strcmp(z.inst, "REALM")) {
258 if (!strcmp(z.opcode, "ADD_SUBSCRIBE"))
259 printf(" realm add-subs");
260 if (!strcmp(z.opcode, "REQ_SUBSCRIBE"))
261 printf(" realm req-subs");
262 if (!strcmp(z.opcode, "RLM_SUBSCRIBE"))
263 printf(" realm rlm-sub");
264 if (!strcmp(z.opcode, "RLM_UNSUBSCRIBE"))
265 printf(" realm rlm-unsub");
270 if (!strcmp(z.class, "HM_CTL")) {
271 printf(" hm_ctl %s", str_to_lower(z.inst));
272 printf(" %s", str_to_lower(z.opcode));
276 if (!strcmp(z.class, "HM_STAT")) {
277 if (!strcmp(z.inst, "HMST_CLIENT") && !strcmp(z.opcode, "GIMMESTATS")) {
278 printf(" get-client-stats");
283 if (!strcmp(z.class, "WG_CTL")) {
284 printf(" wg_ctl %s", str_to_lower(z.inst));
285 printf(" %s", str_to_lower(z.opcode));
289 if (!strcmp(z.class, "LOGIN")) {
290 if (!strcmp(z.opcode, "USER_FLUSH")) {
291 printf(" flush_locs");
295 if (!strcmp(z.opcode, "NONE") ||
296 !strcmp(z.opcode, "OPSTAFF") ||
297 !strcmp(z.opcode, "REALM-VISIBLE") ||
298 !strcmp(z.opcode, "REALM-ANNOUNCED") ||
299 !strcmp(z.opcode, "NET-VISIBLE") ||
300 !strcmp(z.opcode, "NET-ANNOUNCED")) {
301 printf(" set-exposure %s", str_to_lower(z.opcode));
309 printf(" to %s", z_triple(z.class, z.inst, z.recipient));
311 printf(" op %s", z.opcode);