]> The Tcpdump Group git mirrors - tcpdump/blob - print-msdp.c
Printers must include 'netdissect.h', not 'interface.h'
[tcpdump] / print-msdp.c
1 /*
2 * Copyright (c) 2001 William C. Fenner.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code
7 * distributions retain the above copyright notice and this paragraph
8 * in its entirety, and (2) distributions including binary code include
9 * the above copyright notice and this paragraph in its entirety in
10 * the documentation or other materials provided with the distribution.
11 * The name of William C. Fenner may not be used to endorse or
12 * promote products derived from this software without specific prior
13 * written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND
14 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
15 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16 * FOR A PARTICULAR PURPOSE.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include <tcpdump-stdinc.h>
24
25 #include "netdissect.h"
26 #include "addrtoname.h"
27 #include "extract.h"
28
29 #define MSDP_TYPE_MAX 7
30
31 void
32 msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
33 {
34 unsigned int type, len;
35
36 ND_TCHECK2(*sp, 3);
37 /* See if we think we're at the beginning of a compound packet */
38 type = *sp;
39 len = EXTRACT_16BITS(sp + 1);
40 if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
41 goto trunc; /* not really truncated, but still not decodable */
42 ND_PRINT((ndo, " msdp:"));
43 while (length > 0) {
44 ND_TCHECK2(*sp, 3);
45 type = *sp;
46 len = EXTRACT_16BITS(sp + 1);
47 if (len > 1400 || ndo->ndo_vflag)
48 ND_PRINT((ndo, " [len %u]", len));
49 if (len < 3)
50 goto trunc;
51 sp += 3;
52 length -= 3;
53 switch (type) {
54 case 1: /* IPv4 Source-Active */
55 case 3: /* IPv4 Source-Active Response */
56 if (type == 1)
57 ND_PRINT((ndo, " SA"));
58 else
59 ND_PRINT((ndo, " SA-Response"));
60 ND_TCHECK(*sp);
61 ND_PRINT((ndo, " %u entries", *sp));
62 if ((u_int)((*sp * 12) + 8) < len) {
63 ND_PRINT((ndo, " [w/data]"));
64 if (ndo->ndo_vflag > 1) {
65 ND_PRINT((ndo, " "));
66 ip_print(ndo, sp + *sp * 12 + 8 - 3,
67 len - (*sp * 12 + 8));
68 }
69 }
70 break;
71 case 2:
72 ND_PRINT((ndo, " SA-Request"));
73 ND_TCHECK2(*sp, 5);
74 ND_PRINT((ndo, " for %s", ipaddr_string(ndo, sp + 1)));
75 break;
76 case 4:
77 ND_PRINT((ndo, " Keepalive"));
78 if (len != 3)
79 ND_PRINT((ndo, "[len=%d] ", len));
80 break;
81 case 5:
82 ND_PRINT((ndo, " Notification"));
83 break;
84 default:
85 ND_PRINT((ndo, " [type=%d len=%d]", type, len));
86 break;
87 }
88 sp += (len - 3);
89 length -= (len - 3);
90 }
91 return;
92 trunc:
93 ND_PRINT((ndo, " [|msdp]"));
94 }
95
96 /*
97 * Local Variables:
98 * c-style: whitesmith
99 * c-basic-offset: 8
100 * End:
101 */