]>
git.saurik.com Git - apple/network_cmds.git/blob - tcpdump.tproj/print-wb.c
3b0c1601748d2f86dbb9cde06ee6ae2d56660b12
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1993, 1994, 1995, 1996
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that: (1) source code distributions
30 * retain the above copyright notice and this paragraph in its entirety, (2)
31 * distributions including binary code include the above copyright notice and
32 * this paragraph in its entirety in the documentation or other materials
33 * provided with the distribution, and (3) all advertising materials mentioning
34 * features or use of this software display the following acknowledgement:
35 * ``This product includes software developed by the University of California,
36 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
37 * the University nor the names of its contributors may be used to endorse
38 * or promote products derived from this software without specific prior
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
41 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
46 static const char rcsid
[] =
47 "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-wb.c,v 1.1.1.1 1999/05/02 03:58:35 wsanchez Exp $ (LBL)";
50 #include <sys/types.h>
53 #include <netinet/in.h>
57 #include "interface.h"
58 #include "addrtoname.h"
60 /* XXX need to add byte-swapping macros! */
63 * Largest packet size. Everything should fit within this space.
64 * For instance, multiline objects are sent piecewise.
66 #define MAXFRAMESIZE 1024
69 * Multiple drawing ops can be sent in one packet. Each one starts on a
70 * an even multiple of DOP_ALIGN bytes, which must be a power of two.
73 #define DOP_ROUNDUP(x) ((((int)(x)) + (DOP_ALIGN - 1)) & ~(DOP_ALIGN - 1))
75 ((struct dophdr *)((u_char *)(d) + \
76 DOP_ROUNDUP(ntohs((d)->dh_len) + sizeof(*(d)))))
79 * Format of the whiteboard packet header.
80 * The transport level header.
83 u_int32_t ph_src
; /* site id of source */
84 u_int32_t ph_ts
; /* time stamp (for skew computation) */
85 u_short ph_version
; /* version number */
86 u_char ph_type
; /* message type */
87 u_char ph_flags
; /* message flags */
91 #define PT_DRAWOP 0 /* drawing operation */
92 #define PT_ID 1 /* announcement packet */
93 #define PT_RREQ 2 /* repair request */
94 #define PT_RREP 3 /* repair reply */
95 #define PT_KILL 4 /* terminate participation */
96 #define PT_PREQ 5 /* page vector request */
97 #define PT_PREP 7 /* page vector reply */
100 #define PF_USER 0x01 /* hint that packet has interactive data */
101 #define PF_VIS 0x02 /* only visible ops wanted */
104 u_int32_t p_sid
; /* session id of initiator */
105 u_int32_t p_uid
; /* page number */
109 u_int32_t dh_ts
; /* sender's timestamp */
110 u_short dh_len
; /* body length */
112 u_char dh_type
; /* body type */
116 * Drawing op sub-types.
132 #define DT_MAXTYPE 15
135 * A drawing operation.
138 struct PageID pd_page
; /* page that operations apply to */
139 u_int32_t pd_sseq
; /* start sequence number */
140 u_int32_t pd_eseq
; /* end sequence number */
141 /* drawing ops follow */
148 u_int32_t pr_id
; /* source id of drawops to be repaired */
149 struct PageID pr_page
; /* page of drawops */
150 u_int32_t pr_sseq
; /* start seqno */
151 u_int32_t pr_eseq
; /* end seqno */
158 u_int32_t pr_id
; /* original site id of ops */
159 struct pkt_dop pr_dop
;
160 /* drawing ops follow */
177 * An announcement packet.
181 struct PageID pi_mpage
; /* current page */
182 struct pgstate pi_ps
;
184 /* null-terminated site name */
188 struct PageID pp_page
;
194 u_int32_t pp_n
; /* size of pageid array */
195 /* pgstate's follow */
199 wb_id(const struct pkt_id
*id
, u_int len
)
203 const struct id_off
*io
;
209 if (len
< 0 || (u_char
*)(id
+ 1) > snapend
)
212 printf(" %u/%s:%u (max %u/%s:%u) ",
213 (u_int32_t
)ntohl(id
->pi_ps
.slot
),
214 ipaddr_string(&id
->pi_ps
.page
.p_sid
),
215 (u_int32_t
)ntohl(id
->pi_ps
.page
.p_uid
),
216 (u_int32_t
)ntohl(id
->pi_mslot
),
217 ipaddr_string(&id
->pi_mpage
.p_sid
),
218 (u_int32_t
)ntohl(id
->pi_mpage
.p_uid
));
220 nid
= ntohs(id
->pi_ps
.nid
);
221 len
-= sizeof(*io
) * nid
;
222 io
= (struct id_off
*)(id
+ 1);
223 cp
= (char *)(io
+ nid
);
224 if ((u_char
*)cp
+ len
<= snapend
) {
226 (void)fn_print((u_char
*)cp
, (u_char
*)cp
+ len
);
231 for (i
= 0; i
< nid
&& (u_char
*)io
< snapend
; ++io
, ++i
) {
233 c
, ipaddr_string(&io
->id
), (u_int32_t
)ntohl(io
->off
));
244 wb_rreq(const struct pkt_rreq
*rreq
, u_int len
)
247 if (len
< sizeof(*rreq
) || (u_char
*)(rreq
+ 1) > snapend
)
250 printf(" please repair %s %s:%u<%u:%u>",
251 ipaddr_string(&rreq
->pr_id
),
252 ipaddr_string(&rreq
->pr_page
.p_sid
),
253 (u_int32_t
)ntohl(rreq
->pr_page
.p_uid
),
254 (u_int32_t
)ntohl(rreq
->pr_sseq
),
255 (u_int32_t
)ntohl(rreq
->pr_eseq
));
260 wb_preq(const struct pkt_preq
*preq
, u_int len
)
263 if (len
< sizeof(*preq
) || (u_char
*)(preq
+ 1) > snapend
)
266 printf(" need %u/%s:%u",
267 (u_int32_t
)ntohl(preq
->pp_low
),
268 ipaddr_string(&preq
->pp_page
.p_sid
),
269 (u_int32_t
)ntohl(preq
->pp_page
.p_uid
));
274 wb_prep(const struct pkt_prep
*prep
, u_int len
)
277 const struct pgstate
*ps
;
278 const u_char
*ep
= snapend
;
281 if (len
< sizeof(*prep
)) {
284 n
= ntohl(prep
->pp_n
);
285 ps
= (const struct pgstate
*)(prep
+ 1);
286 while (--n
>= 0 && (u_char
*)ps
< ep
) {
287 const struct id_off
*io
, *ie
;
291 (u_int32_t
)ntohl(ps
->slot
),
292 ipaddr_string(&ps
->page
.p_sid
),
293 (u_int32_t
)ntohl(ps
->page
.p_uid
));
294 io
= (struct id_off
*)(ps
+ 1);
295 for (ie
= io
+ ps
->nid
; io
< ie
&& (u_char
*)io
< ep
; ++io
) {
296 printf("%c%s:%u", c
, ipaddr_string(&io
->id
),
297 (u_int32_t
)ntohl(io
->off
));
301 ps
= (struct pgstate
*)io
;
303 return ((u_char
*)ps
<= ep
? 0 : -1);
327 wb_dops(const struct dophdr
*dh
, u_int32_t ss
, u_int32_t es
)
330 for ( ; ss
<= es
; ++ss
) {
331 register int t
= dh
->dh_type
;
334 printf(" dop-%d!", t
);
336 printf(" %s", dopstr
[t
]);
337 if (t
== DT_SKIP
|| t
== DT_HOLE
) {
338 int ts
= ntohl(dh
->dh_ts
);
339 printf("%d", ts
- ss
+ 1);
340 if (ss
> ts
|| ts
> es
) {
349 if ((u_char
*)dh
> snapend
) {
359 wb_rrep(const struct pkt_rrep
*rrep
, u_int len
)
361 const struct pkt_dop
*dop
= &rrep
->pr_dop
;
364 len
-= sizeof(*rrep
);
365 if (len
< 0 || (u_char
*)(rrep
+ 1) > snapend
)
368 printf(" for %s %s:%u<%u:%u>",
369 ipaddr_string(&rrep
->pr_id
),
370 ipaddr_string(&dop
->pd_page
.p_sid
),
371 (u_int32_t
)ntohl(dop
->pd_page
.p_uid
),
372 (u_int32_t
)ntohl(dop
->pd_sseq
),
373 (u_int32_t
)ntohl(dop
->pd_eseq
));
376 return (wb_dops((const struct dophdr
*)(dop
+ 1),
377 ntohl(dop
->pd_sseq
), ntohl(dop
->pd_eseq
)));
382 wb_drawop(const struct pkt_dop
*dop
, u_int len
)
386 if (len
< 0 || (u_char
*)(dop
+ 1) > snapend
)
389 printf(" %s:%u<%u:%u>",
390 ipaddr_string(&dop
->pd_page
.p_sid
),
391 (u_int32_t
)ntohl(dop
->pd_page
.p_uid
),
392 (u_int32_t
)ntohl(dop
->pd_sseq
),
393 (u_int32_t
)ntohl(dop
->pd_eseq
));
396 return (wb_dops((const struct dophdr
*)(dop
+ 1),
397 ntohl(dop
->pd_sseq
), ntohl(dop
->pd_eseq
)));
402 * Print whiteboard multicast packets.
405 wb_print(register const void *hdr
, register u_int len
)
407 register const struct pkt_hdr
*ph
;
409 ph
= (const struct pkt_hdr
*)hdr
;
411 if (len
< 0 || (u_char
*)(ph
+ 1) <= snapend
) {
414 switch (ph
->ph_type
) {
421 if (wb_id((struct pkt_id
*)(ph
+ 1), len
) >= 0)
426 if (wb_rreq((struct pkt_rreq
*)(ph
+ 1), len
) >= 0)
431 if (wb_rrep((struct pkt_rrep
*)(ph
+ 1), len
) >= 0)
436 if (wb_drawop((struct pkt_dop
*)(ph
+ 1), len
) >= 0)
441 if (wb_preq((struct pkt_preq
*)(ph
+ 1), len
) >= 0)
446 if (wb_prep((struct pkt_prep
*)(ph
+ 1), len
) >= 0)
451 printf(" wb-%d!", ph
->ph_type
);