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" },
83 static char z_buf[256];
86 parse_field(netdissect_options *ndo, const char **pptr, int *len, int *truncated)
92 /* Scan for the NUL terminator */
95 /* Ran out of packet data without finding it */
98 if (!ND_TTEST(**pptr)) {
99 /* Ran out of captured data without finding it */
103 if (**pptr == '\0') {
111 /* Skip the NUL terminator */
118 z_triple(const char *class, const char *inst, const char *recipient)
122 snprintf(z_buf, sizeof(z_buf), "<%s,%s,%s>", class, inst, recipient);
123 z_buf[sizeof(z_buf)-1] = '\0';
128 str_to_lower(const char *string)
132 strncpy(z_buf, string, sizeof(z_buf));
133 z_buf[sizeof(z_buf)-1] = '\0';
137 *zb_string = tolower((unsigned char)(*zb_string));
145 zephyr_print(netdissect_options *ndo, const u_char *cp, int length)
148 const char *parse = (const char *) cp;
149 int parselen = length;
154 /* squelch compiler warnings */
163 #define PARSE_STRING \
164 s = parse_field(ndo, &parse, &parselen, &truncated); \
165 if (truncated) goto trunc; \
168 #define PARSE_FIELD_INT(field) \
170 if (!lose) field = strtol(s, 0, 16);
172 #define PARSE_FIELD_STR(field) \
174 if (!lose) field = s;
176 PARSE_FIELD_STR(z.version);
178 if (strncmp(z.version, "ZEPH", 4))
181 PARSE_FIELD_INT(z.numfields);
182 PARSE_FIELD_INT(z.kind);
183 PARSE_FIELD_STR(z.uid);
184 PARSE_FIELD_INT(z.port);
185 PARSE_FIELD_INT(z.auth);
186 PARSE_FIELD_INT(z.authlen);
187 PARSE_FIELD_STR(z.authdata);
188 PARSE_FIELD_STR(z.class);
189 PARSE_FIELD_STR(z.inst);
190 PARSE_FIELD_STR(z.opcode);
191 PARSE_FIELD_STR(z.sender);
192 PARSE_FIELD_STR(z.recipient);
193 PARSE_FIELD_STR(z.format);
194 PARSE_FIELD_INT(z.cksum);
195 PARSE_FIELD_INT(z.multi);
196 PARSE_FIELD_STR(z.multi_uid);
201 ND_PRINT((ndo, " zephyr"));
202 if (strncmp(z.version+4, "0.2", 3)) {
203 ND_PRINT((ndo, " v%s", z.version+4));
207 ND_PRINT((ndo, " %s", tok2str(z_types, "type %d", z.kind)));
208 if (z.kind == Z_PACKET_SERVACK) {
209 /* Initialization to silence warnings */
210 const char *ackdata = NULL;
211 PARSE_FIELD_STR(ackdata);
212 if (!lose && strcmp(ackdata, "SENT"))
213 ND_PRINT((ndo, "/%s", str_to_lower(ackdata)));
215 if (*z.sender) ND_PRINT((ndo, " %s", z.sender));
217 if (!strcmp(z.class, "USER_LOCATE")) {
218 if (!strcmp(z.opcode, "USER_HIDE"))
219 ND_PRINT((ndo, " hide"));
220 else if (!strcmp(z.opcode, "USER_UNHIDE"))
221 ND_PRINT((ndo, " unhide"));
223 ND_PRINT((ndo, " locate %s", z.inst));
227 if (!strcmp(z.class, "ZEPHYR_ADMIN")) {
228 ND_PRINT((ndo, " zephyr-admin %s", str_to_lower(z.opcode)));
232 if (!strcmp(z.class, "ZEPHYR_CTL")) {
233 if (!strcmp(z.inst, "CLIENT")) {
234 if (!strcmp(z.opcode, "SUBSCRIBE") ||
235 !strcmp(z.opcode, "SUBSCRIBE_NODEFS") ||
236 !strcmp(z.opcode, "UNSUBSCRIBE")) {
238 ND_PRINT((ndo, " %ssub%s", strcmp(z.opcode, "SUBSCRIBE") ? "un" : "",
239 strcmp(z.opcode, "SUBSCRIBE_NODEFS") ? "" :
241 if (z.kind != Z_PACKET_SERVACK) {
242 /* Initialization to silence warnings */
243 const char *c = NULL, *i = NULL, *r = NULL;
247 if (!lose) ND_PRINT((ndo, " %s", z_triple(c, i, r)));
252 if (!strcmp(z.opcode, "GIMME")) {
253 ND_PRINT((ndo, " ret"));
257 if (!strcmp(z.opcode, "GIMMEDEFS")) {
258 ND_PRINT((ndo, " gimme-defs"));
262 if (!strcmp(z.opcode, "CLEARSUB")) {
263 ND_PRINT((ndo, " clear-subs"));
267 ND_PRINT((ndo, " %s", str_to_lower(z.opcode)));
271 if (!strcmp(z.inst, "HM")) {
272 ND_PRINT((ndo, " %s", str_to_lower(z.opcode)));
276 if (!strcmp(z.inst, "REALM")) {
277 if (!strcmp(z.opcode, "ADD_SUBSCRIBE"))
278 ND_PRINT((ndo, " realm add-subs"));
279 if (!strcmp(z.opcode, "REQ_SUBSCRIBE"))
280 ND_PRINT((ndo, " realm req-subs"));
281 if (!strcmp(z.opcode, "RLM_SUBSCRIBE"))
282 ND_PRINT((ndo, " realm rlm-sub"));
283 if (!strcmp(z.opcode, "RLM_UNSUBSCRIBE"))
284 ND_PRINT((ndo, " realm rlm-unsub"));
289 if (!strcmp(z.class, "HM_CTL")) {
290 ND_PRINT((ndo, " hm_ctl %s", str_to_lower(z.inst)));
291 ND_PRINT((ndo, " %s", str_to_lower(z.opcode)));
295 if (!strcmp(z.class, "HM_STAT")) {
296 if (!strcmp(z.inst, "HMST_CLIENT") && !strcmp(z.opcode, "GIMMESTATS")) {
297 ND_PRINT((ndo, " get-client-stats"));
302 if (!strcmp(z.class, "WG_CTL")) {
303 ND_PRINT((ndo, " wg_ctl %s", str_to_lower(z.inst)));
304 ND_PRINT((ndo, " %s", str_to_lower(z.opcode)));
308 if (!strcmp(z.class, "LOGIN")) {
309 if (!strcmp(z.opcode, "USER_FLUSH")) {
310 ND_PRINT((ndo, " flush_locs"));
314 if (!strcmp(z.opcode, "NONE") ||
315 !strcmp(z.opcode, "OPSTAFF") ||
316 !strcmp(z.opcode, "REALM-VISIBLE") ||
317 !strcmp(z.opcode, "REALM-ANNOUNCED") ||
318 !strcmp(z.opcode, "NET-VISIBLE") ||
319 !strcmp(z.opcode, "NET-ANNOUNCED")) {
320 ND_PRINT((ndo, " set-exposure %s", str_to_lower(z.opcode)));
328 ND_PRINT((ndo, " to %s", z_triple(z.class, z.inst, z.recipient)));
330 ND_PRINT((ndo, " op %s", z.opcode));
334 ND_PRINT((ndo, " [|zephyr] (%d)", length));