]>
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
;
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" }
83 parse_field(char **pptr
, int *len
)
87 if (*len
<= 0 || !pptr
|| !*pptr
)
89 if (*pptr
> (char *) snapend
)
93 while (*pptr
<= (char *) snapend
&& *len
>= 0 && **pptr
) {
99 if (*len
< 0 || *pptr
> (char *) snapend
)
105 z_triple(char *class, 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(char *string
)
117 strncpy(z_buf
, string
, sizeof(z_buf
));
118 z_buf
[sizeof(z_buf
)-1] = '\0';
122 *string
= tolower((unsigned char)(*string
));
130 zephyr_print(const u_char
*cp
, int length
)
133 char *parse
= (char *) cp
;
134 int parselen
= length
;
138 /* squelch compiler warnings */
147 #define PARSE_STRING \
148 s = parse_field(&parse, &parselen); \
151 #define PARSE_FIELD_INT(field) \
153 if (!lose) field = strtol(s, 0, 16);
155 #define PARSE_FIELD_STR(field) \
157 if (!lose) field = s;
159 PARSE_FIELD_STR(z
.version
);
161 if (strncmp(z
.version
, "ZEPH", 4))
164 PARSE_FIELD_INT(z
.numfields
);
165 PARSE_FIELD_INT(z
.kind
);
166 PARSE_FIELD_STR(z
.uid
);
167 PARSE_FIELD_INT(z
.port
);
168 PARSE_FIELD_INT(z
.auth
);
169 PARSE_FIELD_INT(z
.authlen
);
170 PARSE_FIELD_STR(z
.authdata
);
171 PARSE_FIELD_STR(z
.class);
172 PARSE_FIELD_STR(z
.inst
);
173 PARSE_FIELD_STR(z
.opcode
);
174 PARSE_FIELD_STR(z
.sender
);
175 PARSE_FIELD_STR(z
.recipient
);
176 PARSE_FIELD_STR(z
.format
);
177 PARSE_FIELD_INT(z
.cksum
);
178 PARSE_FIELD_INT(z
.multi
);
179 PARSE_FIELD_STR(z
.multi_uid
);
182 printf(" [|zephyr] (%d)", length
);
187 if (strncmp(z
.version
+4, "0.2", 3)) {
188 printf(" v%s", z
.version
+4);
192 printf(" %s", tok2str(z_types
, "type %d", z
.kind
));
193 if (z
.kind
== Z_PACKET_SERVACK
) {
194 /* Initialization to silence warnings */
195 char *ackdata
= NULL
;
196 PARSE_FIELD_STR(ackdata
);
197 if (!lose
&& strcmp(ackdata
, "SENT"))
198 printf("/%s", str_to_lower(ackdata
));
200 if (*z
.sender
) printf(" %s", z
.sender
);
202 if (!strcmp(z
.class, "USER_LOCATE")) {
203 if (!strcmp(z
.opcode
, "USER_HIDE"))
205 else if (!strcmp(z
.opcode
, "USER_UNHIDE"))
208 printf(" locate %s", z
.inst
);
212 if (!strcmp(z
.class, "ZEPHYR_ADMIN")) {
213 printf(" zephyr-admin %s", str_to_lower(z
.opcode
));
217 if (!strcmp(z
.class, "ZEPHYR_CTL")) {
218 if (!strcmp(z
.inst
, "CLIENT")) {
219 if (!strcmp(z
.opcode
, "SUBSCRIBE") ||
220 !strcmp(z
.opcode
, "SUBSCRIBE_NODEFS") ||
221 !strcmp(z
.opcode
, "UNSUBSCRIBE")) {
223 printf(" %ssub%s", strcmp(z
.opcode
, "SUBSCRIBE") ? "un" : "",
224 strcmp(z
.opcode
, "SUBSCRIBE_NODEFS") ? "" :
226 if (z
.kind
!= Z_PACKET_SERVACK
) {
227 /* Initialization to silence warnings */
228 char *c
= NULL
, *i
= NULL
, *r
= NULL
;
232 if (!lose
) printf(" %s", z_triple(c
, i
, r
));
237 if (!strcmp(z
.opcode
, "GIMME")) {
242 if (!strcmp(z
.opcode
, "GIMMEDEFS")) {
243 printf(" gimme-defs");
247 if (!strcmp(z
.opcode
, "CLEARSUB")) {
248 printf(" clear-subs");
252 printf(" %s", str_to_lower(z
.opcode
));
256 if (!strcmp(z
.inst
, "HM")) {
257 printf(" %s", str_to_lower(z
.opcode
));
261 if (!strcmp(z
.inst
, "REALM")) {
262 if (!strcmp(z
.opcode
, "ADD_SUBSCRIBE"))
263 printf(" realm add-subs");
264 if (!strcmp(z
.opcode
, "REQ_SUBSCRIBE"))
265 printf(" realm req-subs");
266 if (!strcmp(z
.opcode
, "RLM_SUBSCRIBE"))
267 printf(" realm rlm-sub");
268 if (!strcmp(z
.opcode
, "RLM_UNSUBSCRIBE"))
269 printf(" realm rlm-unsub");
274 if (!strcmp(z
.class, "HM_CTL")) {
275 printf(" hm_ctl %s", str_to_lower(z
.inst
));
276 printf(" %s", str_to_lower(z
.opcode
));
280 if (!strcmp(z
.class, "HM_STAT")) {
281 if (!strcmp(z
.inst
, "HMST_CLIENT") && !strcmp(z
.opcode
, "GIMMESTATS")) {
282 printf(" get-client-stats");
287 if (!strcmp(z
.class, "WG_CTL")) {
288 printf(" wg_ctl %s", str_to_lower(z
.inst
));
289 printf(" %s", str_to_lower(z
.opcode
));
293 if (!strcmp(z
.class, "LOGIN")) {
294 if (!strcmp(z
.opcode
, "USER_FLUSH")) {
295 printf(" flush_locs");
299 if (!strcmp(z
.opcode
, "NONE") ||
300 !strcmp(z
.opcode
, "OPSTAFF") ||
301 !strcmp(z
.opcode
, "REALM-VISIBLE") ||
302 !strcmp(z
.opcode
, "REALM-ANNOUNCED") ||
303 !strcmp(z
.opcode
, "NET-VISIBLE") ||
304 !strcmp(z
.opcode
, "NET-ANNOUNCED")) {
305 printf(" set-exposure %s", str_to_lower(z
.opcode
));
313 printf(" to %s", z_triple(z
.class, z
.inst
, z
.recipient
));
315 printf(" op %s", z
.opcode
);