]> The Tcpdump Group git mirrors - tcpdump/blob - print-rip.c
7fcc5aa047b8fe51f7cdb8c6be38ddb428466ebe
[tcpdump] / print-rip.c
1 /*
2 * Copyright (c) 1989, 1990, 1991, 1993, 1994, 1996
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 #ifndef lint
23 static const char rcsid[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-rip.c,v 1.37 1999-10-17 21:37:15 mcr Exp $ (LBL)";
25 #endif
26
27 #include <sys/param.h>
28 #include <sys/time.h>
29 #include <sys/socket.h>
30
31 #include <netinet/in.h>
32 #include <netinet/in_systm.h>
33 #include <netinet/ip.h>
34 #include <netinet/udp.h>
35
36 #include <stdio.h>
37
38 #include "interface.h"
39 #include "addrtoname.h"
40 #include "extract.h" /* must come after interface.h */
41
42 struct rip {
43 u_char rip_cmd; /* request/response */
44 u_char rip_vers; /* protocol version # */
45 u_short rip_zero2; /* unused */
46 };
47 #define RIPCMD_REQUEST 1 /* want info */
48 #define RIPCMD_RESPONSE 2 /* responding to request */
49 #define RIPCMD_TRACEON 3 /* turn tracing on */
50 #define RIPCMD_TRACEOFF 4 /* turn it off */
51 #define RIPCMD_POLL 5 /* want info from everybody */
52 #define RIPCMD_POLLENTRY 6 /* poll for entry */
53
54 struct rip_netinfo {
55 u_short rip_family;
56 u_short rip_tag;
57 u_int32_t rip_dest;
58 u_int32_t rip_dest_mask;
59 u_int32_t rip_router;
60 u_int32_t rip_metric; /* cost of route */
61 };
62
63 static void
64 rip_entry_print(register int vers, register const struct rip_netinfo *ni)
65 {
66 register u_char *cp, *ep;
67
68 if (EXTRACT_16BITS(&ni->rip_family) != AF_INET) {
69
70 printf(" [family %d:", EXTRACT_16BITS(&ni->rip_family));
71 cp = (u_char *)&ni->rip_tag;
72 ep = (u_char *)&ni->rip_metric + sizeof(ni->rip_metric);
73 for (; cp < ep; cp += 2)
74 printf(" %04x", EXTRACT_16BITS(cp));
75 printf("]");
76 } else if (vers < 2) {
77 /* RFC 1058 */
78 printf(" %s", ipaddr_string(&ni->rip_dest));
79 } else {
80 /* RFC 1723 */
81 printf(" {%s", ipaddr_string(&ni->rip_dest));
82 if (ni->rip_dest_mask)
83 printf("/%s", ipaddr_string(&ni->rip_dest_mask));
84 if (ni->rip_router)
85 printf("->%s", ipaddr_string(&ni->rip_router));
86 if (ni->rip_tag)
87 printf(" tag %04x", EXTRACT_16BITS(&ni->rip_tag));
88 printf("}");
89 }
90 printf("(%d)", EXTRACT_32BITS(&ni->rip_metric));
91 }
92
93 void
94 rip_print(const u_char *dat, u_int length)
95 {
96 register const struct rip *rp;
97 register const struct rip_netinfo *ni;
98 register int i, j, trunc;
99
100 i = min(length, snapend - dat) - sizeof(*rp);
101 if (i < 0)
102 return;
103
104 rp = (struct rip *)dat;
105 switch (rp->rip_cmd) {
106
107 case RIPCMD_REQUEST:
108 printf(" rip-req %d", length);
109 break;
110
111 case RIPCMD_RESPONSE:
112 j = length / sizeof(*ni);
113 if (j * sizeof(*ni) != length - 4)
114 printf(" rip-resp %d[%d]:", j, length);
115 else
116 printf(" rip-resp %d:", j);
117 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
118 ni = (struct rip_netinfo *)(rp + 1);
119 for (; (i -= sizeof(*ni)) >= 0; ++ni)
120 rip_entry_print(rp->rip_vers, ni);
121 if (trunc)
122 printf("[|rip]");
123 break;
124
125 case RIPCMD_TRACEON:
126 printf(" rip-traceon %d: \"", length);
127 (void)fn_print((const u_char *)(rp + 1), snapend);
128 fputs("\"\n", stdout);
129 break;
130
131 case RIPCMD_TRACEOFF:
132 printf(" rip-traceoff %d", length);
133 break;
134
135 case RIPCMD_POLL:
136 printf(" rip-poll %d", length);
137 break;
138
139 case RIPCMD_POLLENTRY:
140 printf(" rip-pollentry %d", length);
141 break;
142
143 default:
144 printf(" rip-#%d %d", rp->rip_cmd, length);
145 break;
146 }
147 switch (rp->rip_vers) {
148
149 case 1:
150 case 2:
151 break;
152
153 default:
154 printf(" [vers %d]", rp->rip_vers);
155 break;
156 }
157 }