]>
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.5 2003-09-12 22:05:57 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 %d ms", EXTRACT_32BITS(&ah
->interval
));
78 printf("\n\text %d %d", ep
->type
, ep
->length
);
84 aodv_rreq(const union aodv
*ap
, const u_char
*dat
, u_int length
)
92 i
= min(length
, (u_int
)(snapend
- dat
));
93 if (i
< sizeof(ap
->rreq
)) {
97 i
-= sizeof(ap
->rreq
);
98 printf(" rreq %d %s%s%s%s%shops %d id 0x%08x\n"
99 "\tdst %s seq %d src %s seq %d", length
,
100 ap
->rreq
.rreq_type
& RREQ_JOIN
? "[J]" : "",
101 ap
->rreq
.rreq_type
& RREQ_REPAIR
? "[R]" : "",
102 ap
->rreq
.rreq_type
& RREQ_GRAT
? "[G]" : "",
103 ap
->rreq
.rreq_type
& RREQ_DEST
? "[D]" : "",
104 ap
->rreq
.rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
106 EXTRACT_32BITS(&ap
->rreq
.rreq_id
),
107 ipaddr_string(&ap
->rreq
.rreq_da
),
108 EXTRACT_32BITS(&ap
->rreq
.rreq_ds
),
109 ipaddr_string(&ap
->rreq
.rreq_oa
),
110 EXTRACT_32BITS(&ap
->rreq
.rreq_os
));
111 if (i
>= sizeof(struct aodv_ext
))
112 aodv_extension((void *)(&ap
->rreq
+ 1), i
);
116 aodv_rrep(const union aodv
*ap
, const u_char
*dat
, u_int length
)
124 i
= min(length
, (u_int
)(snapend
- dat
));
125 if (i
< sizeof(ap
->rrep
)) {
129 i
-= sizeof(ap
->rrep
);
130 printf(" rrep %d %s%sprefix %d hops %d\n"
131 "\tdst %s dseq %d src %s %d ms", length
,
132 ap
->rrep
.rrep_type
& RREP_REPAIR
? "[R]" : "",
133 ap
->rrep
.rrep_type
& RREP_ACK
? "[A] " : " ",
134 ap
->rrep
.rrep_ps
& RREP_PREFIX_MASK
,
136 ipaddr_string(&ap
->rrep
.rrep_da
),
137 EXTRACT_32BITS(&ap
->rrep
.rrep_ds
),
138 ipaddr_string(&ap
->rrep
.rrep_oa
),
139 EXTRACT_32BITS(&ap
->rrep
.rrep_life
));
140 if (i
>= sizeof(struct aodv_ext
))
141 aodv_extension((void *)(&ap
->rrep
+ 1), i
);
145 aodv_rerr(const union aodv
*ap
, u_int length
)
147 const struct rerr_unreach
*dp
= NULL
;
150 i
= length
- offsetof(struct aodv_rerr
, r
);
151 j
= sizeof(ap
->rerr
.r
.dest
[0]);
152 dp
= &ap
->rerr
.r
.dest
[0];
153 n
= ap
->rerr
.rerr_dc
* j
;
154 printf(" rerr %s [items %d] [%d]:",
155 ap
->rerr
.rerr_flags
& RERR_NODELETE
? "[D]" : "",
156 ap
->rerr
.rerr_dc
, length
);
158 for (; i
-= j
>= 0; ++dp
) {
159 printf(" {%s}(%d)", ipaddr_string(&dp
->u_da
),
160 EXTRACT_32BITS(&dp
->u_ds
));
168 aodv_v6_rreq(const union aodv
*ap
, const u_char
*dat
, u_int length
)
170 aodv_v6_rreq(const union aodv
*ap _U_
, const u_char
*dat _U_
, u_int length
)
180 i
= min(length
, (u_int
)(snapend
- dat
));
181 if (i
< sizeof(ap
->rreq6
)) {
185 i
-= sizeof(ap
->rreq6
);
186 printf(" v6 rreq %d %s%s%s%s%shops %d id 0x%08x\n"
187 "\tdst %s seq %d src %s seq %d", length
,
188 ap
->rreq6
.rreq_type
& RREQ_JOIN
? "[J]" : "",
189 ap
->rreq6
.rreq_type
& RREQ_REPAIR
? "[R]" : "",
190 ap
->rreq6
.rreq_type
& RREQ_GRAT
? "[G]" : "",
191 ap
->rreq6
.rreq_type
& RREQ_DEST
? "[D]" : "",
192 ap
->rreq6
.rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
194 EXTRACT_32BITS(&ap
->rreq6
.rreq_id
),
195 ip6addr_string(&ap
->rreq6
.rreq_da
),
196 EXTRACT_32BITS(&ap
->rreq6
.rreq_ds
),
197 ip6addr_string(&ap
->rreq6
.rreq_oa
),
198 EXTRACT_32BITS(&ap
->rreq6
.rreq_os
));
199 if (i
>= sizeof(struct aodv_ext
))
200 aodv_extension((void *)(&ap
->rreq6
+ 1), i
);
202 printf(" v6 rreq %d", length
);
208 aodv_v6_rrep(const union aodv
*ap
, const u_char
*dat
, u_int length
)
210 aodv_v6_rrep(const union aodv
*ap _U_
, const u_char
*dat _U_
, u_int length
)
220 i
= min(length
, (u_int
)(snapend
- dat
));
221 if (i
< sizeof(ap
->rrep6
)) {
225 i
-= sizeof(ap
->rrep6
);
226 printf(" rrep %d %s%sprefix %d hops %d\n"
227 "\tdst %s dseq %d src %s %d ms", length
,
228 ap
->rrep6
.rrep_type
& RREP_REPAIR
? "[R]" : "",
229 ap
->rrep6
.rrep_type
& RREP_ACK
? "[A] " : " ",
230 ap
->rrep6
.rrep_ps
& RREP_PREFIX_MASK
,
232 ip6addr_string(&ap
->rrep6
.rrep_da
),
233 EXTRACT_32BITS(&ap
->rrep6
.rrep_ds
),
234 ip6addr_string(&ap
->rrep6
.rrep_oa
),
235 EXTRACT_32BITS(&ap
->rrep6
.rrep_life
));
236 if (i
>= sizeof(struct aodv_ext
))
237 aodv_extension((void *)(&ap
->rrep6
+ 1), i
);
239 printf(" v6 rrep %d", length
);
245 aodv_v6_rerr(const union aodv
*ap
, u_int length
)
247 aodv_v6_rerr(const union aodv
*ap _U_
, u_int length
)
251 const struct rerr_unreach6
*dp6
= NULL
;
254 i
= length
- offsetof(struct aodv_rerr
, r
);
255 j
= sizeof(ap
->rerr
.r
.dest6
[0]);
256 dp6
= &ap
->rerr
.r
.dest6
[0];
257 n
= ap
->rerr
.rerr_dc
* j
;
258 printf(" rerr %s [items %d] [%d]:",
259 ap
->rerr
.rerr_flags
& RERR_NODELETE
? "[D]" : "",
260 ap
->rerr
.rerr_dc
, length
);
262 for (; i
-= j
>= 0; ++dp6
) {
263 printf(" {%s}(%d)", ip6addr_string(&dp6
->u_da
),
264 EXTRACT_32BITS(&dp6
->u_ds
));
269 printf(" v6 rerr %d", length
);
274 aodv_print(const u_char
*dat
, u_int length
, int is_ip6
)
276 const union aodv
*ap
;
278 ap
= (union aodv
*)dat
;
283 if (min(length
, (u_int
)(snapend
- dat
)) < sizeof(ap
->rrep_ack
)) {
289 switch (ap
->rerr
.rerr_type
) {
293 aodv_v6_rreq(ap
, dat
, length
);
295 aodv_rreq(ap
, dat
, length
);
300 aodv_v6_rrep(ap
, dat
, length
);
302 aodv_rrep(ap
, dat
, length
);
307 aodv_v6_rerr(ap
, length
);
309 aodv_rerr(ap
, length
);
313 printf(" rrep-ack %d", length
);
317 aodv_v6_rreq(ap
, dat
, length
);
321 aodv_v6_rrep(ap
, dat
, length
);
325 aodv_v6_rerr(ap
, length
);
328 case AODV_V6_RREP_ACK
:
329 printf(" v6 rrep-ack %d", length
);
333 printf(" %d %d", ap
->rreq
.rreq_type
, length
);