]>
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
27 #include <tcpdump-stdinc.h>
33 #include "interface.h"
48 const char *recipient
;
52 const char *multi_uid
;
53 /* Other fields follow here.. */
68 static const struct tok z_types
[] = {
69 { Z_PACKET_UNSAFE
, "unsafe" },
70 { Z_PACKET_UNACKED
, "unacked" },
71 { Z_PACKET_ACKED
, "acked" },
72 { Z_PACKET_HMACK
, "hm-ack" },
73 { Z_PACKET_HMCTL
, "hm-ctl" },
74 { Z_PACKET_SERVACK
, "serv-ack" },
75 { Z_PACKET_SERVNAK
, "serv-nak" },
76 { Z_PACKET_CLIENTACK
, "client-ack" },
77 { Z_PACKET_STAT
, "stat" }
80 static char z_buf
[256];
83 parse_field(netdissect_options
*ndo
, const char **pptr
, int *len
)
87 if (*len
<= 0 || !pptr
|| !*pptr
)
89 if (*pptr
> (const char *) ndo
->ndo_snapend
)
93 while (*pptr
<= (const char *) ndo
->ndo_snapend
&& *len
>= 0 && **pptr
) {
99 if (*len
< 0 || *pptr
> (const char *) ndo
->ndo_snapend
)
105 z_triple(const char *class, const char *inst
, const char *recipient
)
109 snprintf(z_buf
, sizeof(z_buf
), "<%s,%s,%s>", class, inst
, recipient
);
110 z_buf
[sizeof(z_buf
)-1] = '\0';
115 str_to_lower(const char *string
)
119 strncpy(z_buf
, string
, sizeof(z_buf
));
120 z_buf
[sizeof(z_buf
)-1] = '\0';
124 *zb_string
= tolower((unsigned char)(*zb_string
));
132 zephyr_print(netdissect_options
*ndo
, const u_char
*cp
, int length
)
135 const char *parse
= (const char *) cp
;
136 int parselen
= length
;
140 /* squelch compiler warnings */
149 #define PARSE_STRING \
150 s = parse_field(ndo, &parse, &parselen); \
153 #define PARSE_FIELD_INT(field) \
155 if (!lose) field = strtol(s, 0, 16);
157 #define PARSE_FIELD_STR(field) \
159 if (!lose) field = s;
161 PARSE_FIELD_STR(z
.version
);
163 if (strncmp(z
.version
, "ZEPH", 4))
166 PARSE_FIELD_INT(z
.numfields
);
167 PARSE_FIELD_INT(z
.kind
);
168 PARSE_FIELD_STR(z
.uid
);
169 PARSE_FIELD_INT(z
.port
);
170 PARSE_FIELD_INT(z
.auth
);
171 PARSE_FIELD_INT(z
.authlen
);
172 PARSE_FIELD_STR(z
.authdata
);
173 PARSE_FIELD_STR(z
.class);
174 PARSE_FIELD_STR(z
.inst
);
175 PARSE_FIELD_STR(z
.opcode
);
176 PARSE_FIELD_STR(z
.sender
);
177 PARSE_FIELD_STR(z
.recipient
);
178 PARSE_FIELD_STR(z
.format
);
179 PARSE_FIELD_INT(z
.cksum
);
180 PARSE_FIELD_INT(z
.multi
);
181 PARSE_FIELD_STR(z
.multi_uid
);
184 ND_PRINT((ndo
, " [|zephyr] (%d)", length
));
188 ND_PRINT((ndo
, " zephyr"));
189 if (strncmp(z
.version
+4, "0.2", 3)) {
190 ND_PRINT((ndo
, " v%s", z
.version
+4));
194 ND_PRINT((ndo
, " %s", tok2str(z_types
, "type %d", z
.kind
)));
195 if (z
.kind
== Z_PACKET_SERVACK
) {
196 /* Initialization to silence warnings */
197 const char *ackdata
= NULL
;
198 PARSE_FIELD_STR(ackdata
);
199 if (!lose
&& strcmp(ackdata
, "SENT"))
200 ND_PRINT((ndo
, "/%s", str_to_lower(ackdata
)));
202 if (*z
.sender
) ND_PRINT((ndo
, " %s", z
.sender
));
204 if (!strcmp(z
.class, "USER_LOCATE")) {
205 if (!strcmp(z
.opcode
, "USER_HIDE"))
206 ND_PRINT((ndo
, " hide"));
207 else if (!strcmp(z
.opcode
, "USER_UNHIDE"))
208 ND_PRINT((ndo
, " unhide"));
210 ND_PRINT((ndo
, " locate %s", z
.inst
));
214 if (!strcmp(z
.class, "ZEPHYR_ADMIN")) {
215 ND_PRINT((ndo
, " zephyr-admin %s", str_to_lower(z
.opcode
)));
219 if (!strcmp(z
.class, "ZEPHYR_CTL")) {
220 if (!strcmp(z
.inst
, "CLIENT")) {
221 if (!strcmp(z
.opcode
, "SUBSCRIBE") ||
222 !strcmp(z
.opcode
, "SUBSCRIBE_NODEFS") ||
223 !strcmp(z
.opcode
, "UNSUBSCRIBE")) {
225 ND_PRINT((ndo
, " %ssub%s", strcmp(z
.opcode
, "SUBSCRIBE") ? "un" : "",
226 strcmp(z
.opcode
, "SUBSCRIBE_NODEFS") ? "" :
228 if (z
.kind
!= Z_PACKET_SERVACK
) {
229 /* Initialization to silence warnings */
230 const char *c
= NULL
, *i
= NULL
, *r
= NULL
;
234 if (!lose
) ND_PRINT((ndo
, " %s", z_triple(c
, i
, r
)));
239 if (!strcmp(z
.opcode
, "GIMME")) {
240 ND_PRINT((ndo
, " ret"));
244 if (!strcmp(z
.opcode
, "GIMMEDEFS")) {
245 ND_PRINT((ndo
, " gimme-defs"));
249 if (!strcmp(z
.opcode
, "CLEARSUB")) {
250 ND_PRINT((ndo
, " clear-subs"));
254 ND_PRINT((ndo
, " %s", str_to_lower(z
.opcode
)));
258 if (!strcmp(z
.inst
, "HM")) {
259 ND_PRINT((ndo
, " %s", str_to_lower(z
.opcode
)));
263 if (!strcmp(z
.inst
, "REALM")) {
264 if (!strcmp(z
.opcode
, "ADD_SUBSCRIBE"))
265 ND_PRINT((ndo
, " realm add-subs"));
266 if (!strcmp(z
.opcode
, "REQ_SUBSCRIBE"))
267 ND_PRINT((ndo
, " realm req-subs"));
268 if (!strcmp(z
.opcode
, "RLM_SUBSCRIBE"))
269 ND_PRINT((ndo
, " realm rlm-sub"));
270 if (!strcmp(z
.opcode
, "RLM_UNSUBSCRIBE"))
271 ND_PRINT((ndo
, " realm rlm-unsub"));
276 if (!strcmp(z
.class, "HM_CTL")) {
277 ND_PRINT((ndo
, " hm_ctl %s", str_to_lower(z
.inst
)));
278 ND_PRINT((ndo
, " %s", str_to_lower(z
.opcode
)));
282 if (!strcmp(z
.class, "HM_STAT")) {
283 if (!strcmp(z
.inst
, "HMST_CLIENT") && !strcmp(z
.opcode
, "GIMMESTATS")) {
284 ND_PRINT((ndo
, " get-client-stats"));
289 if (!strcmp(z
.class, "WG_CTL")) {
290 ND_PRINT((ndo
, " wg_ctl %s", str_to_lower(z
.inst
)));
291 ND_PRINT((ndo
, " %s", str_to_lower(z
.opcode
)));
295 if (!strcmp(z
.class, "LOGIN")) {
296 if (!strcmp(z
.opcode
, "USER_FLUSH")) {
297 ND_PRINT((ndo
, " flush_locs"));
301 if (!strcmp(z
.opcode
, "NONE") ||
302 !strcmp(z
.opcode
, "OPSTAFF") ||
303 !strcmp(z
.opcode
, "REALM-VISIBLE") ||
304 !strcmp(z
.opcode
, "REALM-ANNOUNCED") ||
305 !strcmp(z
.opcode
, "NET-VISIBLE") ||
306 !strcmp(z
.opcode
, "NET-ANNOUNCED")) {
307 ND_PRINT((ndo
, " set-exposure %s", str_to_lower(z
.opcode
)));
315 ND_PRINT((ndo
, " to %s", z_triple(z
.class, z
.inst
, z
.recipient
)));
317 ND_PRINT((ndo
, " op %s", z
.opcode
));