]>
The Tcpdump Group git mirrors - tcpdump/blob - print-wb.c
2 * Copyright (c) 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 /* \summary: White Board printer */
28 #include "netdissect-stdinc.h"
30 #include "netdissect.h"
31 #include "addrtoname.h"
35 /* XXX need to add byte-swapping macros! */
36 /* XXX - you mean like the ones in "extract.h"? */
39 * Largest packet size. Everything should fit within this space.
40 * For instance, multiline objects are sent piecewise.
42 #define MAXFRAMESIZE 1024
45 * Multiple drawing ops can be sent in one packet. Each one starts on a
46 * an even multiple of DOP_ALIGN bytes, which must be a power of two.
49 #define DOP_ROUNDUP(x) roundup2(x, DOP_ALIGN)
51 ((const struct dophdr *)((const u_char *)(d) + \
52 DOP_ROUNDUP(GET_BE_U_2((d)->dh_len) + sizeof(*(d)))))
55 * Format of the whiteboard packet header.
56 * The transport level header.
59 nd_uint32_t ph_src
; /* site id of source */
60 nd_uint32_t ph_ts
; /* time stamp (for skew computation) */
61 nd_uint16_t ph_version
; /* version number */
62 nd_uint8_t ph_type
; /* message type */
63 nd_uint8_t ph_flags
; /* message flags */
67 #define PT_DRAWOP 0 /* drawing operation */
68 #define PT_ID 1 /* announcement packet */
69 #define PT_RREQ 2 /* repair request */
70 #define PT_RREP 3 /* repair reply */
71 #define PT_KILL 4 /* terminate participation */
72 #define PT_PREQ 5 /* page vector request */
73 #define PT_PREP 7 /* page vector reply */
76 #undef PF_USER /* {Digital,Tru64} UNIX define this, alas */
80 #define PF_USER 0x01 /* hint that packet has interactive data */
81 #define PF_VIS 0x02 /* only visible ops wanted */
84 nd_uint32_t p_sid
; /* session id of initiator */
85 nd_uint32_t p_uid
; /* page number */
89 nd_uint32_t dh_ts
; /* sender's timestamp */
90 nd_uint16_t dh_len
; /* body length */
92 nd_uint8_t dh_type
; /* body type */
96 * Drawing op sub-types.
112 #define DT_MAXTYPE 15
115 * A drawing operation.
118 struct PageID pd_page
; /* page that operations apply to */
119 nd_uint32_t pd_sseq
; /* start sequence number */
120 nd_uint32_t pd_eseq
; /* end sequence number */
121 /* drawing ops follow */
128 nd_uint32_t pr_id
; /* source id of drawops to be repaired */
129 struct PageID pr_page
; /* page of drawops */
130 nd_uint32_t pr_sseq
; /* start seqno */
131 nd_uint32_t pr_eseq
; /* end seqno */
138 nd_uint32_t pr_id
; /* original site id of ops */
139 struct pkt_dop pr_dop
;
140 /* drawing ops follow */
157 * An announcement packet.
160 nd_uint32_t pi_mslot
;
161 struct PageID pi_mpage
; /* current page */
162 struct pgstate pi_ps
;
164 /* null-terminated site name */
168 struct PageID pp_page
;
174 nd_uint32_t pp_n
; /* size of pageid array */
175 /* pgstate's follow */
179 wb_id(netdissect_options
*ndo
,
180 const struct pkt_id
*id
, u_int len
)
184 const struct id_off
*io
;
189 if (len
< sizeof(*id
) || !ND_TTEST_SIZE(id
))
193 ND_PRINT(" %u/%s:%u (max %u/%s:%u) ",
194 GET_BE_U_4(id
->pi_ps
.slot
),
195 GET_IPADDR_STRING(id
->pi_ps
.page
.p_sid
),
196 GET_BE_U_4(id
->pi_ps
.page
.p_uid
),
197 GET_BE_U_4(id
->pi_mslot
),
198 GET_IPADDR_STRING(id
->pi_mpage
.p_sid
),
199 GET_BE_U_4(id
->pi_mpage
.p_uid
));
201 nid
= GET_BE_U_2(id
->pi_ps
.nid
);
202 len
-= sizeof(*io
) * nid
;
203 io
= (const struct id_off
*)(id
+ 1);
204 cp
= (const char *)(io
+ nid
);
205 if (ND_TTEST_LEN(cp
, len
)) {
207 nd_print(ndo
, (const u_char
*)cp
, (const u_char
*)cp
+ len
);
212 for (i
= 0; i
< nid
&& ND_TTEST_SIZE(io
); ++io
, ++i
) {
214 c
, GET_IPADDR_STRING(io
->id
), GET_BE_U_4(io
->off
));
225 wb_rreq(netdissect_options
*ndo
,
226 const struct pkt_rreq
*rreq
, u_int len
)
228 ND_PRINT(" wb-rreq:");
229 if (len
< sizeof(*rreq
) || !ND_TTEST_SIZE(rreq
))
232 ND_PRINT(" please repair %s %s:%u<%u:%u>",
233 GET_IPADDR_STRING(rreq
->pr_id
),
234 GET_IPADDR_STRING(rreq
->pr_page
.p_sid
),
235 GET_BE_U_4(rreq
->pr_page
.p_uid
),
236 GET_BE_U_4(rreq
->pr_sseq
),
237 GET_BE_U_4(rreq
->pr_eseq
));
242 wb_preq(netdissect_options
*ndo
,
243 const struct pkt_preq
*preq
, u_int len
)
245 ND_PRINT(" wb-preq:");
246 if (len
< sizeof(*preq
) || !ND_TTEST_SIZE(preq
))
249 ND_PRINT(" need %u/%s:%u",
250 GET_BE_U_4(preq
->pp_low
),
251 GET_IPADDR_STRING(preq
->pp_page
.p_sid
),
252 GET_BE_U_4(preq
->pp_page
.p_uid
));
257 wb_prep(netdissect_options
*ndo
,
258 const struct pkt_prep
*prep
, u_int len
)
261 const struct pgstate
*ps
;
262 const u_char
*ep
= ndo
->ndo_snapend
;
264 ND_PRINT(" wb-prep:");
265 if (len
< sizeof(*prep
) || !ND_TTEST_SIZE(prep
))
267 n
= GET_BE_U_4(prep
->pp_n
);
268 ps
= (const struct pgstate
*)(prep
+ 1);
269 while (n
!= 0 && ND_TTEST_SIZE(ps
)) {
270 const struct id_off
*io
, *ie
;
273 ND_PRINT(" %u/%s:%u",
274 GET_BE_U_4(ps
->slot
),
275 GET_IPADDR_STRING(ps
->page
.p_sid
),
276 GET_BE_U_4(ps
->page
.p_uid
));
277 io
= (const struct id_off
*)(ps
+ 1);
278 for (ie
= io
+ GET_U_1(ps
->nid
); io
< ie
&& ND_TTEST_SIZE(io
); ++io
) {
279 ND_PRINT("%c%s:%u", c
, GET_IPADDR_STRING(io
->id
),
280 GET_BE_U_4(io
->off
));
284 ps
= (const struct pgstate
*)io
;
287 return ((const u_char
*)ps
<= ep
? 0 : -1);
291 static const char *dopstr
[] = {
311 wb_dops(netdissect_options
*ndo
, const struct pkt_dop
*dop
,
312 uint32_t ss
, uint32_t es
)
314 const struct dophdr
*dh
= (const struct dophdr
*)((const u_char
*)dop
+ sizeof(*dop
));
317 for ( ; ss
<= es
; ++ss
) {
320 if (!ND_TTEST_SIZE(dh
)) {
324 t
= GET_U_1(dh
->dh_type
);
327 ND_PRINT(" dop-%u!", t
);
329 ND_PRINT(" %s", dopstr
[t
]);
330 if (t
== DT_SKIP
|| t
== DT_HOLE
) {
331 uint32_t ts
= GET_BE_U_4(dh
->dh_ts
);
332 ND_PRINT("%u", ts
- ss
+ 1);
333 if (ss
> ts
|| ts
> es
) {
348 wb_rrep(netdissect_options
*ndo
,
349 const struct pkt_rrep
*rrep
, u_int len
)
351 const struct pkt_dop
*dop
= &rrep
->pr_dop
;
353 ND_PRINT(" wb-rrep:");
354 if (len
< sizeof(*rrep
) || !ND_TTEST_SIZE(rrep
))
356 len
-= sizeof(*rrep
);
358 ND_PRINT(" for %s %s:%u<%u:%u>",
359 GET_IPADDR_STRING(rrep
->pr_id
),
360 GET_IPADDR_STRING(dop
->pd_page
.p_sid
),
361 GET_BE_U_4(dop
->pd_page
.p_uid
),
362 GET_BE_U_4(dop
->pd_sseq
),
363 GET_BE_U_4(dop
->pd_eseq
));
366 return (wb_dops(ndo
, dop
,
367 GET_BE_U_4(dop
->pd_sseq
),
368 GET_BE_U_4(dop
->pd_eseq
)));
373 wb_drawop(netdissect_options
*ndo
,
374 const struct pkt_dop
*dop
, u_int len
)
376 ND_PRINT(" wb-dop:");
377 if (len
< sizeof(*dop
) || !ND_TTEST_SIZE(dop
))
381 ND_PRINT(" %s:%u<%u:%u>",
382 GET_IPADDR_STRING(dop
->pd_page
.p_sid
),
383 GET_BE_U_4(dop
->pd_page
.p_uid
),
384 GET_BE_U_4(dop
->pd_sseq
),
385 GET_BE_U_4(dop
->pd_eseq
));
388 return (wb_dops(ndo
, dop
,
389 GET_BE_U_4(dop
->pd_sseq
),
390 GET_BE_U_4(dop
->pd_eseq
)));
395 * Print whiteboard multicast packets.
398 wb_print(netdissect_options
*ndo
,
399 const u_char
*hdr
, u_int len
)
401 const struct pkt_hdr
*ph
;
404 ndo
->ndo_protocol
= "wb";
405 ph
= (const struct pkt_hdr
*)hdr
;
406 if (len
< sizeof(*ph
) || !ND_TTEST_SIZE(ph
)) {
412 if (GET_U_1(ph
->ph_flags
))
414 type
= GET_U_1(ph
->ph_type
);
418 ND_PRINT(" wb-kill");
422 if (wb_id(ndo
, (const struct pkt_id
*)(ph
+ 1), len
) >= 0)
428 if (wb_rreq(ndo
, (const struct pkt_rreq
*)(ph
+ 1), len
) >= 0)
434 if (wb_rrep(ndo
, (const struct pkt_rrep
*)(ph
+ 1), len
) >= 0)
440 if (wb_drawop(ndo
, (const struct pkt_dop
*)(ph
+ 1), len
) >= 0)
446 if (wb_preq(ndo
, (const struct pkt_preq
*)(ph
+ 1), len
) >= 0)
452 if (wb_prep(ndo
, (const struct pkt_prep
*)(ph
+ 1), len
) >= 0)
458 ND_PRINT(" wb-%u!", type
);