xref: /freebsd/contrib/tcpdump/print-msdp.c (revision 5b0fe47811aa43b75fc69dbf7338cace232a4d48)
1a90e161bSBill Fenner /*
2a90e161bSBill Fenner  * Copyright (c) 2001 William C. Fenner.
3a90e161bSBill Fenner  *                All rights reserved.
4a90e161bSBill Fenner  *
5a90e161bSBill Fenner  * Redistribution and use in source and binary forms, with or without
6a90e161bSBill Fenner  * modification, are permitted provided that: (1) source code
7a90e161bSBill Fenner  * distributions retain the above copyright notice and this paragraph
8a90e161bSBill Fenner  * in its entirety, and (2) distributions including binary code include
9a90e161bSBill Fenner  * the above copyright notice and this paragraph in its entirety in
10a90e161bSBill Fenner  * the documentation or other materials provided with the distribution.
11a90e161bSBill Fenner  * The name of William C. Fenner may not be used to endorse or
12a90e161bSBill Fenner  * promote products derived from this software without specific prior
13a90e161bSBill Fenner  * written permission.  THIS SOFTWARE IS PROVIDED ``AS IS'' AND
14a90e161bSBill Fenner  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
15a90e161bSBill Fenner  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16a90e161bSBill Fenner  * FOR A PARTICULAR PURPOSE.
17a90e161bSBill Fenner  */
18a90e161bSBill Fenner #ifndef lint
195b0fe478SBruce M Simpson static const char rcsid[] _U_ =
205b0fe478SBruce M Simpson     "@(#) $Header: /tcpdump/master/tcpdump/print-msdp.c,v 1.4.2.2 2003/11/16 08:51:34 guy Exp $";
21a90e161bSBill Fenner #endif
22a90e161bSBill Fenner 
23a90e161bSBill Fenner #ifdef HAVE_CONFIG_H
24a90e161bSBill Fenner #include "config.h"
25a90e161bSBill Fenner #endif
26a90e161bSBill Fenner 
275b0fe478SBruce M Simpson #include <tcpdump-stdinc.h>
285b0fe478SBruce M Simpson 
29a90e161bSBill Fenner #include <stdio.h>
30a90e161bSBill Fenner #include <stdlib.h>
31a90e161bSBill Fenner 
32a90e161bSBill Fenner #include "interface.h"
33a90e161bSBill Fenner #include "addrtoname.h"
34a90e161bSBill Fenner #include "extract.h"
35a90e161bSBill Fenner 
36a90e161bSBill Fenner #define MSDP_TYPE_MAX	7
37a90e161bSBill Fenner 
38a90e161bSBill Fenner void
39a90e161bSBill Fenner msdp_print(const unsigned char *sp, u_int length)
40a90e161bSBill Fenner {
41a90e161bSBill Fenner 	unsigned int type, len;
42a90e161bSBill Fenner 
43a90e161bSBill Fenner 	TCHECK2(*sp, 3);
44a90e161bSBill Fenner 	/* See if we think we're at the beginning of a compound packet */
45a90e161bSBill Fenner 	type = *sp;
46a90e161bSBill Fenner 	len = EXTRACT_16BITS(sp + 1);
47a90e161bSBill Fenner 	if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
48a90e161bSBill Fenner 		goto trunc;	/* not really truncated, but still not decodable */
49a90e161bSBill Fenner 	(void)printf(" msdp:");
50a90e161bSBill Fenner 	while (length > 0) {
51a90e161bSBill Fenner 		TCHECK2(*sp, 3);
52a90e161bSBill Fenner 		type = *sp;
53a90e161bSBill Fenner 		len = EXTRACT_16BITS(sp + 1);
54a90e161bSBill Fenner 		if (len > 1400 || vflag)
555b0fe478SBruce M Simpson 			printf(" [len %u]", len);
56a90e161bSBill Fenner 		if (len < 3)
57a90e161bSBill Fenner 			goto trunc;
58a90e161bSBill Fenner 		sp += 3;
59a90e161bSBill Fenner 		length -= 3;
60a90e161bSBill Fenner 		switch (type) {
61a90e161bSBill Fenner 		case 1:	/* IPv4 Source-Active */
62a90e161bSBill Fenner 		case 3: /* IPv4 Source-Active Response */
63a90e161bSBill Fenner 			if (type == 1)
64a90e161bSBill Fenner 				(void)printf(" SA");
65a90e161bSBill Fenner 			else
66a90e161bSBill Fenner 				(void)printf(" SA-Response");
67a90e161bSBill Fenner 			TCHECK(*sp);
685b0fe478SBruce M Simpson 			(void)printf(" %u entries", *sp);
695b0fe478SBruce M Simpson 			if ((u_int)((*sp * 12) + 8) < len) {
70a90e161bSBill Fenner 				(void)printf(" [w/data]");
71a90e161bSBill Fenner 				if (vflag > 1) {
72a90e161bSBill Fenner 					(void)printf(" ");
73a90e161bSBill Fenner 					ip_print(sp + *sp * 12 + 8 - 3,
74a90e161bSBill Fenner 					         len - (*sp * 12 + 8));
75a90e161bSBill Fenner 				}
76a90e161bSBill Fenner 			}
77a90e161bSBill Fenner 			break;
78a90e161bSBill Fenner 		case 2:
79a90e161bSBill Fenner 			(void)printf(" SA-Request");
80a90e161bSBill Fenner 			TCHECK2(*sp, 5);
81a90e161bSBill Fenner 			(void)printf(" for %s", ipaddr_string(sp + 1));
82a90e161bSBill Fenner 			break;
83a90e161bSBill Fenner 		case 4:
84a90e161bSBill Fenner 			(void)printf(" Keepalive");
85a90e161bSBill Fenner 			if (len != 3)
86a90e161bSBill Fenner 				(void)printf("[len=%d] ", len);
87a90e161bSBill Fenner 			break;
88a90e161bSBill Fenner 		case 5:
89a90e161bSBill Fenner 			(void)printf(" Notification");
90a90e161bSBill Fenner 			break;
91a90e161bSBill Fenner 		default:
92a90e161bSBill Fenner 			(void)printf(" [type=%d len=%d]", type, len);
93a90e161bSBill Fenner 			break;
94a90e161bSBill Fenner 		}
95a90e161bSBill Fenner 		sp += (len - 3);
96a90e161bSBill Fenner 		length -= (len - 3);
97a90e161bSBill Fenner 	}
98a90e161bSBill Fenner 	return;
99a90e161bSBill Fenner trunc:
100a90e161bSBill Fenner 	(void)printf(" [|msdp]");
101a90e161bSBill Fenner }
102