]>
The Tcpdump Group git mirrors - tcpdump/blob - print-aodv.c
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
[] =
35 "@(#) $Header: /tcpdump/master/tcpdump/print-aodv.c,v 1.4 2003-09-06 22:16:56 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(struct aodv_ext
*ep
, u_int length
)
59 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 %d ms",
75 EXTRACT_32BITS(ah
->interval
));
79 printf("\n\text %d %d", ep
->type
, ep
->length
);
85 aodv_rreq(union aodv
*ap
, const u_char
*dat
, u_int length
, void *ip6
97 i
= min(length
, (u_int
)(snapend
- dat
));
98 if (i
< sizeof(ap
->rreq
)) {
102 i
-= sizeof(ap
->rreq
);
105 printf(" rreq %d %s%s%s%s%shops %d id 0x%08lx\n"
106 "\tdst %s seq %ld src %s seq %ld", length
,
107 ap
->rreq6
.rreq_type
& RREQ_JOIN
? "[J]" : "",
108 ap
->rreq6
.rreq_type
& RREQ_REPAIR
? "[R]" : "",
109 ap
->rreq6
.rreq_type
& RREQ_GRAT
? "[G]" : "",
110 ap
->rreq6
.rreq_type
& RREQ_DEST
? "[D]" : "",
111 ap
->rreq6
.rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
113 (unsigned long)EXTRACT_32BITS(ap
->rreq6
.rreq_id
),
114 ip6addr_string(&ap
->rreq6
.rreq_da
),
115 (unsigned long)EXTRACT_32BITS(ap
->rreq6
.rreq_ds
),
116 ip6addr_string(&ap
->rreq6
.rreq_oa
),
117 (unsigned long)EXTRACT_32BITS(ap
->rreq6
.rreq_os
));
118 if (i
>= sizeof(ap
->rreq6
) + sizeof(struct aodv_ext
)) {
119 aodv_extension((void *) (&ap
->rreq6
+ 1),
120 length
- sizeof(ap
->rreq6
));
125 printf(" rreq %d %s%s%s%s%shops %d id 0x%08x\n"
126 "\tdst %s seq %d src %s seq %d", length
,
127 ap
->rreq
.rreq_type
& RREQ_JOIN
? "[J]" : "",
128 ap
->rreq
.rreq_type
& RREQ_REPAIR
? "[R]" : "",
129 ap
->rreq
.rreq_type
& RREQ_GRAT
? "[G]" : "",
130 ap
->rreq
.rreq_type
& RREQ_DEST
? "[D]" : "",
131 ap
->rreq
.rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
133 EXTRACT_32BITS(ap
->rreq
.rreq_id
),
134 ipaddr_string(ap
->rreq
.rreq_da
),
135 EXTRACT_32BITS(ap
->rreq
.rreq_ds
),
136 ipaddr_string(ap
->rreq
.rreq_oa
),
137 EXTRACT_32BITS(ap
->rreq
.rreq_os
));
138 if (i
>= sizeof(ap
->rreq
) + sizeof(struct aodv_ext
)) {
139 aodv_extension((void *) (&ap
->rreq
+ 1),
140 length
- sizeof(ap
->rreq
));
146 aodv_rrep(union aodv
*ap
, const u_char
*dat
, u_int length
, void *ip6
158 i
= min(length
, (u_int
)(snapend
- dat
));
159 if (i
< sizeof(ap
->rrep
)) {
163 i
-= sizeof(ap
->rrep
);
166 printf(" rrep %d %s%sprefix %d hops %d\n"
167 "\tdst %s dseq %d src %s %d ms", length
,
168 ap
->rrep6
.rrep_type
& RREP_REPAIR
? "[R]" : "",
169 ap
->rrep6
.rrep_type
& RREP_ACK
? "[A] " : " ",
170 ap
->rrep6
.rrep_ps
& RREP_PREFIX_MASK
,
172 ip6addr_string(&ap
->rrep6
.rrep_da
),
173 EXTRACT_32BITS(ap
->rrep6
.rrep_ds
),
174 ip6addr_string(&ap
->rrep6
.rrep_oa
),
175 EXTRACT_32BITS(ap
->rrep6
.rrep_life
));
176 if (i
>= sizeof(ap
->rrep6
) + sizeof(struct aodv_ext
)) {
177 aodv_extension((void *) (&ap
->rrep6
+ 1),
178 length
- sizeof(ap
->rrep6
));
183 printf(" rrep %d %s%sprefix %d hops %d\n"
184 "\tdst %s dseq %d src %s %d ms", length
,
185 ap
->rrep
.rrep_type
& RREP_REPAIR
? "[R]" : "",
186 ap
->rrep
.rrep_type
& RREP_ACK
? "[A] " : " ",
187 ap
->rrep
.rrep_ps
& RREP_PREFIX_MASK
,
189 ipaddr_string(ap
->rrep
.rrep_da
),
190 EXTRACT_32BITS(ap
->rrep
.rrep_ds
),
191 ipaddr_string(ap
->rrep
.rrep_oa
),
192 EXTRACT_32BITS(ap
->rrep
.rrep_life
));
193 if (i
>= sizeof(ap
->rrep
) + sizeof(struct aodv_ext
)) {
194 aodv_extension((void *) (&ap
->rrep
+ 1),
195 length
- sizeof(ap
->rrep
));
201 aodv_rerr(union aodv
*ap
, u_int length
, void *ip6
208 struct rerr_unreach
*dp
= NULL
;
210 struct rerr_unreach6
*dp6
= NULL
;
213 i
= length
- offsetof(struct aodv_rerr
, r
);
216 j
= sizeof(ap
->rerr
.r
.dest6
[0]);
217 dp6
= &ap
->rerr
.r
.dest6
[0];
221 j
= sizeof(ap
->rerr
.r
.dest
[0]);
222 dp
= &ap
->rerr
.r
.dest
[0];
224 n
= ap
->rerr
.rerr_dc
* j
;
225 printf(" rerr %s [items %d] [%d]:",
226 ap
->rerr
.rerr_flags
& RERR_NODELETE
? "[D]" : "",
227 ap
->rerr
.rerr_dc
, length
);
231 for (; i
-= j
>= 0; ++dp6
) {
232 printf(" {%s}(%d)", ip6addr_string(&dp6
->u_da
),
233 EXTRACT_32BITS(dp6
->u_ds
));
238 for (; i
-= j
>= 0; ++dp
) {
239 printf(" {%s}(%d)", ipaddr_string(dp
->u_da
),
240 EXTRACT_32BITS(dp
->u_ds
));
248 aodv_print(const u_char
*dat
, u_int length
, void *ip6
)
252 ap
= (union aodv
*)dat
;
257 if (min(length
, (u_int
)(snapend
- dat
)) < sizeof(ap
->rrep_ack
)) {
263 switch (ap
->rerr
.rerr_type
) {
265 aodv_rreq(ap
, dat
, length
, ip6
);
268 aodv_rrep(ap
, dat
, length
, ip6
);
271 aodv_rerr(ap
, length
, ip6
);
274 printf(" rrep-ack %d", ap
->rrep_ack
.ra_type
);
278 printf(" %d %d", ap
->rreq
.rreq_type
, length
);