4 * Copyright (c) 2003 Bruce M. Simpson <bms@spc.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Bruce M. Simpson.
18 * 4. Neither the name of Bruce M. Simpson nor the names of co-
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY Bruce M. Simpson AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Bruce M. Simpson OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
38 static const char rcsid
[] _U_
=
39 "@(#) Header: /tcpdump/master/tcpdump/print-aodv.c,v 1.11 2004/03/24 00:30:19 guy Exp (LBL)";
41 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
49 #include <tcpdump-stdinc.h>
56 #include "interface.h"
57 #include "addrtoname.h"
58 #include "extract.h" /* must come after interface.h */
63 aodv_extension(const struct aodv_ext
*ep
, u_int length
)
66 const struct aodv_hello
*ah
;
70 if (snapend
< (u_char
*) ep
) {
74 i
= min(length
, (u_int
)(snapend
- (u_char
*)ep
));
75 if (i
< sizeof(struct aodv_hello
)) {
79 i
-= sizeof(struct aodv_hello
);
81 printf("\n\text HELLO %ld ms",
82 (unsigned long)EXTRACT_32BITS(&ah
->interval
));
86 printf("\n\text %u %u", ep
->type
, ep
->length
);
92 aodv_rreq(const union aodv
*ap
, const u_char
*dat
, u_int length
)
100 i
= min(length
, (u_int
)(snapend
- dat
));
101 if (i
< sizeof(ap
->rreq
)) {
105 i
-= sizeof(ap
->rreq
);
106 printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
107 "\tdst %s seq %lu src %s seq %lu", length
,
108 ap
->rreq
.rreq_type
& RREQ_JOIN
? "[J]" : "",
109 ap
->rreq
.rreq_type
& RREQ_REPAIR
? "[R]" : "",
110 ap
->rreq
.rreq_type
& RREQ_GRAT
? "[G]" : "",
111 ap
->rreq
.rreq_type
& RREQ_DEST
? "[D]" : "",
112 ap
->rreq
.rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
114 (unsigned long)EXTRACT_32BITS(&ap
->rreq
.rreq_id
),
115 ipaddr_string(&ap
->rreq
.rreq_da
),
116 (unsigned long)EXTRACT_32BITS(&ap
->rreq
.rreq_ds
),
117 ipaddr_string(&ap
->rreq
.rreq_oa
),
118 (unsigned long)EXTRACT_32BITS(&ap
->rreq
.rreq_os
));
119 if (i
>= sizeof(struct aodv_ext
))
120 aodv_extension((void *)(&ap
->rreq
+ 1), i
);
124 aodv_rrep(const union aodv
*ap
, const u_char
*dat
, u_int length
)
132 i
= min(length
, (u_int
)(snapend
- dat
));
133 if (i
< sizeof(ap
->rrep
)) {
137 i
-= sizeof(ap
->rrep
);
138 printf(" rrep %u %s%sprefix %u hops %u\n"
139 "\tdst %s dseq %lu src %s %lu ms", length
,
140 ap
->rrep
.rrep_type
& RREP_REPAIR
? "[R]" : "",
141 ap
->rrep
.rrep_type
& RREP_ACK
? "[A] " : " ",
142 ap
->rrep
.rrep_ps
& RREP_PREFIX_MASK
,
144 ipaddr_string(&ap
->rrep
.rrep_da
),
145 (unsigned long)EXTRACT_32BITS(&ap
->rrep
.rrep_ds
),
146 ipaddr_string(&ap
->rrep
.rrep_oa
),
147 (unsigned long)EXTRACT_32BITS(&ap
->rrep
.rrep_life
));
148 if (i
>= sizeof(struct aodv_ext
))
149 aodv_extension((void *)(&ap
->rrep
+ 1), i
);
153 aodv_rerr(const union aodv
*ap
, const u_char
*dat
, u_int length
)
156 const struct rerr_unreach
*dp
= NULL
;
163 i
= min(length
, (u_int
)(snapend
- dat
));
164 if (i
< offsetof(struct aodv_rerr
, r
)) {
168 i
-= offsetof(struct aodv_rerr
, r
);
169 dp
= &ap
->rerr
.r
.dest
[0];
170 n
= ap
->rerr
.rerr_dc
* sizeof(ap
->rerr
.r
.dest
[0]);
171 printf(" rerr %s [items %u] [%u]:",
172 ap
->rerr
.rerr_flags
& RERR_NODELETE
? "[D]" : "",
173 ap
->rerr
.rerr_dc
, length
);
174 trunc
= n
- (i
/sizeof(ap
->rerr
.r
.dest
[0]));
175 for (; i
>= sizeof(ap
->rerr
.r
.dest
[0]);
176 ++dp
, i
-= sizeof(ap
->rerr
.r
.dest
[0])) {
177 printf(" {%s}(%ld)", ipaddr_string(&dp
->u_da
),
178 (unsigned long)EXTRACT_32BITS(&dp
->u_ds
));
186 aodv_v6_rreq(const union aodv
*ap
, const u_char
*dat
, u_int length
)
188 aodv_v6_rreq(const union aodv
*ap _U_
, const u_char
*dat _U_
, u_int length
)
198 i
= min(length
, (u_int
)(snapend
- dat
));
199 if (i
< sizeof(ap
->rreq6
)) {
203 i
-= sizeof(ap
->rreq6
);
204 printf(" v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
205 "\tdst %s seq %lu src %s seq %lu", length
,
206 ap
->rreq6
.rreq_type
& RREQ_JOIN
? "[J]" : "",
207 ap
->rreq6
.rreq_type
& RREQ_REPAIR
? "[R]" : "",
208 ap
->rreq6
.rreq_type
& RREQ_GRAT
? "[G]" : "",
209 ap
->rreq6
.rreq_type
& RREQ_DEST
? "[D]" : "",
210 ap
->rreq6
.rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
212 (unsigned long)EXTRACT_32BITS(&ap
->rreq6
.rreq_id
),
213 ip6addr_string(&ap
->rreq6
.rreq_da
),
214 (unsigned long)EXTRACT_32BITS(&ap
->rreq6
.rreq_ds
),
215 ip6addr_string(&ap
->rreq6
.rreq_oa
),
216 (unsigned long)EXTRACT_32BITS(&ap
->rreq6
.rreq_os
));
217 if (i
>= sizeof(struct aodv_ext
))
218 aodv_extension((void *)(&ap
->rreq6
+ 1), i
);
220 printf(" v6 rreq %u", length
);
226 aodv_v6_rrep(const union aodv
*ap
, const u_char
*dat
, u_int length
)
228 aodv_v6_rrep(const union aodv
*ap _U_
, const u_char
*dat _U_
, u_int length
)
238 i
= min(length
, (u_int
)(snapend
- dat
));
239 if (i
< sizeof(ap
->rrep6
)) {
243 i
-= sizeof(ap
->rrep6
);
244 printf(" rrep %u %s%sprefix %u hops %u\n"
245 "\tdst %s dseq %lu src %s %lu ms", length
,
246 ap
->rrep6
.rrep_type
& RREP_REPAIR
? "[R]" : "",
247 ap
->rrep6
.rrep_type
& RREP_ACK
? "[A] " : " ",
248 ap
->rrep6
.rrep_ps
& RREP_PREFIX_MASK
,
250 ip6addr_string(&ap
->rrep6
.rrep_da
),
251 (unsigned long)EXTRACT_32BITS(&ap
->rrep6
.rrep_ds
),
252 ip6addr_string(&ap
->rrep6
.rrep_oa
),
253 (unsigned long)EXTRACT_32BITS(&ap
->rrep6
.rrep_life
));
254 if (i
>= sizeof(struct aodv_ext
))
255 aodv_extension((void *)(&ap
->rrep6
+ 1), i
);
257 printf(" rrep %u", length
);
263 aodv_v6_rerr(const union aodv
*ap
, u_int length
)
265 aodv_v6_rerr(const union aodv
*ap _U_
, u_int length
)
269 const struct rerr_unreach6
*dp6
= NULL
;
272 i
= length
- offsetof(struct aodv_rerr
, r
);
273 j
= sizeof(ap
->rerr
.r
.dest6
[0]);
274 dp6
= &ap
->rerr
.r
.dest6
[0];
275 n
= ap
->rerr
.rerr_dc
* j
;
276 printf(" rerr %s [items %u] [%u]:",
277 ap
->rerr
.rerr_flags
& RERR_NODELETE
? "[D]" : "",
278 ap
->rerr
.rerr_dc
, length
);
280 for (; i
-= j
>= 0; ++dp6
) {
281 printf(" {%s}(%ld)", ip6addr_string(&dp6
->u_da
),
282 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
));
287 printf(" rerr %u", length
);
293 aodv_v6_draft_01_rreq(const union aodv
*ap
, const u_char
*dat
, u_int length
)
295 aodv_v6_draft_01_rreq(const union aodv
*ap _U_
, const u_char
*dat _U_
,
306 i
= min(length
, (u_int
)(snapend
- dat
));
307 if (i
< sizeof(ap
->rreq6_draft_01
)) {
311 i
-= sizeof(ap
->rreq6_draft_01
);
312 printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
313 "\tdst %s seq %lu src %s seq %lu", length
,
314 ap
->rreq6_draft_01
.rreq_type
& RREQ_JOIN
? "[J]" : "",
315 ap
->rreq6_draft_01
.rreq_type
& RREQ_REPAIR
? "[R]" : "",
316 ap
->rreq6_draft_01
.rreq_type
& RREQ_GRAT
? "[G]" : "",
317 ap
->rreq6_draft_01
.rreq_type
& RREQ_DEST
? "[D]" : "",
318 ap
->rreq6_draft_01
.rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
319 ap
->rreq6_draft_01
.rreq_hops
,
320 (unsigned long)EXTRACT_32BITS(&ap
->rreq6_draft_01
.rreq_id
),
321 ip6addr_string(&ap
->rreq6_draft_01
.rreq_da
),
322 (unsigned long)EXTRACT_32BITS(&ap
->rreq6_draft_01
.rreq_ds
),
323 ip6addr_string(&ap
->rreq6_draft_01
.rreq_oa
),
324 (unsigned long)EXTRACT_32BITS(&ap
->rreq6_draft_01
.rreq_os
));
325 if (i
>= sizeof(struct aodv_ext
))
326 aodv_extension((void *)(&ap
->rreq6_draft_01
+ 1), i
);
328 printf(" rreq %u", length
);
334 aodv_v6_draft_01_rrep(const union aodv
*ap
, const u_char
*dat
, u_int length
)
336 aodv_v6_draft_01_rrep(const union aodv
*ap _U_
, const u_char
*dat _U_
,
347 i
= min(length
, (u_int
)(snapend
- dat
));
348 if (i
< sizeof(ap
->rrep6_draft_01
)) {
352 i
-= sizeof(ap
->rrep6_draft_01
);
353 printf(" rrep %u %s%sprefix %u hops %u\n"
354 "\tdst %s dseq %lu src %s %lu ms", length
,
355 ap
->rrep6_draft_01
.rrep_type
& RREP_REPAIR
? "[R]" : "",
356 ap
->rrep6_draft_01
.rrep_type
& RREP_ACK
? "[A] " : " ",
357 ap
->rrep6_draft_01
.rrep_ps
& RREP_PREFIX_MASK
,
358 ap
->rrep6_draft_01
.rrep_hops
,
359 ip6addr_string(&ap
->rrep6_draft_01
.rrep_da
),
360 (unsigned long)EXTRACT_32BITS(&ap
->rrep6_draft_01
.rrep_ds
),
361 ip6addr_string(&ap
->rrep6_draft_01
.rrep_oa
),
362 (unsigned long)EXTRACT_32BITS(&ap
->rrep6_draft_01
.rrep_life
));
363 if (i
>= sizeof(struct aodv_ext
))
364 aodv_extension((void *)(&ap
->rrep6_draft_01
+ 1), i
);
366 printf(" rrep %u", length
);
372 aodv_v6_draft_01_rerr(const union aodv
*ap
, u_int length
)
374 aodv_v6_draft_01_rerr(const union aodv
*ap _U_
, u_int length
)
378 const struct rerr_unreach6_draft_01
*dp6
= NULL
;
381 i
= length
- offsetof(struct aodv_rerr
, r
);
382 j
= sizeof(ap
->rerr
.r
.dest6_draft_01
[0]);
383 dp6
= &ap
->rerr
.r
.dest6_draft_01
[0];
384 n
= ap
->rerr
.rerr_dc
* j
;
385 printf(" rerr %s [items %u] [%u]:",
386 ap
->rerr
.rerr_flags
& RERR_NODELETE
? "[D]" : "",
387 ap
->rerr
.rerr_dc
, length
);
389 for (; i
-= j
>= 0; ++dp6
) {
390 printf(" {%s}(%ld)", ip6addr_string(&dp6
->u_da
),
391 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
));
396 printf(" rerr %u", length
);
401 aodv_print(const u_char
*dat
, u_int length
, int is_ip6
)
403 const union aodv
*ap
;
405 ap
= (union aodv
*)dat
;
410 if (min(length
, (u_int
)(snapend
- dat
)) < sizeof(ap
->rrep_ack
)) {
416 switch (ap
->rerr
.rerr_type
) {
420 aodv_v6_rreq(ap
, dat
, length
);
422 aodv_rreq(ap
, dat
, length
);
427 aodv_v6_rrep(ap
, dat
, length
);
429 aodv_rrep(ap
, dat
, length
);
434 aodv_v6_rerr(ap
, length
);
436 aodv_rerr(ap
, dat
, length
);
440 printf(" rrep-ack %u", length
);
443 case AODV_V6_DRAFT_01_RREQ
:
444 aodv_v6_draft_01_rreq(ap
, dat
, length
);
447 case AODV_V6_DRAFT_01_RREP
:
448 aodv_v6_draft_01_rrep(ap
, dat
, length
);
451 case AODV_V6_DRAFT_01_RERR
:
452 aodv_v6_draft_01_rerr(ap
, length
);
455 case AODV_V6_DRAFT_01_RREP_ACK
:
456 printf(" rrep-ack %u", length
);
460 printf(" %u %u", ap
->rreq
.rreq_type
, length
);