1258057Sbr/*
2261406Sbr * Copyright (c) 2001 William C. Fenner.
3258057Sbr *                All rights reserved.
4258057Sbr *
5258057Sbr * Redistribution and use in source and binary forms, with or without
6258057Sbr * modification, are permitted provided that: (1) source code
7258057Sbr * distributions retain the above copyright notice and this paragraph
8258057Sbr * in its entirety, and (2) distributions including binary code include
9258057Sbr * the above copyright notice and this paragraph in its entirety in
10258057Sbr * the documentation or other materials provided with the distribution.
11258057Sbr * The name of William C. Fenner may not be used to endorse or
12258057Sbr * promote products derived from this software without specific prior
13258057Sbr * written permission.  THIS SOFTWARE IS PROVIDED ``AS IS'' AND
14258057Sbr * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
15258057Sbr * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16258057Sbr * FOR A PARTICULAR PURPOSE.
17258057Sbr */
18258057Sbr#ifndef lint
19258057Sbrstatic const char rcsid[] _U_ =
20258057Sbr    "@(#) $Header: /tcpdump/master/tcpdump/print-msdp.c,v 1.7 2005-04-06 21:32:41 mcr Exp $";
21258057Sbr#endif
22258057Sbr
23258057Sbr#ifdef HAVE_CONFIG_H
24258057Sbr#include "config.h"
25258057Sbr#endif
26258057Sbr
27258057Sbr#include <tcpdump-stdinc.h>
28258057Sbr
29258057Sbr#include <stdio.h>
30258057Sbr#include <stdlib.h>
31261406Sbr
32258057Sbr#include "interface.h"
33258057Sbr#include "addrtoname.h"
34258057Sbr#include "extract.h"
35258057Sbr
36258057Sbr#define MSDP_TYPE_MAX	7
37258057Sbr
38258057Sbrvoid
39258057Sbrmsdp_print(const unsigned char *sp, u_int length)
40258057Sbr{
41261406Sbr	unsigned int type, len;
42261406Sbr
43261406Sbr	TCHECK2(*sp, 3);
44261406Sbr	/* See if we think we're at the beginning of a compound packet */
45261406Sbr	type = *sp;
46261406Sbr	len = EXTRACT_16BITS(sp + 1);
47261406Sbr	if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
48261406Sbr		goto trunc;	/* not really truncated, but still not decodable */
49261406Sbr	(void)printf(" msdp:");
50258057Sbr	while (length > 0) {
51258057Sbr		TCHECK2(*sp, 3);
52258057Sbr		type = *sp;
53258057Sbr		len = EXTRACT_16BITS(sp + 1);
54258057Sbr		if (len > 1400 || vflag)
55258057Sbr			printf(" [len %u]", len);
56258057Sbr		if (len < 3)
57258057Sbr			goto trunc;
58258057Sbr		sp += 3;
59258057Sbr		length -= 3;
60258057Sbr		switch (type) {
61258057Sbr		case 1:	/* IPv4 Source-Active */
62258057Sbr		case 3: /* IPv4 Source-Active Response */
63258057Sbr			if (type == 1)
64258057Sbr				(void)printf(" SA");
65258057Sbr			else
66258057Sbr				(void)printf(" SA-Response");
67258057Sbr			TCHECK(*sp);
68258057Sbr			(void)printf(" %u entries", *sp);
69258057Sbr			if ((u_int)((*sp * 12) + 8) < len) {
70258057Sbr				(void)printf(" [w/data]");
71258057Sbr				if (vflag > 1) {
72258057Sbr					(void)printf(" ");
73258057Sbr					ip_print(gndo, sp + *sp * 12 + 8 - 3,
74258057Sbr					         len - (*sp * 12 + 8));
75258057Sbr				}
76258057Sbr			}
77258057Sbr			break;
78258057Sbr		case 2:
79258057Sbr			(void)printf(" SA-Request");
80258057Sbr			TCHECK2(*sp, 5);
81258057Sbr			(void)printf(" for %s", ipaddr_string(sp + 1));
82258057Sbr			break;
83258057Sbr		case 4:
84258057Sbr			(void)printf(" Keepalive");
85258057Sbr			if (len != 3)
86261406Sbr				(void)printf("[len=%d] ", len);
87258057Sbr			break;
88258057Sbr		case 5:
89258057Sbr			(void)printf(" Notification");
90258057Sbr			break;
91258057Sbr		default:
92258057Sbr			(void)printf(" [type=%d len=%d]", type, len);
93258057Sbr			break;
94258057Sbr		}
95258057Sbr		sp += (len - 3);
96258057Sbr		length -= (len - 3);
97258057Sbr	}
98258057Sbr	return;
99258057Sbrtrunc:
100261406Sbr	(void)printf(" [|msdp]");
101261406Sbr}
102261406Sbr
103261406Sbr/*
104261406Sbr * Local Variables:
105261406Sbr * c-style: whitesmith
106261406Sbr * c-basic-offset: 8
107261406Sbr * End:
108261406Sbr */
109261406Sbr