]>
The Tcpdump Group git mirrors - tcpdump/blob - print-zephyr.c
2 * Decode and print Zephyr packets.
4 * https://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-ctype.h"
37 #include "netdissect.h"
53 const char *recipient
;
57 const char *multi_uid
;
58 /* Other fields follow here.. */
73 static const 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" },
86 static char z_buf
[256];
89 parse_field(netdissect_options
*ndo
, const char **pptr
, int *len
)
95 /* Scan for the NUL terminator */
98 /* Ran out of packet data without finding it */
101 if (GET_U_1(*pptr
) == '\0') {
109 /* Skip the NUL terminator */
116 z_triple(const char *class, const char *inst
, const char *recipient
)
120 snprintf(z_buf
, sizeof(z_buf
), "<%s,%s,%s>", class, inst
, recipient
);
121 z_buf
[sizeof(z_buf
)-1] = '\0';
126 str_to_lower(const char *string
)
130 strncpy(z_buf
, string
, sizeof(z_buf
));
131 z_buf
[sizeof(z_buf
)-1] = '\0';
135 *zb_string
= ND_ASCII_TOLOWER(*zb_string
);
143 zephyr_print(netdissect_options
*ndo
, const u_char
*cp
, u_int length
)
145 struct z_packet z
= {
158 NULL
, /* recipient */
164 const char *parse
= (const char *) cp
;
165 int parselen
= length
;
169 ndo
->ndo_protocol
= "zephyr";
170 /* squelch compiler warnings */
172 #define PARSE_STRING \
173 s = parse_field(ndo, &parse, &parselen); \
176 #define PARSE_FIELD_INT(field) \
178 if (!lose) field = strtol(s, 0, 16);
180 #define PARSE_FIELD_STR(field) \
182 if (!lose) field = s;
184 PARSE_FIELD_STR(z
.version
);
188 if (strncmp(z
.version
, "ZEPH", 4))
191 PARSE_FIELD_INT(z
.numfields
);
192 PARSE_FIELD_INT(z
.kind
);
193 PARSE_FIELD_STR(z
.uid
);
194 PARSE_FIELD_INT(z
.port
);
195 PARSE_FIELD_INT(z
.auth
);
196 PARSE_FIELD_INT(z
.authlen
);
197 PARSE_FIELD_STR(z
.authdata
);
198 PARSE_FIELD_STR(z
.class);
199 PARSE_FIELD_STR(z
.inst
);
200 PARSE_FIELD_STR(z
.opcode
);
201 PARSE_FIELD_STR(z
.sender
);
202 PARSE_FIELD_STR(z
.recipient
);
203 PARSE_FIELD_STR(z
.format
);
204 PARSE_FIELD_INT(z
.cksum
);
205 PARSE_FIELD_INT(z
.multi
);
206 PARSE_FIELD_STR(z
.multi_uid
);
212 if (strncmp(z
.version
+4, "0.2", 3)) {
213 ND_PRINT(" v%s", z
.version
+4);
217 ND_PRINT(" %s", tok2str(z_types
, "type %d", z
.kind
));
218 if (z
.kind
== Z_PACKET_SERVACK
) {
219 /* Initialization to silence warnings */
220 const char *ackdata
= NULL
;
221 PARSE_FIELD_STR(ackdata
);
222 if (!lose
&& strcmp(ackdata
, "SENT"))
223 ND_PRINT("/%s", str_to_lower(ackdata
));
225 if (*z
.sender
) ND_PRINT(" %s", z
.sender
);
227 if (!strcmp(z
.class, "USER_LOCATE")) {
228 if (!strcmp(z
.opcode
, "USER_HIDE"))
230 else if (!strcmp(z
.opcode
, "USER_UNHIDE"))
233 ND_PRINT(" locate %s", z
.inst
);
237 if (!strcmp(z
.class, "ZEPHYR_ADMIN")) {
238 ND_PRINT(" zephyr-admin %s", str_to_lower(z
.opcode
));
242 if (!strcmp(z
.class, "ZEPHYR_CTL")) {
243 if (!strcmp(z
.inst
, "CLIENT")) {
244 if (!strcmp(z
.opcode
, "SUBSCRIBE") ||
245 !strcmp(z
.opcode
, "SUBSCRIBE_NODEFS") ||
246 !strcmp(z
.opcode
, "UNSUBSCRIBE")) {
248 ND_PRINT(" %ssub%s", strcmp(z
.opcode
, "SUBSCRIBE") ? "un" : "",
249 strcmp(z
.opcode
, "SUBSCRIBE_NODEFS") ? "" :
251 if (z
.kind
!= Z_PACKET_SERVACK
) {
252 /* Initialization to silence warnings */
253 const char *c
= NULL
, *i
= NULL
, *r
= NULL
;
257 if (!lose
) ND_PRINT(" %s", z_triple(c
, i
, r
));
262 if (!strcmp(z
.opcode
, "GIMME")) {
267 if (!strcmp(z
.opcode
, "GIMMEDEFS")) {
268 ND_PRINT(" gimme-defs");
272 if (!strcmp(z
.opcode
, "CLEARSUB")) {
273 ND_PRINT(" clear-subs");
277 ND_PRINT(" %s", str_to_lower(z
.opcode
));
281 if (!strcmp(z
.inst
, "HM")) {
282 ND_PRINT(" %s", str_to_lower(z
.opcode
));
286 if (!strcmp(z
.inst
, "REALM")) {
287 if (!strcmp(z
.opcode
, "ADD_SUBSCRIBE"))
288 ND_PRINT(" realm add-subs");
289 if (!strcmp(z
.opcode
, "REQ_SUBSCRIBE"))
290 ND_PRINT(" realm req-subs");
291 if (!strcmp(z
.opcode
, "RLM_SUBSCRIBE"))
292 ND_PRINT(" realm rlm-sub");
293 if (!strcmp(z
.opcode
, "RLM_UNSUBSCRIBE"))
294 ND_PRINT(" realm rlm-unsub");
299 if (!strcmp(z
.class, "HM_CTL")) {
300 ND_PRINT(" hm_ctl %s", str_to_lower(z
.inst
));
301 ND_PRINT(" %s", str_to_lower(z
.opcode
));
305 if (!strcmp(z
.class, "HM_STAT")) {
306 if (!strcmp(z
.inst
, "HMST_CLIENT") && !strcmp(z
.opcode
, "GIMMESTATS")) {
307 ND_PRINT(" get-client-stats");
312 if (!strcmp(z
.class, "WG_CTL")) {
313 ND_PRINT(" wg_ctl %s", str_to_lower(z
.inst
));
314 ND_PRINT(" %s", str_to_lower(z
.opcode
));
318 if (!strcmp(z
.class, "LOGIN")) {
319 if (!strcmp(z
.opcode
, "USER_FLUSH")) {
320 ND_PRINT(" flush_locs");
324 if (!strcmp(z
.opcode
, "NONE") ||
325 !strcmp(z
.opcode
, "OPSTAFF") ||
326 !strcmp(z
.opcode
, "REALM-VISIBLE") ||
327 !strcmp(z
.opcode
, "REALM-ANNOUNCED") ||
328 !strcmp(z
.opcode
, "NET-VISIBLE") ||
329 !strcmp(z
.opcode
, "NET-ANNOUNCED")) {
330 ND_PRINT(" set-exposure %s", str_to_lower(z
.opcode
));
338 ND_PRINT(" to %s", z_triple(z
.class, z
.inst
, z
.recipient
));
340 ND_PRINT(" op %s", z
.opcode
);
344 nd_print_invalid(ndo
);