Fix markup. Fix backslashes to surive roff.
[netbsd-mini2440.git] / dist / tcpdump / print-ripng.c
blobbc4d175d392db4d934d5cb92d38d5c8f6f77957e
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 1989, 1990, 1991, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 #include <sys/cdefs.h>
25 #ifndef lint
26 #if 0
27 static const char rcsid[] _U_ =
28 "@(#) Header: /tcpdump/master/tcpdump/print-ripng.c,v 1.18 2005/01/04 00:15:54 guy Exp";
29 #else
30 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
31 #endif
32 #endif
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
38 #ifdef INET6
40 #include <tcpdump-stdinc.h>
41 #include <stdio.h>
43 #include "route6d.h"
44 #include "interface.h"
45 #include "addrtoname.h"
46 #include "extract.h"
48 #if !defined(IN6_IS_ADDR_UNSPECIFIED) && !defined(_MSC_VER) /* MSVC inline */
49 static int IN6_IS_ADDR_UNSPECIFIED(const struct in6_addr *addr)
51 static const struct in6_addr in6addr_any; /* :: */
52 return (memcmp(addr, &in6addr_any, sizeof(*addr)) == 0);
54 #endif
56 static int
57 rip6_entry_print(register const struct netinfo6 *ni, int metric)
59 int l;
60 l = printf("%s/%d", ip6addr_string(&ni->rip6_dest), ni->rip6_plen);
61 if (ni->rip6_tag)
62 l += printf(" [%d]", EXTRACT_16BITS(&ni->rip6_tag));
63 if (metric)
64 l += printf(" (%d)", ni->rip6_metric);
65 return l;
68 void
69 ripng_print(const u_char *dat, unsigned int length)
71 register const struct rip6 *rp = (struct rip6 *)dat;
72 register const struct netinfo6 *ni;
73 register u_int amt;
74 register u_int i;
75 int j;
76 int trunc;
78 if (snapend < dat)
79 return;
80 amt = snapend - dat;
81 i = min(length, amt);
82 if (i < (sizeof(struct rip6) - sizeof(struct netinfo6)))
83 return;
84 i -= (sizeof(struct rip6) - sizeof(struct netinfo6));
86 switch (rp->rip6_cmd) {
88 case RIP6_REQUEST:
89 j = length / sizeof(*ni);
90 if (j == 1
91 && rp->rip6_nets->rip6_metric == HOPCNT_INFINITY6
92 && IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) {
93 printf(" ripng-req dump");
94 break;
96 if (j * sizeof(*ni) != length - 4)
97 printf(" ripng-req %d[%u]:", j, length);
98 else
99 printf(" ripng-req %d:", j);
100 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
101 for (ni = rp->rip6_nets; i >= sizeof(*ni);
102 i -= sizeof(*ni), ++ni) {
103 if (vflag > 1)
104 printf("\n\t");
105 else
106 printf(" ");
107 rip6_entry_print(ni, 0);
109 break;
110 case RIP6_RESPONSE:
111 j = length / sizeof(*ni);
112 if (j * sizeof(*ni) != length - 4)
113 printf(" ripng-resp %d[%u]:", j, length);
114 else
115 printf(" ripng-resp %d:", j);
116 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
117 for (ni = rp->rip6_nets; i >= sizeof(*ni);
118 i -= sizeof(*ni), ++ni) {
119 if (vflag > 1)
120 printf("\n\t");
121 else
122 printf(" ");
123 rip6_entry_print(ni, ni->rip6_metric);
125 if (trunc)
126 printf("[|ripng]");
127 break;
128 default:
129 printf(" ripng-%d ?? %u", rp->rip6_cmd, length);
130 break;
132 if (rp->rip6_vers != RIP6_VERSION)
133 printf(" [vers %d]", rp->rip6_vers);
135 #endif /* INET6 */