]> The Tcpdump Group git mirrors - tcpdump/blob - print-msdp.c
Fix build on FreeBSD.
[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 <stdio.h>
26 #include <stdlib.h>
27
28 #include "interface.h"
29 #include "addrtoname.h"
30 #include "extract.h"
31
32 #define MSDP_TYPE_MAX 7
33
34 void
35 msdp_print(const unsigned char *sp, u_int length)
36 {
37 unsigned int type, len;
38
39 TCHECK2(*sp, 3);
40 /* See if we think we're at the beginning of a compound packet */
41 type = *sp;
42 len = EXTRACT_16BITS(sp + 1);
43 if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
44 goto trunc; /* not really truncated, but still not decodable */
45 (void)printf(" msdp:");
46 while (length > 0) {
47 TCHECK2(*sp, 3);
48 type = *sp;
49 len = EXTRACT_16BITS(sp + 1);
50 if (len > 1400 || vflag)
51 printf(" [len %u]", len);
52 if (len < 3)
53 goto trunc;
54 sp += 3;
55 length -= 3;
56 switch (type) {
57 case 1: /* IPv4 Source-Active */
58 case 3: /* IPv4 Source-Active Response */
59 if (type == 1)
60 (void)printf(" SA");
61 else
62 (void)printf(" SA-Response");
63 TCHECK(*sp);
64 (void)printf(" %u entries", *sp);
65 if ((u_int)((*sp * 12) + 8) < len) {
66 (void)printf(" [w/data]");
67 if (vflag > 1) {
68 (void)printf(" ");
69 ip_print(gndo, sp + *sp * 12 + 8 - 3,
70 len - (*sp * 12 + 8));
71 }
72 }
73 break;
74 case 2:
75 (void)printf(" SA-Request");
76 TCHECK2(*sp, 5);
77 (void)printf(" for %s", ipaddr_string(sp + 1));
78 break;
79 case 4:
80 (void)printf(" Keepalive");
81 if (len != 3)
82 (void)printf("[len=%d] ", len);
83 break;
84 case 5:
85 (void)printf(" Notification");
86 break;
87 default:
88 (void)printf(" [type=%d len=%d]", type, len);
89 break;
90 }
91 sp += (len - 3);
92 length -= (len - 3);
93 }
94 return;
95 trunc:
96 (void)printf(" [|msdp]");
97 }
98
99 /*
100 * Local Variables:
101 * c-style: whitesmith
102 * c-basic-offset: 8
103 * End:
104 */