print-rip.c revision 1.3
1/**//*	$OpenBSD: print-rip.c,v 1.3 1996/06/10 07:47:46 deraadt Exp $	*/
2/*	$NetBSD: print-rip.c,v 1.4 1995/06/20 23:38:49 christos Exp $	*/
3
4/*
5 * Copyright (c) 1989, 1990, 1991, 1993, 1994
6 *	The Regents of the University of California.  All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that: (1) source code distributions
10 * retain the above copyright notice and this paragraph in its entirety, (2)
11 * distributions including binary code include the above copyright notice and
12 * this paragraph in its entirety in the documentation or other materials
13 * provided with the distribution, and (3) all advertising materials mentioning
14 * features or use of this software display the following acknowledgement:
15 * ``This product includes software developed by the University of California,
16 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
17 * the University nor the names of its contributors may be used to endorse
18 * or promote products derived from this software without specific prior
19 * written permission.
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 */
24
25#ifndef lint
26static char rcsid[] =
27    "@(#) Header: print-rip.c,v 1.20 94/06/14 20:18:47 leres Exp (LBL)";
28#endif
29
30#include <sys/param.h>
31#include <sys/time.h>
32#include <sys/types.h>
33#include <sys/socket.h>
34
35#include <netinet/in.h>
36#include <netinet/in_systm.h>
37#include <netinet/ip.h>
38#include <netinet/ip_var.h>
39#include <netinet/udp.h>
40#include <netinet/udp_var.h>
41
42#include <protocols/routed.h>
43
44#include <errno.h>
45#include <stdio.h>
46
47#include "interface.h"
48#include "addrtoname.h"
49
50static void
51rip_entry_print(register const struct netinfo *ni)
52{
53	if (ntohs(ni->rip_family) != AF_INET) {
54		register int i;
55
56		printf(" [family %d:", ntohs(ni->rip_family));
57		printf(" %04x", ni->rip_dst);
58		printf("]");
59	} else {
60		struct sockaddr_in sin;
61		sin.sin_addr.s_addr = ni->rip_dst;
62		printf(" %s", ipaddr_string(&sin.sin_addr));
63		if (ni->rip_tag)
64			printf(" [port %d]", ni->rip_tag);
65	}
66	printf("(%d)", ntohl(ni->rip_metric));
67}
68
69void
70rip_print(const u_char *dat, int length)
71{
72	register const struct rip *rp = (struct rip *)dat;
73	register const struct netinfo *ni;
74	register int amt = snapend - dat;
75	register int i = min(length, amt) -
76			 (sizeof(struct rip) - sizeof(struct netinfo));
77	int j;
78	int trunc;
79
80	if (i < 0)
81		return;
82
83	switch (rp->rip_cmd) {
84
85	case RIPCMD_REQUEST:
86		printf(" rip-req %d", length);
87		break;
88	case RIPCMD_RESPONSE:
89		j = length / sizeof(*ni);
90		if (j * sizeof(*ni) != length - 4)
91			printf(" rip-resp %d[%d]:", j, length);
92		else
93			printf(" rip-resp %d:", j);
94		trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
95		for (ni = rp->rip_nets; (i -= sizeof(*ni)) >= 0; ++ni)
96			rip_entry_print(ni);
97		if (trunc)
98			printf("[|rip]");
99		break;
100	case RIPCMD_TRACEON:
101		printf(" rip-traceon %d: \"%s\"", length, rp->rip_tracefile);
102		break;
103	case RIPCMD_TRACEOFF:
104		printf(" rip-traceoff %d", length);
105		break;
106	case RIPCMD_POLL:
107		printf(" rip-poll %d", length);
108		break;
109	case RIPCMD_POLLENTRY:
110		printf(" rip-pollentry %d", length);
111		break;
112	default:
113		printf(" rip-%d ?? %d", rp->rip_cmd, length);
114		break;
115	}
116	if (rp->rip_vers != RIP_VERSION_1)
117		printf(" [vers %d]", rp->rip_vers);
118}
119