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.
23 static const char rcsid[] _U_ =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-wb.c,v 1.33 2004/03/24 04:06:28 guy Exp $ (LBL)";
33 #include <tcpdump-stdinc.h>
37 #include "interface.h"
38 #include "addrtoname.h"
41 /* XXX need to add byte-swapping macros! */
42 /* XXX - you mean like the ones in "extract.h"? */
45 * Largest packet size. Everything should fit within this space.
46 * For instance, multiline objects are sent piecewise.
48 #define MAXFRAMESIZE 1024
51 * Multiple drawing ops can be sent in one packet. Each one starts on a
52 * an even multiple of DOP_ALIGN bytes, which must be a power of two.
55 #define DOP_ROUNDUP(x) ((((int)(x)) + (DOP_ALIGN - 1)) & ~(DOP_ALIGN - 1))
57 ((struct dophdr *)((u_char *)(d) + \
58 DOP_ROUNDUP(EXTRACT_16BITS(&(d)->dh_len) + sizeof(*(d)))))
61 * Format of the whiteboard packet header.
62 * The transport level header.
65 u_int32_t ph_src; /* site id of source */
66 u_int32_t ph_ts; /* time stamp (for skew computation) */
67 u_int16_t ph_version; /* version number */
68 u_char ph_type; /* message type */
69 u_char ph_flags; /* message flags */
73 #define PT_DRAWOP 0 /* drawing operation */
74 #define PT_ID 1 /* announcement packet */
75 #define PT_RREQ 2 /* repair request */
76 #define PT_RREP 3 /* repair reply */
77 #define PT_KILL 4 /* terminate participation */
78 #define PT_PREQ 5 /* page vector request */
79 #define PT_PREP 7 /* page vector reply */
82 #undef PF_USER /* {Digital,Tru64} UNIX define this, alas */
86 #define PF_USER 0x01 /* hint that packet has interactive data */
87 #define PF_VIS 0x02 /* only visible ops wanted */
90 u_int32_t p_sid; /* session id of initiator */
91 u_int32_t p_uid; /* page number */
95 u_int32_t dh_ts; /* sender's timestamp */
96 u_int16_t dh_len; /* body length */
98 u_char dh_type; /* body type */
102 * Drawing op sub-types.
118 #define DT_MAXTYPE 15
121 * A drawing operation.
124 struct PageID pd_page; /* page that operations apply to */
125 u_int32_t pd_sseq; /* start sequence number */
126 u_int32_t pd_eseq; /* end sequence number */
127 /* drawing ops follow */
134 u_int32_t pr_id; /* source id of drawops to be repaired */
135 struct PageID pr_page; /* page of drawops */
136 u_int32_t pr_sseq; /* start seqno */
137 u_int32_t pr_eseq; /* end seqno */
144 u_int32_t pr_id; /* original site id of ops */
145 struct pkt_dop pr_dop;
146 /* drawing ops follow */
163 * An announcement packet.
167 struct PageID pi_mpage; /* current page */
168 struct pgstate pi_ps;
170 /* null-terminated site name */
174 struct PageID pp_page;
180 u_int32_t pp_n; /* size of pageid array */
181 /* pgstate's follow */
185 wb_id(const struct pkt_id *id, u_int len)
189 const struct id_off *io;
194 if (len < sizeof(*id) || (u_char *)(id + 1) > snapend)
198 printf(" %u/%s:%u (max %u/%s:%u) ",
199 EXTRACT_32BITS(&id->pi_ps.slot),
200 ipaddr_string(&id->pi_ps.page.p_sid),
201 EXTRACT_32BITS(&id->pi_ps.page.p_uid),
202 EXTRACT_32BITS(&id->pi_mslot),
203 ipaddr_string(&id->pi_mpage.p_sid),
204 EXTRACT_32BITS(&id->pi_mpage.p_uid));
206 nid = EXTRACT_16BITS(&id->pi_ps.nid);
207 len -= sizeof(*io) * nid;
208 io = (struct id_off *)(id + 1);
209 cp = (char *)(io + nid);
210 if ((u_char *)cp + len <= snapend) {
212 (void)fn_print((u_char *)cp, (u_char *)cp + len);
217 for (i = 0; i < nid && (u_char *)(io + 1) <= snapend; ++io, ++i) {
219 c, ipaddr_string(&io->id), EXTRACT_32BITS(&io->off));
230 wb_rreq(const struct pkt_rreq *rreq, u_int len)
233 if (len < sizeof(*rreq) || (u_char *)(rreq + 1) > snapend)
236 printf(" please repair %s %s:%u<%u:%u>",
237 ipaddr_string(&rreq->pr_id),
238 ipaddr_string(&rreq->pr_page.p_sid),
239 EXTRACT_32BITS(&rreq->pr_page.p_uid),
240 EXTRACT_32BITS(&rreq->pr_sseq),
241 EXTRACT_32BITS(&rreq->pr_eseq));
246 wb_preq(const struct pkt_preq *preq, u_int len)
249 if (len < sizeof(*preq) || (u_char *)(preq + 1) > snapend)
252 printf(" need %u/%s:%u",
253 EXTRACT_32BITS(&preq->pp_low),
254 ipaddr_string(&preq->pp_page.p_sid),
255 EXTRACT_32BITS(&preq->pp_page.p_uid));
260 wb_prep(const struct pkt_prep *prep, u_int len)
263 const struct pgstate *ps;
264 const u_char *ep = snapend;
267 if (len < sizeof(*prep)) {
270 n = EXTRACT_32BITS(&prep->pp_n);
271 ps = (const struct pgstate *)(prep + 1);
272 while (--n >= 0 && (u_char *)(ps + 1) <= ep) {
273 const struct id_off *io, *ie;
277 EXTRACT_32BITS(&ps->slot),
278 ipaddr_string(&ps->page.p_sid),
279 EXTRACT_32BITS(&ps->page.p_uid));
280 io = (struct id_off *)(ps + 1);
281 for (ie = io + ps->nid; io < ie && (u_char *)(io + 1) <= ep; ++io) {
282 printf("%c%s:%u", c, ipaddr_string(&io->id),
283 EXTRACT_32BITS(&io->off));
287 ps = (struct pgstate *)io;
289 return ((u_char *)ps <= ep? 0 : -1);
293 const char *dopstr[] = {
313 wb_dops(const struct dophdr *dh, u_int32_t ss, u_int32_t es)
316 for ( ; ss <= es; ++ss) {
317 register int t = dh->dh_type;
320 printf(" dop-%d!", t);
322 printf(" %s", dopstr[t]);
323 if (t == DT_SKIP || t == DT_HOLE) {
324 u_int32_t ts = EXTRACT_32BITS(&dh->dh_ts);
325 printf("%d", ts - ss + 1);
326 if (ss > ts || ts > es) {
335 if ((u_char *)dh > snapend) {
345 wb_rrep(const struct pkt_rrep *rrep, u_int len)
347 const struct pkt_dop *dop = &rrep->pr_dop;
350 if (len < sizeof(*rrep) || (u_char *)(rrep + 1) > snapend)
352 len -= sizeof(*rrep);
354 printf(" for %s %s:%u<%u:%u>",
355 ipaddr_string(&rrep->pr_id),
356 ipaddr_string(&dop->pd_page.p_sid),
357 EXTRACT_32BITS(&dop->pd_page.p_uid),
358 EXTRACT_32BITS(&dop->pd_sseq),
359 EXTRACT_32BITS(&dop->pd_eseq));
362 return (wb_dops((const struct dophdr *)(dop + 1),
363 EXTRACT_32BITS(&dop->pd_sseq),
364 EXTRACT_32BITS(&dop->pd_eseq)));
369 wb_drawop(const struct pkt_dop *dop, u_int len)
372 if (len < sizeof(*dop) || (u_char *)(dop + 1) > snapend)
376 printf(" %s:%u<%u:%u>",
377 ipaddr_string(&dop->pd_page.p_sid),
378 EXTRACT_32BITS(&dop->pd_page.p_uid),
379 EXTRACT_32BITS(&dop->pd_sseq),
380 EXTRACT_32BITS(&dop->pd_eseq));
383 return (wb_dops((const struct dophdr *)(dop + 1),
384 EXTRACT_32BITS(&dop->pd_sseq),
385 EXTRACT_32BITS(&dop->pd_eseq)));
390 * Print whiteboard multicast packets.
393 wb_print(register const void *hdr, register u_int len)
395 register const struct pkt_hdr *ph;
397 ph = (const struct pkt_hdr *)hdr;
398 if (len < sizeof(*ph) || (u_char *)(ph + 1) > snapend) {
406 switch (ph->ph_type) {
413 if (wb_id((struct pkt_id *)(ph + 1), len) >= 0)
418 if (wb_rreq((struct pkt_rreq *)(ph + 1), len) >= 0)
423 if (wb_rrep((struct pkt_rrep *)(ph + 1), len) >= 0)
428 if (wb_drawop((struct pkt_dop *)(ph + 1), len) >= 0)
433 if (wb_preq((struct pkt_preq *)(ph + 1), len) >= 0)
438 if (wb_prep((struct pkt_prep *)(ph + 1), len) >= 0)
443 printf(" wb-%d!", ph->ph_type);