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
23 /* \summary: Zephyr printer */
29 #include <netdissect-stdinc.h>
35 #include "netdissect.h"
50 const char *recipient;
54 const char *multi_uid;
55 /* Other fields follow here.. */
70 static const struct tok z_types[] = {
71 { Z_PACKET_UNSAFE, "unsafe" },
72 { Z_PACKET_UNACKED, "unacked" },
73 { Z_PACKET_ACKED, "acked" },
74 { Z_PACKET_HMACK, "hm-ack" },
75 { Z_PACKET_HMCTL, "hm-ctl" },
76 { Z_PACKET_SERVACK, "serv-ack" },
77 { Z_PACKET_SERVNAK, "serv-nak" },
78 { Z_PACKET_CLIENTACK, "client-ack" },
79 { Z_PACKET_STAT, "stat" }
82 static char z_buf[256];
85 parse_field(netdissect_options *ndo, const char **pptr, int *len)
89 if (*len <= 0 || !pptr || !*pptr)
91 if (*pptr > (const char *) ndo->ndo_snapend)
95 while (*pptr <= (const char *) ndo->ndo_snapend && *len >= 0 && **pptr) {
101 if (*len < 0 || *pptr > (const char *) ndo->ndo_snapend)
107 z_triple(const char *class, const char *inst, const char *recipient)
111 snprintf(z_buf, sizeof(z_buf), "<%s,%s,%s>", class, inst, recipient);
112 z_buf[sizeof(z_buf)-1] = '\0';
117 str_to_lower(const char *string)
121 strncpy(z_buf, string, sizeof(z_buf));
122 z_buf[sizeof(z_buf)-1] = '\0';
126 *zb_string = tolower((unsigned char)(*zb_string));
134 zephyr_print(netdissect_options *ndo, const u_char *cp, int length)
137 const char *parse = (const char *) cp;
138 int parselen = length;
142 /* squelch compiler warnings */
151 #define PARSE_STRING \
152 s = parse_field(ndo, &parse, &parselen); \
155 #define PARSE_FIELD_INT(field) \
157 if (!lose) field = strtol(s, 0, 16);
159 #define PARSE_FIELD_STR(field) \
161 if (!lose) field = s;
163 PARSE_FIELD_STR(z.version);
165 if (strncmp(z.version, "ZEPH", 4))
168 PARSE_FIELD_INT(z.numfields);
169 PARSE_FIELD_INT(z.kind);
170 PARSE_FIELD_STR(z.uid);
171 PARSE_FIELD_INT(z.port);
172 PARSE_FIELD_INT(z.auth);
173 PARSE_FIELD_INT(z.authlen);
174 PARSE_FIELD_STR(z.authdata);
175 PARSE_FIELD_STR(z.class);
176 PARSE_FIELD_STR(z.inst);
177 PARSE_FIELD_STR(z.opcode);
178 PARSE_FIELD_STR(z.sender);
179 PARSE_FIELD_STR(z.recipient);
180 PARSE_FIELD_STR(z.format);
181 PARSE_FIELD_INT(z.cksum);
182 PARSE_FIELD_INT(z.multi);
183 PARSE_FIELD_STR(z.multi_uid);
186 ND_PRINT((ndo, " [|zephyr] (%d)", length));
190 ND_PRINT((ndo, " zephyr"));
191 if (strncmp(z.version+4, "0.2", 3)) {
192 ND_PRINT((ndo, " v%s", z.version+4));
196 ND_PRINT((ndo, " %s", tok2str(z_types, "type %d", z.kind)));
197 if (z.kind == Z_PACKET_SERVACK) {
198 /* Initialization to silence warnings */
199 const char *ackdata = NULL;
200 PARSE_FIELD_STR(ackdata);
201 if (!lose && strcmp(ackdata, "SENT"))
202 ND_PRINT((ndo, "/%s", str_to_lower(ackdata)));
204 if (*z.sender) ND_PRINT((ndo, " %s", z.sender));
206 if (!strcmp(z.class, "USER_LOCATE")) {
207 if (!strcmp(z.opcode, "USER_HIDE"))
208 ND_PRINT((ndo, " hide"));
209 else if (!strcmp(z.opcode, "USER_UNHIDE"))
210 ND_PRINT((ndo, " unhide"));
212 ND_PRINT((ndo, " locate %s", z.inst));
216 if (!strcmp(z.class, "ZEPHYR_ADMIN")) {
217 ND_PRINT((ndo, " zephyr-admin %s", str_to_lower(z.opcode)));
221 if (!strcmp(z.class, "ZEPHYR_CTL")) {
222 if (!strcmp(z.inst, "CLIENT")) {
223 if (!strcmp(z.opcode, "SUBSCRIBE") ||
224 !strcmp(z.opcode, "SUBSCRIBE_NODEFS") ||
225 !strcmp(z.opcode, "UNSUBSCRIBE")) {
227 ND_PRINT((ndo, " %ssub%s", strcmp(z.opcode, "SUBSCRIBE") ? "un" : "",
228 strcmp(z.opcode, "SUBSCRIBE_NODEFS") ? "" :
230 if (z.kind != Z_PACKET_SERVACK) {
231 /* Initialization to silence warnings */
232 const char *c = NULL, *i = NULL, *r = NULL;
236 if (!lose) ND_PRINT((ndo, " %s", z_triple(c, i, r)));
241 if (!strcmp(z.opcode, "GIMME")) {
242 ND_PRINT((ndo, " ret"));
246 if (!strcmp(z.opcode, "GIMMEDEFS")) {
247 ND_PRINT((ndo, " gimme-defs"));
251 if (!strcmp(z.opcode, "CLEARSUB")) {
252 ND_PRINT((ndo, " clear-subs"));
256 ND_PRINT((ndo, " %s", str_to_lower(z.opcode)));
260 if (!strcmp(z.inst, "HM")) {
261 ND_PRINT((ndo, " %s", str_to_lower(z.opcode)));
265 if (!strcmp(z.inst, "REALM")) {
266 if (!strcmp(z.opcode, "ADD_SUBSCRIBE"))
267 ND_PRINT((ndo, " realm add-subs"));
268 if (!strcmp(z.opcode, "REQ_SUBSCRIBE"))
269 ND_PRINT((ndo, " realm req-subs"));
270 if (!strcmp(z.opcode, "RLM_SUBSCRIBE"))
271 ND_PRINT((ndo, " realm rlm-sub"));
272 if (!strcmp(z.opcode, "RLM_UNSUBSCRIBE"))
273 ND_PRINT((ndo, " realm rlm-unsub"));
278 if (!strcmp(z.class, "HM_CTL")) {
279 ND_PRINT((ndo, " hm_ctl %s", str_to_lower(z.inst)));
280 ND_PRINT((ndo, " %s", str_to_lower(z.opcode)));
284 if (!strcmp(z.class, "HM_STAT")) {
285 if (!strcmp(z.inst, "HMST_CLIENT") && !strcmp(z.opcode, "GIMMESTATS")) {
286 ND_PRINT((ndo, " get-client-stats"));
291 if (!strcmp(z.class, "WG_CTL")) {
292 ND_PRINT((ndo, " wg_ctl %s", str_to_lower(z.inst)));
293 ND_PRINT((ndo, " %s", str_to_lower(z.opcode)));
297 if (!strcmp(z.class, "LOGIN")) {
298 if (!strcmp(z.opcode, "USER_FLUSH")) {
299 ND_PRINT((ndo, " flush_locs"));
303 if (!strcmp(z.opcode, "NONE") ||
304 !strcmp(z.opcode, "OPSTAFF") ||
305 !strcmp(z.opcode, "REALM-VISIBLE") ||
306 !strcmp(z.opcode, "REALM-ANNOUNCED") ||
307 !strcmp(z.opcode, "NET-VISIBLE") ||
308 !strcmp(z.opcode, "NET-ANNOUNCED")) {
309 ND_PRINT((ndo, " set-exposure %s", str_to_lower(z.opcode)));
317 ND_PRINT((ndo, " to %s", z_triple(z.class, z.inst, z.recipient)));
319 ND_PRINT((ndo, " op %s", z.opcode));