print-msdp.c revision 146773
164562Sgshapiro/*
264562Sgshapiro * Copyright (c) 2001 William C. Fenner.
364562Sgshapiro *                All rights reserved.
464562Sgshapiro *
564562Sgshapiro * Redistribution and use in source and binary forms, with or without
6111823Sgshapiro * modification, are permitted provided that: (1) source code
764562Sgshapiro * distributions retain the above copyright notice and this paragraph
864562Sgshapiro * in its entirety, and (2) distributions including binary code include
964562Sgshapiro * the above copyright notice and this paragraph in its entirety in
1064562Sgshapiro * the documentation or other materials provided with the distribution.
1164562Sgshapiro * The name of William C. Fenner may not be used to endorse or
1264562Sgshapiro * promote products derived from this software without specific prior
1364562Sgshapiro * written permission.  THIS SOFTWARE IS PROVIDED ``AS IS'' AND
1464562Sgshapiro * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
1564562Sgshapiro * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
1664562Sgshapiro * FOR A PARTICULAR PURPOSE.
17159609Sgshapiro */
1864562Sgshapiro#ifndef lint
1964562Sgshapirostatic const char rcsid[] _U_ =
2064562Sgshapiro    "@(#) $Header: /tcpdump/master/tcpdump/print-msdp.c,v 1.7 2005/04/06 21:32:41 mcr Exp $";
2164562Sgshapiro#endif
2264562Sgshapiro
2364562Sgshapiro#ifdef HAVE_CONFIG_H
2464562Sgshapiro#include "config.h"
2564562Sgshapiro#endif
26159609Sgshapiro
27159609Sgshapiro#include <tcpdump-stdinc.h>
28159609Sgshapiro
29159609Sgshapiro#include <stdio.h>
30159609Sgshapiro#include <stdlib.h>
31159609Sgshapiro
32159609Sgshapiro#include "interface.h"
33159609Sgshapiro#include "addrtoname.h"
34159609Sgshapiro#include "extract.h"
35159609Sgshapiro
36159609Sgshapiro#define MSDP_TYPE_MAX	7
37159609Sgshapiro
38159609Sgshapirovoid
39159609Sgshapiromsdp_print(const unsigned char *sp, u_int length)
40159609Sgshapiro{
41159609Sgshapiro	unsigned int type, len;
42159609Sgshapiro
43159609Sgshapiro	TCHECK2(*sp, 3);
44159609Sgshapiro	/* See if we think we're at the beginning of a compound packet */
45159609Sgshapiro	type = *sp;
46159609Sgshapiro	len = EXTRACT_16BITS(sp + 1);
4780785Sgshapiro	if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
48159609Sgshapiro		goto trunc;	/* not really truncated, but still not decodable */
49159609Sgshapiro	(void)printf(" msdp:");
50159609Sgshapiro	while (length > 0) {
51159609Sgshapiro		TCHECK2(*sp, 3);
52159609Sgshapiro		type = *sp;
53159609Sgshapiro		len = EXTRACT_16BITS(sp + 1);
54159609Sgshapiro		if (len > 1400 || vflag)
55159609Sgshapiro			printf(" [len %u]", len);
56159609Sgshapiro		if (len < 3)
57159609Sgshapiro			goto trunc;
58159609Sgshapiro		sp += 3;
59159609Sgshapiro		length -= 3;
60159609Sgshapiro		switch (type) {
61159609Sgshapiro		case 1:	/* IPv4 Source-Active */
62159609Sgshapiro		case 3: /* IPv4 Source-Active Response */
63159609Sgshapiro			if (type == 1)
64159609Sgshapiro				(void)printf(" SA");
65159609Sgshapiro			else
6680785Sgshapiro				(void)printf(" SA-Response");
67159609Sgshapiro			TCHECK(*sp);
68159609Sgshapiro			(void)printf(" %u entries", *sp);
69159609Sgshapiro			if ((u_int)((*sp * 12) + 8) < len) {
70159609Sgshapiro				(void)printf(" [w/data]");
71159609Sgshapiro				if (vflag > 1) {
72159609Sgshapiro					(void)printf(" ");
73159609Sgshapiro					ip_print(gndo, sp + *sp * 12 + 8 - 3,
74159609Sgshapiro					         len - (*sp * 12 + 8));
75159609Sgshapiro				}
76159609Sgshapiro			}
77159609Sgshapiro			break;
78159609Sgshapiro		case 2:
79159609Sgshapiro			(void)printf(" SA-Request");
80159609Sgshapiro			TCHECK2(*sp, 5);
81159609Sgshapiro			(void)printf(" for %s", ipaddr_string(sp + 1));
82159609Sgshapiro			break;
83159609Sgshapiro		case 4:
84159609Sgshapiro			(void)printf(" Keepalive");
85159609Sgshapiro			if (len != 3)
86159609Sgshapiro				(void)printf("[len=%d] ", len);
87159609Sgshapiro			break;
88159609Sgshapiro		case 5:
89159609Sgshapiro			(void)printf(" Notification");
90159609Sgshapiro			break;
91159609Sgshapiro		default:
92159609Sgshapiro			(void)printf(" [type=%d len=%d]", type, len);
93159609Sgshapiro			break;
94159609Sgshapiro		}
95159609Sgshapiro		sp += (len - 3);
96159609Sgshapiro		length -= (len - 3);
97159609Sgshapiro	}
98159609Sgshapiro	return;
99159609Sgshapirotrunc:
100159609Sgshapiro	(void)printf(" [|msdp]");
101159609Sgshapiro}
102159609Sgshapiro
103159609Sgshapiro/*
104159609Sgshapiro * Local Variables:
105159609Sgshapiro * c-style: whitesmith
106159609Sgshapiro * c-basic-offset: 8
107159609Sgshapiro * End:
108159609Sgshapiro */
109159609Sgshapiro