Explicitly request literal mode after .Xr.
[netbsd-mini2440.git] / dist / tcpdump / print-vrrp.c
blob383d3781769b7785dd415d203a7b515cd626e674
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 2000 William C. Fenner.
5 * All rights reserved.
7 * Kevin Steves <ks@hp.se> July 2000
8 * Modified to:
9 * - print version, type string and packet length
10 * - print IP address count if > 1 (-v)
11 * - verify checksum (-v)
12 * - print authentication string (-v)
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that: (1) source code
16 * distributions retain the above copyright notice and this paragraph
17 * in its entirety, and (2) distributions including binary code include
18 * the above copyright notice and this paragraph in its entirety in
19 * the documentation or other materials provided with the distribution.
20 * The name of William C. Fenner may not be used to endorse or
21 * promote products derived from this software without specific prior
22 * written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND
23 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
24 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE.
28 #include <sys/cdefs.h>
29 #ifndef lint
30 #if 0
31 static const char rcsid[] _U_ =
32 "@(#) Header: /tcpdump/master/tcpdump/print-vrrp.c,v 1.9.2.1 2005/05/06 07:57:20 guy Exp";
33 #else
34 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
35 #endif
36 #endif
38 #ifdef HAVE_CONFIG_H
39 #include "config.h"
40 #endif
42 #include <tcpdump-stdinc.h>
44 #include <stdio.h>
45 #include <stdlib.h>
47 #include "interface.h"
48 #include "extract.h"
49 #include "addrtoname.h"
52 * RFC 2338:
53 * 0 1 2 3
54 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
55 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56 * |Version| Type | Virtual Rtr ID| Priority | Count IP Addrs|
57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 * | Auth Type | Adver Int | Checksum |
59 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 * | IP Address (1) |
61 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62 * | . |
63 * | . |
64 * | . |
65 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 * | IP Address (n) |
67 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 * | Authentication Data (1) |
69 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 * | Authentication Data (2) |
71 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 /* Type */
75 #define VRRP_TYPE_ADVERTISEMENT 1
77 static const struct tok type2str[] = {
78 { VRRP_TYPE_ADVERTISEMENT, "Advertisement" },
79 { 0, NULL }
82 /* Auth Type */
83 #define VRRP_AUTH_NONE 0
84 #define VRRP_AUTH_SIMPLE 1
85 #define VRRP_AUTH_AH 2
87 static const struct tok auth2str[] = {
88 { VRRP_AUTH_NONE, "none" },
89 { VRRP_AUTH_SIMPLE, "simple" },
90 { VRRP_AUTH_AH, "ah" },
91 { 0, NULL }
94 void
95 vrrp_print(register const u_char *bp, register u_int len, int ttl)
97 int version, type, auth_type;
98 const char *type_s;
100 TCHECK(bp[0]);
101 version = (bp[0] & 0xf0) >> 4;
102 type = bp[0] & 0x0f;
103 type_s = tok2str(type2str, "unknown type (%u)", type);
104 printf("VRRPv%u, %s", version, type_s);
105 if (ttl != 255)
106 printf(", (ttl %u)", ttl);
107 if (version != 2 || type != VRRP_TYPE_ADVERTISEMENT)
108 return;
109 TCHECK(bp[2]);
110 printf(", vrid %u, prio %u", bp[1], bp[2]);
111 TCHECK(bp[5]);
112 auth_type = bp[4];
113 printf(", authtype %s", tok2str(auth2str, NULL, auth_type));
114 printf(", intvl %us, length %u", bp[5],len);
115 if (vflag) {
116 int naddrs = bp[3];
117 int i;
118 char c;
120 if (TTEST2(bp[0], len) && in_cksum((const u_short*)bp, len, 0))
121 printf(", (bad vrrp cksum %x)",
122 EXTRACT_16BITS(&bp[6]));
123 printf(", addrs");
124 if (naddrs > 1)
125 printf("(%d)", naddrs);
126 printf(":");
127 c = ' ';
128 bp += 8;
129 for (i = 0; i < naddrs; i++) {
130 TCHECK(bp[3]);
131 printf("%c%s", c, ipaddr_string(bp));
132 c = ',';
133 bp += 4;
135 if (auth_type == VRRP_AUTH_SIMPLE) { /* simple text password */
136 TCHECK(bp[7]);
137 printf(" auth \"");
138 if (fn_printn(bp, 8, snapend)) {
139 printf("\"");
140 goto trunc;
142 printf("\"");
145 return;
146 trunc:
147 printf("[|vrrp]");