xref: /netbsd-src/external/bsd/tcpdump/dist/print-msdp.c (revision 6a9b3088d8d2341ca1454531d365c15fe9c1c589)
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 #include <sys/cdefs.h>
19 #ifndef lint
20 #if 0
21 static const char rcsid[] _U_ =
22     "@(#) Header: /tcpdump/master/tcpdump/print-msdp.c,v 1.7 2005-04-06 21:32:41 mcr Exp";
23 #else
24 __RCSID("$NetBSD: print-msdp.c,v 1.2 2010/12/05 05:11:30 christos Exp $");
25 #endif
26 #endif
27 
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31 
32 #include <tcpdump-stdinc.h>
33 
34 #include <stdio.h>
35 #include <stdlib.h>
36 
37 #include "interface.h"
38 #include "addrtoname.h"
39 #include "extract.h"
40 
41 #define MSDP_TYPE_MAX	7
42 
43 void
44 msdp_print(const unsigned char *sp, u_int length)
45 {
46 	unsigned int type, len;
47 
48 	TCHECK2(*sp, 3);
49 	/* See if we think we're at the beginning of a compound packet */
50 	type = *sp;
51 	len = EXTRACT_16BITS(sp + 1);
52 	if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
53 		goto trunc;	/* not really truncated, but still not decodable */
54 	(void)printf(" msdp:");
55 	while (length > 0) {
56 		TCHECK2(*sp, 3);
57 		type = *sp;
58 		len = EXTRACT_16BITS(sp + 1);
59 		if (len > 1400 || vflag)
60 			printf(" [len %u]", len);
61 		if (len < 3)
62 			goto trunc;
63 		sp += 3;
64 		length -= 3;
65 		switch (type) {
66 		case 1:	/* IPv4 Source-Active */
67 		case 3: /* IPv4 Source-Active Response */
68 			if (type == 1)
69 				(void)printf(" SA");
70 			else
71 				(void)printf(" SA-Response");
72 			TCHECK(*sp);
73 			(void)printf(" %u entries", *sp);
74 			if ((u_int)((*sp * 12) + 8) < len) {
75 				(void)printf(" [w/data]");
76 				if (vflag > 1) {
77 					(void)printf(" ");
78 					ip_print(gndo, sp + *sp * 12 + 8 - 3,
79 					         len - (*sp * 12 + 8));
80 				}
81 			}
82 			break;
83 		case 2:
84 			(void)printf(" SA-Request");
85 			TCHECK2(*sp, 5);
86 			(void)printf(" for %s", ipaddr_string(sp + 1));
87 			break;
88 		case 4:
89 			(void)printf(" Keepalive");
90 			if (len != 3)
91 				(void)printf("[len=%d] ", len);
92 			break;
93 		case 5:
94 			(void)printf(" Notification");
95 			break;
96 		default:
97 			(void)printf(" [type=%d len=%d]", type, len);
98 			break;
99 		}
100 		sp += (len - 3);
101 		length -= (len - 3);
102 	}
103 	return;
104 trunc:
105 	(void)printf(" [|msdp]");
106 }
107 
108 /*
109  * Local Variables:
110  * c-style: whitesmith
111  * c-basic-offset: 8
112  * End:
113  */
114