]>
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 /* \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_SIZE(*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
)
147 struct z_packet z
= {0};
148 const char *parse
= (const char *) cp
;
149 int parselen
= length
;
154 /* squelch compiler warnings */
156 #define PARSE_STRING \
157 s = parse_field(ndo, &parse, &parselen, &truncated); \
158 if (truncated) goto trunc; \
161 #define PARSE_FIELD_INT(field) \
163 if (!lose) field = strtol(s, 0, 16);
165 #define PARSE_FIELD_STR(field) \
167 if (!lose) field = s;
169 PARSE_FIELD_STR(z
.version
);
171 if (strncmp(z
.version
, "ZEPH", 4))
174 PARSE_FIELD_INT(z
.numfields
);
175 PARSE_FIELD_INT(z
.kind
);
176 PARSE_FIELD_STR(z
.uid
);
177 PARSE_FIELD_INT(z
.port
);
178 PARSE_FIELD_INT(z
.auth
);
179 PARSE_FIELD_INT(z
.authlen
);
180 PARSE_FIELD_STR(z
.authdata
);
181 PARSE_FIELD_STR(z
.class);
182 PARSE_FIELD_STR(z
.inst
);
183 PARSE_FIELD_STR(z
.opcode
);
184 PARSE_FIELD_STR(z
.sender
);
185 PARSE_FIELD_STR(z
.recipient
);
186 PARSE_FIELD_STR(z
.format
);
187 PARSE_FIELD_INT(z
.cksum
);
188 PARSE_FIELD_INT(z
.multi
);
189 PARSE_FIELD_STR(z
.multi_uid
);
195 if (strncmp(z
.version
+4, "0.2", 3)) {
196 ND_PRINT(" v%s", z
.version
+4);
200 ND_PRINT(" %s", tok2str(z_types
, "type %d", z
.kind
));
201 if (z
.kind
== Z_PACKET_SERVACK
) {
202 /* Initialization to silence warnings */
203 const char *ackdata
= NULL
;
204 PARSE_FIELD_STR(ackdata
);
205 if (!lose
&& strcmp(ackdata
, "SENT"))
206 ND_PRINT("/%s", str_to_lower(ackdata
));
208 if (*z
.sender
) ND_PRINT(" %s", z
.sender
);
210 if (!strcmp(z
.class, "USER_LOCATE")) {
211 if (!strcmp(z
.opcode
, "USER_HIDE"))
213 else if (!strcmp(z
.opcode
, "USER_UNHIDE"))
216 ND_PRINT(" locate %s", z
.inst
);
220 if (!strcmp(z
.class, "ZEPHYR_ADMIN")) {
221 ND_PRINT(" zephyr-admin %s", str_to_lower(z
.opcode
));
225 if (!strcmp(z
.class, "ZEPHYR_CTL")) {
226 if (!strcmp(z
.inst
, "CLIENT")) {
227 if (!strcmp(z
.opcode
, "SUBSCRIBE") ||
228 !strcmp(z
.opcode
, "SUBSCRIBE_NODEFS") ||
229 !strcmp(z
.opcode
, "UNSUBSCRIBE")) {
231 ND_PRINT(" %ssub%s", strcmp(z
.opcode
, "SUBSCRIBE") ? "un" : "",
232 strcmp(z
.opcode
, "SUBSCRIBE_NODEFS") ? "" :
234 if (z
.kind
!= Z_PACKET_SERVACK
) {
235 /* Initialization to silence warnings */
236 const char *c
= NULL
, *i
= NULL
, *r
= NULL
;
240 if (!lose
) ND_PRINT(" %s", z_triple(c
, i
, r
));
245 if (!strcmp(z
.opcode
, "GIMME")) {
250 if (!strcmp(z
.opcode
, "GIMMEDEFS")) {
251 ND_PRINT(" gimme-defs");
255 if (!strcmp(z
.opcode
, "CLEARSUB")) {
256 ND_PRINT(" clear-subs");
260 ND_PRINT(" %s", str_to_lower(z
.opcode
));
264 if (!strcmp(z
.inst
, "HM")) {
265 ND_PRINT(" %s", str_to_lower(z
.opcode
));
269 if (!strcmp(z
.inst
, "REALM")) {
270 if (!strcmp(z
.opcode
, "ADD_SUBSCRIBE"))
271 ND_PRINT(" realm add-subs");
272 if (!strcmp(z
.opcode
, "REQ_SUBSCRIBE"))
273 ND_PRINT(" realm req-subs");
274 if (!strcmp(z
.opcode
, "RLM_SUBSCRIBE"))
275 ND_PRINT(" realm rlm-sub");
276 if (!strcmp(z
.opcode
, "RLM_UNSUBSCRIBE"))
277 ND_PRINT(" realm rlm-unsub");
282 if (!strcmp(z
.class, "HM_CTL")) {
283 ND_PRINT(" hm_ctl %s", str_to_lower(z
.inst
));
284 ND_PRINT(" %s", str_to_lower(z
.opcode
));
288 if (!strcmp(z
.class, "HM_STAT")) {
289 if (!strcmp(z
.inst
, "HMST_CLIENT") && !strcmp(z
.opcode
, "GIMMESTATS")) {
290 ND_PRINT(" get-client-stats");
295 if (!strcmp(z
.class, "WG_CTL")) {
296 ND_PRINT(" wg_ctl %s", str_to_lower(z
.inst
));
297 ND_PRINT(" %s", str_to_lower(z
.opcode
));
301 if (!strcmp(z
.class, "LOGIN")) {
302 if (!strcmp(z
.opcode
, "USER_FLUSH")) {
303 ND_PRINT(" flush_locs");
307 if (!strcmp(z
.opcode
, "NONE") ||
308 !strcmp(z
.opcode
, "OPSTAFF") ||
309 !strcmp(z
.opcode
, "REALM-VISIBLE") ||
310 !strcmp(z
.opcode
, "REALM-ANNOUNCED") ||
311 !strcmp(z
.opcode
, "NET-VISIBLE") ||
312 !strcmp(z
.opcode
, "NET-ANNOUNCED")) {
313 ND_PRINT(" set-exposure %s", str_to_lower(z
.opcode
));
321 ND_PRINT(" to %s", z_triple(z
.class, z
.inst
, z
.recipient
));
323 ND_PRINT(" op %s", z
.opcode
);
327 ND_PRINT(" [|zephyr] (%d)", length
);