1 /*
2 * Copyright (c) 1988-1990 The Regents of the University of California.
3 * 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 char rcsid[] =
24 "@(#) $Header: print-rip.c,v 1.12 91/04/19 10:46:46 mccanne Exp $ (LBL)";
25 #endif
26
27 #include <sys/param.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include <netinet/in_systm.h>
32 #include <netinet/ip.h>
33 #include <netinet/ip_var.h>
34 #include <netinet/udp.h>
35 #include <netinet/udp_var.h>
36 #include <protocols/routed.h>
37
38 #include <errno.h>
39
40 #include "interface.h"
41 #include "addrtoname.h"
42
43 static void
rip_entry_print(ni)44 rip_entry_print(ni)
45 register struct netinfo *ni;
46 {
47 if (ntohs(ni->rip_dst.sa_family) != AF_INET) {
48 register int i;
49
50 printf(" [family %d:", ntohs(ni->rip_dst.sa_family));
51 for (i = 0; i < 14; i += 2)
52 printf(" %02x%02x", ni->rip_dst.sa_data[i],
53 ni->rip_dst.sa_data[i+1]);
54 printf("]");
55 } else {
56 register struct sockaddr_in *sin =
57 (struct sockaddr_in *)&ni->rip_dst;
58 printf(" %s", ipaddr_string(&sin->sin_addr));
59 if (sin->sin_port)
60 printf(" [port %d]", sin->sin_port);
61 }
62 printf("(%d)", ntohl(ni->rip_metric));
63 }
64
65 void
rip_print(dat,length)66 rip_print(dat, length)
67 u_char *dat;
68 int length;
69 {
70 register struct rip *rp = (struct rip *)dat;
71 register struct netinfo *ni;
72 register int amt = (u_char *)snapend - dat;
73 register int i = min(length, amt) -
74 (sizeof(struct rip) - sizeof(struct netinfo));
75 int j;
76 int trunc;
77
78 if (i < 0)
79 return;
80
81 switch (rp->rip_cmd) {
82
83 case RIPCMD_REQUEST:
84 printf(" rip-req %d", length);
85 break;
86 case RIPCMD_RESPONSE:
87 j = length / sizeof(*ni);
88 if (j * sizeof(*ni) != length - 4)
89 printf(" rip-resp %d[%d]:", j, length);
90 else
91 printf(" rip-resp %d:", j);
92 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
93 for (ni = rp->rip_nets; (i -= sizeof(*ni)) >= 0; ++ni)
94 rip_entry_print(ni);
95 if (trunc)
96 printf("[|rip]");
97 break;
98 case RIPCMD_TRACEON:
99 printf(" rip-traceon %d: \"%s\"", length, rp->rip_tracefile);
100 break;
101 case RIPCMD_TRACEOFF:
102 printf(" rip-traceoff %d", length);
103 break;
104 case RIPCMD_POLL:
105 printf(" rip-poll %d", length);
106 break;
107 case RIPCMD_POLLENTRY:
108 printf(" rip-pollentry %d", length);
109 break;
110 default:
111 printf(" rip-%d ?? %d", rp->rip_cmd, length);
112 break;
113 }
114 if (rp->rip_vers != RIPVERSION)
115 printf(" [vers %d]", rp->rip_vers);
116 }
117