Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / tcpdump / print-msdp.c
blob53137544e3b0a7401997040332a3c0bc5236fbac
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 2001 William C. Fenner.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code
9 * distributions retain the above copyright notice and this paragraph
10 * in its entirety, and (2) distributions including binary code include
11 * the above copyright notice and this paragraph in its entirety in
12 * the documentation or other materials provided with the distribution.
13 * The name of William C. Fenner may not be used to endorse or
14 * promote products derived from this software without specific prior
15 * written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND
16 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
17 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE.
20 #include <sys/cdefs.h>
21 #ifndef lint
22 #if 0
23 static const char rcsid[] _U_ =
24 "@(#) Header: /tcpdump/master/tcpdump/print-msdp.c,v 1.7 2005/04/06 21:32:41 mcr Exp";
25 #else
26 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
27 #endif
28 #endif
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
34 #include <tcpdump-stdinc.h>
36 #include <stdio.h>
37 #include <stdlib.h>
39 #include "interface.h"
40 #include "addrtoname.h"
41 #include "extract.h"
43 #define MSDP_TYPE_MAX 7
45 void
46 msdp_print(const unsigned char *sp, u_int length)
48 unsigned int type, len;
50 TCHECK2(*sp, 3);
51 /* See if we think we're at the beginning of a compound packet */
52 type = *sp;
53 len = EXTRACT_16BITS(sp + 1);
54 if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
55 goto trunc; /* not really truncated, but still not decodable */
56 (void)printf(" msdp:");
57 while (length > 0) {
58 TCHECK2(*sp, 3);
59 type = *sp;
60 len = EXTRACT_16BITS(sp + 1);
61 if (len > 1400 || vflag)
62 printf(" [len %u]", len);
63 if (len < 3)
64 goto trunc;
65 sp += 3;
66 length -= 3;
67 switch (type) {
68 case 1: /* IPv4 Source-Active */
69 case 3: /* IPv4 Source-Active Response */
70 if (type == 1)
71 (void)printf(" SA");
72 else
73 (void)printf(" SA-Response");
74 TCHECK(*sp);
75 (void)printf(" %u entries", *sp);
76 if ((u_int)((*sp * 12) + 8) < len) {
77 (void)printf(" [w/data]");
78 if (vflag > 1) {
79 (void)printf(" ");
80 ip_print(gndo, sp + *sp * 12 + 8 - 3,
81 len - (*sp * 12 + 8));
84 break;
85 case 2:
86 (void)printf(" SA-Request");
87 TCHECK2(*sp, 5);
88 (void)printf(" for %s", ipaddr_string(sp + 1));
89 break;
90 case 4:
91 (void)printf(" Keepalive");
92 if (len != 3)
93 (void)printf("[len=%d] ", len);
94 break;
95 case 5:
96 (void)printf(" Notification");
97 break;
98 default:
99 (void)printf(" [type=%d len=%d]", type, len);
100 break;
102 sp += (len - 3);
103 length -= (len - 3);
105 return;
106 trunc:
107 (void)printf(" [|msdp]");
111 * Local Variables:
112 * c-style: whitesmith
113 * c-basic-offset: 8
114 * End: