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>
48 #include "interface.h"
49 #include "addrtoname.h"
50 #include "extract.h" /* must come after interface.h */
55 aodv_extension(const struct aodv_ext
*ep
, u_int length
)
57 const struct aodv_hello
*ah
;
61 ah
= (const struct aodv_hello
*)(const void *)ep
;
63 if (length
< sizeof(struct aodv_hello
))
65 printf("\n\text HELLO %ld ms",
66 (unsigned long)EXTRACT_32BITS(&ah
->interval
));
70 printf("\n\text %u %u", ep
->type
, ep
->length
);
80 aodv_rreq(const u_char
*dat
, u_int length
)
83 const struct aodv_rreq
*ap
= (const struct aodv_rreq
*)dat
;
86 if (length
< sizeof(*ap
))
88 printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
89 "\tdst %s seq %lu src %s seq %lu", length
,
90 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
91 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
92 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
93 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
94 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
96 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
97 ipaddr_string(&ap
->rreq_da
),
98 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
99 ipaddr_string(&ap
->rreq_oa
),
100 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
));
101 i
= length
- sizeof(*ap
);
102 if (i
>= sizeof(struct aodv_ext
))
103 aodv_extension((const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
111 aodv_rrep(const u_char
*dat
, u_int length
)
114 const struct aodv_rrep
*ap
= (const struct aodv_rrep
*)dat
;
117 if (length
< sizeof(*ap
))
119 printf(" rrep %u %s%sprefix %u hops %u\n"
120 "\tdst %s dseq %lu src %s %lu ms", length
,
121 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
122 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
123 ap
->rrep_ps
& RREP_PREFIX_MASK
,
125 ipaddr_string(&ap
->rrep_da
),
126 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
127 ipaddr_string(&ap
->rrep_oa
),
128 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
));
129 i
= length
- sizeof(*ap
);
130 if (i
>= sizeof(struct aodv_ext
))
131 aodv_extension((const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
139 aodv_rerr(const u_char
*dat
, u_int length
)
142 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
143 const struct rerr_unreach
*dp
;
146 if (length
< sizeof(*ap
))
148 printf(" rerr %s [items %u] [%u]:",
149 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
150 ap
->rerr_dc
, length
);
151 dp
= (struct rerr_unreach
*)(dat
+ sizeof(*ap
));
152 i
= length
- sizeof(*ap
);
153 for (dc
= ap
->rerr_dc
; dc
!= 0 && i
>= sizeof(*dp
);
154 ++dp
, --dc
, i
-= sizeof(*dp
)) {
156 printf(" {%s}(%ld)", ipaddr_string(&dp
->u_da
),
157 (unsigned long)EXTRACT_32BITS(&dp
->u_ds
));
159 if ((i
% sizeof(*dp
)) != 0)
169 aodv_v6_rreq(const u_char
*dat
, u_int length
)
171 aodv_v6_rreq(const u_char
*dat _U_
, u_int length
)
176 const struct aodv_rreq6
*ap
= (const struct aodv_rreq6
*)dat
;
179 if (length
< sizeof(*ap
))
181 printf(" v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
182 "\tdst %s seq %lu src %s seq %lu", length
,
183 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
184 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
185 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
186 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
187 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
189 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
190 ip6addr_string(&ap
->rreq_da
),
191 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
192 ip6addr_string(&ap
->rreq_oa
),
193 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
));
194 i
= length
- sizeof(*ap
);
195 if (i
>= sizeof(struct aodv_ext
))
196 aodv_extension((const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
202 printf(" v6 rreq %u", length
);
208 aodv_v6_rrep(const u_char
*dat
, u_int length
)
210 aodv_v6_rrep(const u_char
*dat _U_
, u_int length
)
215 const struct aodv_rrep6
*ap
= (const struct aodv_rrep6
*)dat
;
218 if (length
< sizeof(*ap
))
220 printf(" rrep %u %s%sprefix %u hops %u\n"
221 "\tdst %s dseq %lu src %s %lu ms", length
,
222 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
223 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
224 ap
->rrep_ps
& RREP_PREFIX_MASK
,
226 ip6addr_string(&ap
->rrep_da
),
227 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
228 ip6addr_string(&ap
->rrep_oa
),
229 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
));
230 i
= length
- sizeof(*ap
);
231 if (i
>= sizeof(struct aodv_ext
))
232 aodv_extension((const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
238 printf(" rrep %u", length
);
244 aodv_v6_rerr(const u_char
*dat
, u_int length
)
246 aodv_v6_rerr(const u_char
*dat _U_
, u_int length
)
251 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
252 const struct rerr_unreach6
*dp6
;
255 if (length
< sizeof(*ap
))
257 printf(" rerr %s [items %u] [%u]:",
258 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
259 ap
->rerr_dc
, length
);
260 dp6
= (struct rerr_unreach6
*)(void *)(ap
+ 1);
261 i
= length
- sizeof(*ap
);
262 for (dc
= ap
->rerr_dc
; dc
!= 0 && i
>= sizeof(*dp6
);
263 ++dp6
, --dc
, i
-= sizeof(*dp6
)) {
265 printf(" {%s}(%ld)", ip6addr_string(&dp6
->u_da
),
266 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
));
268 if ((i
% sizeof(*dp6
)) != 0)
275 printf(" rerr %u", length
);
281 aodv_v6_draft_01_rreq(const u_char
*dat
, u_int length
)
283 aodv_v6_draft_01_rreq(const u_char
*dat _U_
, u_int length
)
288 const struct aodv_rreq6_draft_01
*ap
= (const struct aodv_rreq6_draft_01
*)dat
;
291 if (length
< sizeof(*ap
))
293 printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
294 "\tdst %s seq %lu src %s seq %lu", length
,
295 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
296 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
297 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
298 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
299 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
301 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
302 ip6addr_string(&ap
->rreq_da
),
303 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
304 ip6addr_string(&ap
->rreq_oa
),
305 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
));
306 i
= length
- sizeof(*ap
);
307 if (i
>= sizeof(struct aodv_ext
))
308 aodv_extension((const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
314 printf(" rreq %u", length
);
320 aodv_v6_draft_01_rrep(const u_char
*dat
, u_int length
)
322 aodv_v6_draft_01_rrep(const u_char
*dat _U_
, u_int length
)
327 const struct aodv_rrep6_draft_01
*ap
= (const struct aodv_rrep6_draft_01
*)dat
;
330 if (length
< sizeof(*ap
))
332 printf(" rrep %u %s%sprefix %u hops %u\n"
333 "\tdst %s dseq %lu src %s %lu ms", length
,
334 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
335 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
336 ap
->rrep_ps
& RREP_PREFIX_MASK
,
338 ip6addr_string(&ap
->rrep_da
),
339 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
340 ip6addr_string(&ap
->rrep_oa
),
341 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
));
342 i
= length
- sizeof(*ap
);
343 if (i
>= sizeof(struct aodv_ext
))
344 aodv_extension((const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
350 printf(" rrep %u", length
);
356 aodv_v6_draft_01_rerr(const u_char
*dat
, u_int length
)
358 aodv_v6_draft_01_rerr(const u_char
*dat _U_
, u_int length
)
363 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
364 const struct rerr_unreach6_draft_01
*dp6
;
367 if (length
< sizeof(*ap
))
369 printf(" rerr %s [items %u] [%u]:",
370 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
371 ap
->rerr_dc
, length
);
372 dp6
= (struct rerr_unreach6_draft_01
*)(void *)(ap
+ 1);
373 i
= length
- sizeof(*ap
);
374 for (dc
= ap
->rerr_dc
; dc
!= 0 && i
>= sizeof(*dp6
);
375 ++dp6
, --dc
, i
-= sizeof(*dp6
)) {
377 printf(" {%s}(%ld)", ip6addr_string(&dp6
->u_da
),
378 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
));
380 if ((i
% sizeof(*dp6
)) != 0)
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(dat
, length
);
410 aodv_rreq(dat
, length
);
415 aodv_v6_rrep(dat
, length
);
417 aodv_rrep(dat
, length
);
422 aodv_v6_rerr(dat
, length
);
424 aodv_rerr(dat
, length
);
428 printf(" rrep-ack %u", length
);
431 case AODV_V6_DRAFT_01_RREQ
:
432 aodv_v6_draft_01_rreq(dat
, length
);
435 case AODV_V6_DRAFT_01_RREP
:
436 aodv_v6_draft_01_rrep(dat
, length
);
439 case AODV_V6_DRAFT_01_RERR
:
440 aodv_v6_draft_01_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
);