]>
The Tcpdump Group git mirrors - tcpdump/blob - print-zephyr.c
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 #define NETDISSECT_REWORKED
28 #include <tcpdump-stdinc.h>
34 #include "interface.h"
49 const char *recipient
;
54 /* Other fields follow here.. */
69 static const struct tok z_types
[] = {
70 { Z_PACKET_UNSAFE
, "unsafe" },
71 { Z_PACKET_UNACKED
, "unacked" },
72 { Z_PACKET_ACKED
, "acked" },
73 { Z_PACKET_HMACK
, "hm-ack" },
74 { Z_PACKET_HMCTL
, "hm-ctl" },
75 { Z_PACKET_SERVACK
, "serv-ack" },
76 { Z_PACKET_SERVNAK
, "serv-nak" },
77 { Z_PACKET_CLIENTACK
, "client-ack" },
78 { Z_PACKET_STAT
, "stat" }
81 static char z_buf
[256];
84 parse_field(netdissect_options
*ndo
, char **pptr
, int *len
)
88 if (*len
<= 0 || !pptr
|| !*pptr
)
90 if (*pptr
> (char *) ndo
->ndo_snapend
)
94 while (*pptr
<= (char *) ndo
->ndo_snapend
&& *len
>= 0 && **pptr
) {
100 if (*len
< 0 || *pptr
> (char *) ndo
->ndo_snapend
)
106 z_triple(char *class, char *inst
, const char *recipient
)
110 snprintf(z_buf
, sizeof(z_buf
), "<%s,%s,%s>", class, inst
, recipient
);
111 z_buf
[sizeof(z_buf
)-1] = '\0';
116 str_to_lower(char *string
)
118 strncpy(z_buf
, string
, sizeof(z_buf
));
119 z_buf
[sizeof(z_buf
)-1] = '\0';
123 *string
= tolower((unsigned char)(*string
));
131 zephyr_print(netdissect_options
*ndo
, const u_char
*cp
, int length
)
134 char *parse
= (char *) cp
;
135 int parselen
= length
;
139 /* squelch compiler warnings */
148 #define PARSE_STRING \
149 s = parse_field(ndo, &parse, &parselen); \
152 #define PARSE_FIELD_INT(field) \
154 if (!lose) field = strtol(s, 0, 16);
156 #define PARSE_FIELD_STR(field) \
158 if (!lose) field = s;
160 PARSE_FIELD_STR(z
.version
);
162 if (strncmp(z
.version
, "ZEPH", 4))
165 PARSE_FIELD_INT(z
.numfields
);
166 PARSE_FIELD_INT(z
.kind
);
167 PARSE_FIELD_STR(z
.uid
);
168 PARSE_FIELD_INT(z
.port
);
169 PARSE_FIELD_INT(z
.auth
);
170 PARSE_FIELD_INT(z
.authlen
);
171 PARSE_FIELD_STR(z
.authdata
);
172 PARSE_FIELD_STR(z
.class);
173 PARSE_FIELD_STR(z
.inst
);
174 PARSE_FIELD_STR(z
.opcode
);
175 PARSE_FIELD_STR(z
.sender
);
176 PARSE_FIELD_STR(z
.recipient
);
177 PARSE_FIELD_STR(z
.format
);
178 PARSE_FIELD_INT(z
.cksum
);
179 PARSE_FIELD_INT(z
.multi
);
180 PARSE_FIELD_STR(z
.multi_uid
);
183 ND_PRINT((ndo
, " [|zephyr] (%d)", length
));
187 ND_PRINT((ndo
, " zephyr"));
188 if (strncmp(z
.version
+4, "0.2", 3)) {
189 ND_PRINT((ndo
, " v%s", z
.version
+4));
193 ND_PRINT((ndo
, " %s", tok2str(z_types
, "type %d", z
.kind
)));
194 if (z
.kind
== Z_PACKET_SERVACK
) {
195 /* Initialization to silence warnings */
196 char *ackdata
= NULL
;
197 PARSE_FIELD_STR(ackdata
);
198 if (!lose
&& strcmp(ackdata
, "SENT"))
199 ND_PRINT((ndo
, "/%s", str_to_lower(ackdata
)));
201 if (*z
.sender
) ND_PRINT((ndo
, " %s", z
.sender
));
203 if (!strcmp(z
.class, "USER_LOCATE")) {
204 if (!strcmp(z
.opcode
, "USER_HIDE"))
205 ND_PRINT((ndo
, " hide"));
206 else if (!strcmp(z
.opcode
, "USER_UNHIDE"))
207 ND_PRINT((ndo
, " unhide"));
209 ND_PRINT((ndo
, " locate %s", z
.inst
));
213 if (!strcmp(z
.class, "ZEPHYR_ADMIN")) {
214 ND_PRINT((ndo
, " zephyr-admin %s", str_to_lower(z
.opcode
)));
218 if (!strcmp(z
.class, "ZEPHYR_CTL")) {
219 if (!strcmp(z
.inst
, "CLIENT")) {
220 if (!strcmp(z
.opcode
, "SUBSCRIBE") ||
221 !strcmp(z
.opcode
, "SUBSCRIBE_NODEFS") ||
222 !strcmp(z
.opcode
, "UNSUBSCRIBE")) {
224 ND_PRINT((ndo
, " %ssub%s", strcmp(z
.opcode
, "SUBSCRIBE") ? "un" : "",
225 strcmp(z
.opcode
, "SUBSCRIBE_NODEFS") ? "" :
227 if (z
.kind
!= Z_PACKET_SERVACK
) {
228 /* Initialization to silence warnings */
229 char *c
= NULL
, *i
= NULL
, *r
= NULL
;
233 if (!lose
) ND_PRINT((ndo
, " %s", z_triple(c
, i
, r
)));
238 if (!strcmp(z
.opcode
, "GIMME")) {
239 ND_PRINT((ndo
, " ret"));
243 if (!strcmp(z
.opcode
, "GIMMEDEFS")) {
244 ND_PRINT((ndo
, " gimme-defs"));
248 if (!strcmp(z
.opcode
, "CLEARSUB")) {
249 ND_PRINT((ndo
, " clear-subs"));
253 ND_PRINT((ndo
, " %s", str_to_lower(z
.opcode
)));
257 if (!strcmp(z
.inst
, "HM")) {
258 ND_PRINT((ndo
, " %s", str_to_lower(z
.opcode
)));
262 if (!strcmp(z
.inst
, "REALM")) {
263 if (!strcmp(z
.opcode
, "ADD_SUBSCRIBE"))
264 ND_PRINT((ndo
, " realm add-subs"));
265 if (!strcmp(z
.opcode
, "REQ_SUBSCRIBE"))
266 ND_PRINT((ndo
, " realm req-subs"));
267 if (!strcmp(z
.opcode
, "RLM_SUBSCRIBE"))
268 ND_PRINT((ndo
, " realm rlm-sub"));
269 if (!strcmp(z
.opcode
, "RLM_UNSUBSCRIBE"))
270 ND_PRINT((ndo
, " realm rlm-unsub"));
275 if (!strcmp(z
.class, "HM_CTL")) {
276 ND_PRINT((ndo
, " hm_ctl %s", str_to_lower(z
.inst
)));
277 ND_PRINT((ndo
, " %s", str_to_lower(z
.opcode
)));
281 if (!strcmp(z
.class, "HM_STAT")) {
282 if (!strcmp(z
.inst
, "HMST_CLIENT") && !strcmp(z
.opcode
, "GIMMESTATS")) {
283 ND_PRINT((ndo
, " get-client-stats"));
288 if (!strcmp(z
.class, "WG_CTL")) {
289 ND_PRINT((ndo
, " wg_ctl %s", str_to_lower(z
.inst
)));
290 ND_PRINT((ndo
, " %s", str_to_lower(z
.opcode
)));
294 if (!strcmp(z
.class, "LOGIN")) {
295 if (!strcmp(z
.opcode
, "USER_FLUSH")) {
296 ND_PRINT((ndo
, " flush_locs"));
300 if (!strcmp(z
.opcode
, "NONE") ||
301 !strcmp(z
.opcode
, "OPSTAFF") ||
302 !strcmp(z
.opcode
, "REALM-VISIBLE") ||
303 !strcmp(z
.opcode
, "REALM-ANNOUNCED") ||
304 !strcmp(z
.opcode
, "NET-VISIBLE") ||
305 !strcmp(z
.opcode
, "NET-ANNOUNCED")) {
306 ND_PRINT((ndo
, " set-exposure %s", str_to_lower(z
.opcode
)));
314 ND_PRINT((ndo
, " to %s", z_triple(z
.class, z
.inst
, z
.recipient
)));
316 ND_PRINT((ndo
, " op %s", z
.opcode
));