2 * Copyright (c) 2003 Bruce M. Simpson <bms@spc.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bruce M. Simpson.
16 * 4. Neither the name of Bruce M. Simpson nor the names of co-
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bruce M. Simpson AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Bruce M. Simpson OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 static const char rcsid
[] _U_
=
35 "@(#) $Header: /tcpdump/master/tcpdump/print-aodv.c,v 1.11 2004-03-24 00:30:19 guy Exp $ (LBL)";
42 #include <tcpdump-stdinc.h>
49 #include "interface.h"
50 #include "addrtoname.h"
51 #include "extract.h" /* must come after interface.h */
56 aodv_extension(const struct aodv_ext
*ep
, u_int length
)
59 const struct aodv_hello
*ah
;
63 if (snapend
< (u_char
*) ep
) {
67 i
= min(length
, (u_int
)(snapend
- (u_char
*)ep
));
68 if (i
< sizeof(struct aodv_hello
)) {
72 i
-= sizeof(struct aodv_hello
);
74 printf("\n\text HELLO %ld ms",
75 (unsigned long)EXTRACT_32BITS(&ah
->interval
));
79 printf("\n\text %u %u", ep
->type
, ep
->length
);
85 aodv_rreq(const struct aodv_rreq
*ap
, const u_char
*dat
, u_int length
)
93 i
= min(length
, (u_int
)(snapend
- dat
));
94 if (i
< sizeof(*ap
)) {
99 printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
100 "\tdst %s seq %lu src %s seq %lu", length
,
101 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
102 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
103 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
104 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
105 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
107 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
108 ipaddr_string(&ap
->rreq_da
),
109 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
110 ipaddr_string(&ap
->rreq_oa
),
111 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
));
112 if (i
>= sizeof(struct aodv_ext
))
113 aodv_extension((void *)(ap
+ 1), i
);
117 aodv_rrep(const struct aodv_rrep
*ap
, const u_char
*dat
, u_int length
)
125 i
= min(length
, (u_int
)(snapend
- dat
));
126 if (i
< sizeof(*ap
)) {
131 printf(" rrep %u %s%sprefix %u hops %u\n"
132 "\tdst %s dseq %lu src %s %lu ms", length
,
133 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
134 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
135 ap
->rrep_ps
& RREP_PREFIX_MASK
,
137 ipaddr_string(&ap
->rrep_da
),
138 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
139 ipaddr_string(&ap
->rrep_oa
),
140 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
));
141 if (i
>= sizeof(struct aodv_ext
))
142 aodv_extension((void *)(ap
+ 1), i
);
146 aodv_rerr(const struct aodv_rerr
*ap
, const u_char
*dat
, u_int length
)
149 const struct rerr_unreach
*dp
= NULL
;
156 i
= min(length
, (u_int
)(snapend
- dat
));
157 if (i
< offsetof(struct aodv_rerr
, r
)) {
161 i
-= offsetof(struct aodv_rerr
, r
);
163 n
= ap
->rerr_dc
* sizeof(ap
->r
.dest
[0]);
164 printf(" rerr %s [items %u] [%u]:",
165 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
166 ap
->rerr_dc
, length
);
167 trunc
= n
- (i
/sizeof(ap
->r
.dest
[0]));
168 for (; i
>= sizeof(ap
->r
.dest
[0]);
169 ++dp
, i
-= sizeof(ap
->r
.dest
[0])) {
170 printf(" {%s}(%ld)", ipaddr_string(&dp
->u_da
),
171 (unsigned long)EXTRACT_32BITS(&dp
->u_ds
));
179 aodv_v6_rreq(const struct aodv_rreq6
*ap
, const u_char
*dat
, u_int length
)
181 aodv_v6_rreq(const struct aodv_rreq6
*ap _U_
, const u_char
*dat _U_
, u_int length
)
191 i
= min(length
, (u_int
)(snapend
- dat
));
192 if (i
< sizeof(*ap
)) {
197 printf(" v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
198 "\tdst %s seq %lu src %s seq %lu", length
,
199 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
200 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
201 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
202 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
203 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
205 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
206 ip6addr_string(&ap
->rreq_da
),
207 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
208 ip6addr_string(&ap
->rreq_oa
),
209 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
));
210 if (i
>= sizeof(struct aodv_ext
))
211 aodv_extension((void *)(ap
+ 1), i
);
213 printf(" v6 rreq %u", length
);
219 aodv_v6_rrep(const struct aodv_rrep6
*ap
, const u_char
*dat
, u_int length
)
221 aodv_v6_rrep(const struct aodv_rrep6
*ap _U_
, const u_char
*dat _U_
, u_int length
)
231 i
= min(length
, (u_int
)(snapend
- dat
));
232 if (i
< sizeof(*ap
)) {
237 printf(" rrep %u %s%sprefix %u hops %u\n"
238 "\tdst %s dseq %lu src %s %lu ms", length
,
239 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
240 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
241 ap
->rrep_ps
& RREP_PREFIX_MASK
,
243 ip6addr_string(&ap
->rrep_da
),
244 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
245 ip6addr_string(&ap
->rrep_oa
),
246 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
));
247 if (i
>= sizeof(struct aodv_ext
))
248 aodv_extension((void *)(ap
+ 1), i
);
250 printf(" rrep %u", length
);
256 aodv_v6_rerr(const struct aodv_rerr
*ap
, u_int length
)
258 aodv_v6_rerr(const struct aodv_rerr
*ap _U_
, u_int length
)
262 const struct rerr_unreach6
*dp6
= NULL
;
265 i
= length
- offsetof(struct aodv_rerr
, r
);
266 j
= sizeof(ap
->r
.dest6
[0]);
267 dp6
= &ap
->r
.dest6
[0];
269 printf(" rerr %s [items %u] [%u]:",
270 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
271 ap
->rerr_dc
, length
);
273 for (; i
-= j
>= 0; ++dp6
) {
274 printf(" {%s}(%ld)", ip6addr_string(&dp6
->u_da
),
275 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
));
280 printf(" rerr %u", length
);
286 aodv_v6_draft_01_rreq(const struct aodv_rreq6_draft_01
*ap
, const u_char
*dat
, u_int length
)
288 aodv_v6_draft_01_rreq(const struct aodv_rreq6_draft_01
*ap _U_
, const u_char
*dat _U_
, u_int length
)
298 i
= min(length
, (u_int
)(snapend
- dat
));
299 if (i
< sizeof(*ap
)) {
304 printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
305 "\tdst %s seq %lu src %s seq %lu", length
,
306 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
307 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
308 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
309 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
310 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
312 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
313 ip6addr_string(&ap
->rreq_da
),
314 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
315 ip6addr_string(&ap
->rreq_oa
),
316 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
));
317 if (i
>= sizeof(struct aodv_ext
))
318 aodv_extension((void *)(ap
+ 1), i
);
320 printf(" rreq %u", length
);
326 aodv_v6_draft_01_rrep(const struct aodv_rrep6_draft_01
*ap
, const u_char
*dat
, u_int length
)
328 aodv_v6_draft_01_rrep(const struct aodv_rrep6_draft_01
*ap _U_
, const u_char
*dat _U_
, u_int length
)
338 i
= min(length
, (u_int
)(snapend
- dat
));
339 if (i
< sizeof(*ap
)) {
344 printf(" rrep %u %s%sprefix %u hops %u\n"
345 "\tdst %s dseq %lu src %s %lu ms", length
,
346 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
347 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
348 ap
->rrep_ps
& RREP_PREFIX_MASK
,
350 ip6addr_string(&ap
->rrep_da
),
351 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
352 ip6addr_string(&ap
->rrep_oa
),
353 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
));
354 if (i
>= sizeof(struct aodv_ext
))
355 aodv_extension((void *)(ap
+ 1), i
);
357 printf(" rrep %u", length
);
363 aodv_v6_draft_01_rerr(const struct aodv_rerr
*ap
, u_int length
)
365 aodv_v6_draft_01_rerr(const struct aodv_rerr
*ap _U_
, u_int length
)
369 const struct rerr_unreach6_draft_01
*dp6
= NULL
;
372 i
= length
- offsetof(struct aodv_rerr
, r
);
373 j
= sizeof(ap
->r
.dest6_draft_01
[0]);
374 dp6
= &ap
->r
.dest6_draft_01
[0];
376 printf(" rerr %s [items %u] [%u]:",
377 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
378 ap
->rerr_dc
, length
);
380 for (; i
-= j
>= 0; ++dp6
) {
381 printf(" {%s}(%ld)", ip6addr_string(&dp6
->u_da
),
382 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
));
387 printf(" rerr %u", length
);
392 aodv_print(const u_char
*dat
, u_int length
, int is_ip6
)
397 * The message type is the first byte; make sure we have it
408 aodv_v6_rreq((const struct aodv_rreq6
*)dat
, dat
, length
);
410 aodv_rreq((const struct aodv_rreq
*)dat
, dat
, length
);
415 aodv_v6_rrep((const struct aodv_rrep6
*)dat
, dat
, length
);
417 aodv_rrep((const struct aodv_rrep
*)dat
, dat
, length
);
422 aodv_v6_rerr((const struct aodv_rerr
*)dat
, length
);
424 aodv_rerr((const struct aodv_rerr
*)dat
, dat
, length
);
428 printf(" rrep-ack %u", length
);
431 case AODV_V6_DRAFT_01_RREQ
:
432 aodv_v6_draft_01_rreq((const struct aodv_rreq6_draft_01
*)dat
, dat
, length
);
435 case AODV_V6_DRAFT_01_RREP
:
436 aodv_v6_draft_01_rrep((const struct aodv_rrep6_draft_01
*)dat
, dat
, length
);
439 case AODV_V6_DRAFT_01_RERR
:
440 aodv_v6_draft_01_rerr((const struct aodv_rerr
*)dat
, length
);
443 case AODV_V6_DRAFT_01_RREP_ACK
:
444 printf(" rrep-ack %u", length
);
448 printf(" type %u %u", msg_type
, length
);