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
)
58 const struct aodv_hello
*ah
;
62 ah
= (const struct aodv_hello
*)(const void *)ep
;
64 if (length
< sizeof(struct aodv_hello
))
66 printf("\n\text HELLO %ld ms",
67 (unsigned long)EXTRACT_32BITS(&ah
->interval
));
71 printf("\n\text %u %u", ep
->type
, ep
->length
);
81 aodv_rreq(const u_char
*dat
, u_int length
)
84 const struct aodv_rreq
*ap
= (const struct aodv_rreq
*)dat
;
87 if (length
< sizeof(*ap
))
89 printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
90 "\tdst %s seq %lu src %s seq %lu", length
,
91 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
92 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
93 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
94 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
95 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
97 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
98 ipaddr_string(&ap
->rreq_da
),
99 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
100 ipaddr_string(&ap
->rreq_oa
),
101 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
));
102 i
= length
- sizeof(*ap
);
103 if (i
>= sizeof(struct aodv_ext
))
104 aodv_extension((const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
112 aodv_rrep(const u_char
*dat
, u_int length
)
115 const struct aodv_rrep
*ap
= (const struct aodv_rrep
*)dat
;
118 if (length
< sizeof(*ap
))
120 printf(" rrep %u %s%sprefix %u hops %u\n"
121 "\tdst %s dseq %lu src %s %lu ms", length
,
122 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
123 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
124 ap
->rrep_ps
& RREP_PREFIX_MASK
,
126 ipaddr_string(&ap
->rrep_da
),
127 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
128 ipaddr_string(&ap
->rrep_oa
),
129 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
));
130 i
= length
- sizeof(*ap
);
131 if (i
>= sizeof(struct aodv_ext
))
132 aodv_extension((const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
140 aodv_rerr(const u_char
*dat
, u_int length
)
143 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
144 const struct rerr_unreach
*dp
;
147 if (length
< sizeof(*ap
))
149 printf(" rerr %s [items %u] [%u]:",
150 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
151 ap
->rerr_dc
, length
);
152 dp
= (struct rerr_unreach
*)(dat
+ sizeof(*ap
));
153 i
= length
- sizeof(*ap
);
154 for (dc
= ap
->rerr_dc
; dc
!= 0 && i
>= sizeof(*dp
);
155 ++dp
, --dc
, i
-= sizeof(*dp
)) {
157 printf(" {%s}(%ld)", ipaddr_string(&dp
->u_da
),
158 (unsigned long)EXTRACT_32BITS(&dp
->u_ds
));
160 if ((i
% sizeof(*dp
)) != 0)
170 aodv_v6_rreq(const u_char
*dat
, u_int length
)
172 aodv_v6_rreq(const u_char
*dat _U_
, u_int length
)
177 const struct aodv_rreq6
*ap
= (const struct aodv_rreq6
*)dat
;
180 if (length
< sizeof(*ap
))
182 printf(" v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
183 "\tdst %s seq %lu src %s seq %lu", length
,
184 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
185 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
186 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
187 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
188 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
190 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
191 ip6addr_string(&ap
->rreq_da
),
192 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
193 ip6addr_string(&ap
->rreq_oa
),
194 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
));
195 i
= length
- sizeof(*ap
);
196 if (i
>= sizeof(struct aodv_ext
))
197 aodv_extension((const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
203 printf(" v6 rreq %u", length
);
209 aodv_v6_rrep(const u_char
*dat
, u_int length
)
211 aodv_v6_rrep(const u_char
*dat _U_
, u_int length
)
216 const struct aodv_rrep6
*ap
= (const struct aodv_rrep6
*)dat
;
219 if (length
< sizeof(*ap
))
221 printf(" rrep %u %s%sprefix %u hops %u\n"
222 "\tdst %s dseq %lu src %s %lu ms", length
,
223 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
224 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
225 ap
->rrep_ps
& RREP_PREFIX_MASK
,
227 ip6addr_string(&ap
->rrep_da
),
228 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
229 ip6addr_string(&ap
->rrep_oa
),
230 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
));
231 i
= length
- sizeof(*ap
);
232 if (i
>= sizeof(struct aodv_ext
))
233 aodv_extension((const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
239 printf(" rrep %u", length
);
245 aodv_v6_rerr(const u_char
*dat
, u_int length
)
247 aodv_v6_rerr(const u_char
*dat _U_
, u_int length
)
252 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
253 const struct rerr_unreach6
*dp6
;
256 if (length
< sizeof(*ap
))
258 printf(" rerr %s [items %u] [%u]:",
259 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
260 ap
->rerr_dc
, length
);
261 dp6
= (struct rerr_unreach6
*)(void *)(ap
+ 1);
262 i
= length
- sizeof(*ap
);
263 for (dc
= ap
->rerr_dc
; dc
!= 0 && i
>= sizeof(*dp6
);
264 ++dp6
, --dc
, i
-= sizeof(*dp6
)) {
266 printf(" {%s}(%ld)", ip6addr_string(&dp6
->u_da
),
267 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
));
269 if ((i
% sizeof(*dp6
)) != 0)
276 printf(" rerr %u", length
);
282 aodv_v6_draft_01_rreq(const u_char
*dat
, u_int length
)
284 aodv_v6_draft_01_rreq(const u_char
*dat _U_
, u_int length
)
289 const struct aodv_rreq6_draft_01
*ap
= (const struct aodv_rreq6_draft_01
*)dat
;
292 if (length
< sizeof(*ap
))
294 printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
295 "\tdst %s seq %lu src %s seq %lu", length
,
296 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
297 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
298 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
299 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
300 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
302 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
303 ip6addr_string(&ap
->rreq_da
),
304 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
305 ip6addr_string(&ap
->rreq_oa
),
306 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
));
307 i
= length
- sizeof(*ap
);
308 if (i
>= sizeof(struct aodv_ext
))
309 aodv_extension((const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
315 printf(" rreq %u", length
);
321 aodv_v6_draft_01_rrep(const u_char
*dat
, u_int length
)
323 aodv_v6_draft_01_rrep(const u_char
*dat _U_
, u_int length
)
328 const struct aodv_rrep6_draft_01
*ap
= (const struct aodv_rrep6_draft_01
*)dat
;
331 if (length
< sizeof(*ap
))
333 printf(" rrep %u %s%sprefix %u hops %u\n"
334 "\tdst %s dseq %lu src %s %lu ms", length
,
335 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
336 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
337 ap
->rrep_ps
& RREP_PREFIX_MASK
,
339 ip6addr_string(&ap
->rrep_da
),
340 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
341 ip6addr_string(&ap
->rrep_oa
),
342 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
));
343 i
= length
- sizeof(*ap
);
344 if (i
>= sizeof(struct aodv_ext
))
345 aodv_extension((const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
351 printf(" rrep %u", length
);
357 aodv_v6_draft_01_rerr(const u_char
*dat
, u_int length
)
359 aodv_v6_draft_01_rerr(const u_char
*dat _U_
, u_int length
)
364 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
365 const struct rerr_unreach6_draft_01
*dp6
;
368 if (length
< sizeof(*ap
))
370 printf(" rerr %s [items %u] [%u]:",
371 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
372 ap
->rerr_dc
, length
);
373 dp6
= (struct rerr_unreach6_draft_01
*)(void *)(ap
+ 1);
374 i
= length
- sizeof(*ap
);
375 for (dc
= ap
->rerr_dc
; dc
!= 0 && i
>= sizeof(*dp6
);
376 ++dp6
, --dc
, i
-= sizeof(*dp6
)) {
378 printf(" {%s}(%ld)", ip6addr_string(&dp6
->u_da
),
379 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
));
381 if ((i
% sizeof(*dp6
)) != 0)
388 printf(" rerr %u", length
);
393 aodv_print(const u_char
*dat
, u_int length
, int is_ip6
)
398 * The message type is the first byte; make sure we have it
409 aodv_v6_rreq(dat
, length
);
411 aodv_rreq(dat
, length
);
416 aodv_v6_rrep(dat
, length
);
418 aodv_rrep(dat
, length
);
423 aodv_v6_rerr(dat
, length
);
425 aodv_rerr(dat
, length
);
429 printf(" rrep-ack %u", length
);
432 case AODV_V6_DRAFT_01_RREQ
:
433 aodv_v6_draft_01_rreq(dat
, length
);
436 case AODV_V6_DRAFT_01_RREP
:
437 aodv_v6_draft_01_rrep(dat
, length
);
440 case AODV_V6_DRAFT_01_RERR
:
441 aodv_v6_draft_01_rerr(dat
, length
);
444 case AODV_V6_DRAFT_01_RREP_ACK
:
445 printf(" rrep-ack %u", length
);
449 printf(" type %u %u", msg_type
, length
);