trace.c revision 27244
111820Sjulian/*
211820Sjulian * Copyright (c) 1985, 1993
311820Sjulian *	The Regents of the University of California.  All rights reserved.
411820Sjulian *
511820Sjulian * Copyright (c) 1995 John Hay.  All rights reserved.
611820Sjulian *
711820Sjulian * This file includes significant work done at Cornell University by
811820Sjulian * Bill Nesheim.  That work included by permission.
911820Sjulian *
1011820Sjulian * Redistribution and use in source and binary forms, with or without
1111820Sjulian * modification, are permitted provided that the following conditions
1211820Sjulian * are met:
1311820Sjulian * 1. Redistributions of source code must retain the above copyright
1411820Sjulian *    notice, this list of conditions and the following disclaimer.
1511820Sjulian * 2. Redistributions in binary form must reproduce the above copyright
1611820Sjulian *    notice, this list of conditions and the following disclaimer in the
1711820Sjulian *    documentation and/or other materials provided with the distribution.
1811820Sjulian * 3. All advertising materials mentioning features or use of this software
1911820Sjulian *    must display the following acknowledgement:
2011820Sjulian *	This product includes software developed by the University of
2111820Sjulian *	California, Berkeley and its contributors.
2211820Sjulian * 4. Neither the name of the University nor the names of its contributors
2311820Sjulian *    may be used to endorse or promote products derived from this software
2411820Sjulian *    without specific prior written permission.
2511820Sjulian *
2611820Sjulian * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2711820Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2811820Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2911820Sjulian * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3011820Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3111820Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3211820Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3311820Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3411820Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3511820Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3611820Sjulian * SUCH DAMAGE.
3711820Sjulian *
3827244Sjhay *	$Id: trace.c,v 1.4 1997/02/22 16:01:04 peter Exp $
3911820Sjulian */
4011820Sjulian
4111820Sjulian#ifndef lint
4211820Sjulianstatic char sccsid[] = "@(#)trace.c	8.1 (Berkeley) 6/5/93";
4311820Sjulian#endif /* not lint */
4411820Sjulian
4511820Sjulian/*
4611820Sjulian * Routing Table Management Daemon
4711820Sjulian */
4811820Sjulian#define	RIPCMDS
4911820Sjulian#define	SAPCMDS
5011820Sjulian#include <stdlib.h>
5111820Sjulian#include <unistd.h>
5211820Sjulian#include <sys/types.h>
5311820Sjulian#include <time.h>
5411820Sjulian#include "defs.h"
5511820Sjulian
5611820Sjulian#define	NRECORDS	50		/* size of circular trace buffer */
5711820Sjulian#ifdef DEBUG
5811820SjulianFILE	*ftrace = stdout;
5911820Sjulianint	tracing = 1;
6011820Sjulian#else DEBUG
6111820SjulianFILE	*ftrace = NULL;
6211820Sjulianint	tracing = 0;
6311820Sjulian#endif
6411820Sjulian
6511820Sjulianvoid dumpif(FILE *fd, struct interface *ifp);
6611820Sjulianvoid dumptrace(FILE *fd, char *dir, struct ifdebug *ifd);
6711820Sjulian
6811820Sjulianvoid
6911820Sjuliantraceinit(ifp)
7011820Sjulian	register struct interface *ifp;
7111820Sjulian{
7211820Sjulian	static int iftraceinit();
7311820Sjulian
7411820Sjulian	if (iftraceinit(ifp, &ifp->int_input) &&
7511820Sjulian	    iftraceinit(ifp, &ifp->int_output))
7611820Sjulian		return;
7711820Sjulian	tracing = 0;
7811820Sjulian	syslog(LOG_ERR, "traceinit: can't init %s\n", ifp->int_name);
7911820Sjulian}
8011820Sjulian
8111820Sjulianstatic int
8211820Sjulianiftraceinit(ifp, ifd)
8311820Sjulian	struct interface *ifp;
8411820Sjulian	register struct ifdebug *ifd;
8511820Sjulian{
8611820Sjulian	register struct iftrace *t;
8711820Sjulian
8811820Sjulian	ifd->ifd_records =
8911820Sjulian	  (struct iftrace *)malloc(NRECORDS * sizeof (struct iftrace));
9011820Sjulian	if (ifd->ifd_records == 0)
9111820Sjulian		return (0);
9211820Sjulian	ifd->ifd_front = ifd->ifd_records;
9311820Sjulian	ifd->ifd_count = 0;
9411820Sjulian	for (t = ifd->ifd_records; t < ifd->ifd_records + NRECORDS; t++) {
9511820Sjulian		t->ift_size = 0;
9611820Sjulian		t->ift_packet = 0;
9711820Sjulian	}
9811820Sjulian	ifd->ifd_if = ifp;
9911820Sjulian	return (1);
10011820Sjulian}
10111820Sjulian
10211820Sjulianvoid
10311820Sjuliantraceon(file)
10411820Sjulian	char *file;
10511820Sjulian{
10611820Sjulian
10711820Sjulian	if (ftrace != NULL)
10811820Sjulian		return;
10911820Sjulian	ftrace = fopen(file, "a");
11011820Sjulian	if (ftrace == NULL)
11111820Sjulian		return;
11211820Sjulian	dup2(fileno(ftrace), 1);
11311820Sjulian	dup2(fileno(ftrace), 2);
11411820Sjulian	tracing = 1;
11511820Sjulian}
11611820Sjulian
11711820Sjulianvoid
11811820Sjuliantraceoff(void)
11911820Sjulian{
12011820Sjulian	if (!tracing)
12111820Sjulian		return;
12211820Sjulian	if (ftrace != NULL)
12311820Sjulian		fclose(ftrace);
12411820Sjulian	ftrace = NULL;
12511820Sjulian	tracing = 0;
12611820Sjulian}
12711820Sjulian
12811820Sjulianvoid
12911820Sjuliantrace(ifd, who, p, len, m)
13011820Sjulian	register struct ifdebug *ifd;
13111820Sjulian	struct sockaddr *who;
13211820Sjulian	char *p;
13311820Sjulian	int len, m;
13411820Sjulian{
13511820Sjulian	register struct iftrace *t;
13611820Sjulian
13711820Sjulian	if (ifd->ifd_records == 0)
13811820Sjulian		return;
13911820Sjulian	t = ifd->ifd_front++;
14011820Sjulian	if (ifd->ifd_front >= ifd->ifd_records + NRECORDS)
14111820Sjulian		ifd->ifd_front = ifd->ifd_records;
14211820Sjulian	if (ifd->ifd_count < NRECORDS)
14311820Sjulian		ifd->ifd_count++;
14411820Sjulian	if (t->ift_size > 0 && t->ift_packet)
14511820Sjulian		free(t->ift_packet);
14611820Sjulian	t->ift_packet = 0;
14711820Sjulian	t->ift_stamp = time(0);
14811820Sjulian	t->ift_who = *who;
14911820Sjulian	if (len > 0) {
15011820Sjulian		t->ift_packet = malloc(len);
15111820Sjulian		if (t->ift_packet)
15211820Sjulian			bcopy(p, t->ift_packet, len);
15311820Sjulian		else
15411820Sjulian			len = 0;
15511820Sjulian	}
15611820Sjulian	t->ift_size = len;
15711820Sjulian	t->ift_metric = m;
15811820Sjulian}
15911820Sjulian
16011820Sjulianvoid
16111820Sjuliantraceaction(fd, action, rt)
16211820Sjulian	FILE *fd;
16311820Sjulian	char *action;
16411820Sjulian	struct rt_entry *rt;
16511820Sjulian{
16611820Sjulian	struct sockaddr_ipx *dst, *gate;
16711820Sjulian	static struct bits {
16811820Sjulian		int	t_bits;
16911820Sjulian		char	*t_name;
17011820Sjulian	} flagbits[] = {
17111820Sjulian		{ RTF_UP,	"UP" },
17211820Sjulian		{ RTF_GATEWAY,	"GATEWAY" },
17311820Sjulian		{ RTF_HOST,	"HOST" },
17411820Sjulian		{ 0 }
17511820Sjulian	}, statebits[] = {
17611820Sjulian		{ RTS_PASSIVE,	"PASSIVE" },
17711820Sjulian		{ RTS_REMOTE,	"REMOTE" },
17811820Sjulian		{ RTS_INTERFACE,"INTERFACE" },
17911820Sjulian		{ RTS_CHANGED,	"CHANGED" },
18011820Sjulian		{ 0 }
18111820Sjulian	};
18211820Sjulian	register struct bits *p;
18311820Sjulian	register int first;
18411820Sjulian	char *cp;
18511820Sjulian
18611820Sjulian	if (fd == NULL)
18711820Sjulian		return;
18811820Sjulian	fprintf(fd, "%s ", action);
18911820Sjulian	dst = (struct sockaddr_ipx *)&rt->rt_dst;
19011820Sjulian	gate = (struct sockaddr_ipx *)&rt->rt_router;
19111820Sjulian	fprintf(fd, "dst %s, ", ipxdp_ntoa(&dst->sipx_addr));
19211820Sjulian	fprintf(fd, "router %s, metric %d, ticks %d, flags",
19311820Sjulian	     ipxdp_ntoa(&gate->sipx_addr), rt->rt_metric, rt->rt_ticks);
19411820Sjulian	cp = " %s";
19511820Sjulian	for (first = 1, p = flagbits; p->t_bits > 0; p++) {
19611820Sjulian		if ((rt->rt_flags & p->t_bits) == 0)
19711820Sjulian			continue;
19811820Sjulian		fprintf(fd, cp, p->t_name);
19911820Sjulian		if (first) {
20011820Sjulian			cp = "|%s";
20111820Sjulian			first = 0;
20211820Sjulian		}
20311820Sjulian	}
20411820Sjulian	fprintf(fd, " state");
20511820Sjulian	cp = " %s";
20611820Sjulian	for (first = 1, p = statebits; p->t_bits > 0; p++) {
20711820Sjulian		if ((rt->rt_state & p->t_bits) == 0)
20811820Sjulian			continue;
20911820Sjulian		fprintf(fd, cp, p->t_name);
21011820Sjulian		if (first) {
21111820Sjulian			cp = "|%s";
21211820Sjulian			first = 0;
21311820Sjulian		}
21411820Sjulian	}
21511820Sjulian	putc('\n', fd);
21611820Sjulian	if (!tracepackets && (rt->rt_state & RTS_PASSIVE) == 0 && rt->rt_ifp)
21711820Sjulian		dumpif(fd, rt->rt_ifp);
21811820Sjulian	fflush(fd);
21911820Sjulian}
22011820Sjulian
22111820Sjulianvoid
22227244Sjhaytraceactionlog(action, rt)
22327244Sjhay	char *action;
22427244Sjhay	struct rt_entry *rt;
22527244Sjhay{
22627244Sjhay	struct sockaddr_ipx *dst, *gate;
22727244Sjhay	static struct bits {
22827244Sjhay		int	t_bits;
22927244Sjhay		char	*t_name;
23027244Sjhay	} flagbits[] = {
23127244Sjhay		{ RTF_UP,	"UP" },
23227244Sjhay		{ RTF_GATEWAY,	"GATEWAY" },
23327244Sjhay		{ RTF_HOST,	"HOST" },
23427244Sjhay		{ 0 }
23527244Sjhay	}, statebits[] = {
23627244Sjhay		{ RTS_PASSIVE,	"PASSIVE" },
23727244Sjhay		{ RTS_REMOTE,	"REMOTE" },
23827244Sjhay		{ RTS_INTERFACE,"INTERFACE" },
23927244Sjhay		{ RTS_CHANGED,	"CHANGED" },
24027244Sjhay		{ 0 }
24127244Sjhay	};
24227244Sjhay	register struct bits *p;
24327244Sjhay	register int first;
24427244Sjhay	char *cp;
24527244Sjhay	char *lstr, *olstr;
24627244Sjhay
24727244Sjhay	dst = (struct sockaddr_ipx *)&rt->rt_dst;
24827244Sjhay	gate = (struct sockaddr_ipx *)&rt->rt_router;
24927244Sjhay	asprintf(&lstr, "%s dst %s,", action, ipxdp_ntoa(&dst->sipx_addr));
25027244Sjhay	olstr = lstr;
25127244Sjhay	asprintf(&lstr, "%s router %s, metric %d, ticks %d, flags",
25227244Sjhay	     olstr, ipxdp_ntoa(&gate->sipx_addr), rt->rt_metric, rt->rt_ticks);
25327244Sjhay	free(olstr);
25427244Sjhay	olstr = lstr;
25527244Sjhay	cp = "%s %s";
25627244Sjhay	for (first = 1, p = flagbits; p->t_bits > 0; p++) {
25727244Sjhay		if ((rt->rt_flags & p->t_bits) == 0)
25827244Sjhay			continue;
25927244Sjhay		asprintf(&lstr, cp, olstr, p->t_name);
26027244Sjhay		free(olstr);
26127244Sjhay		olstr = lstr;
26227244Sjhay		if (first) {
26327244Sjhay			cp = "%s|%s";
26427244Sjhay			first = 0;
26527244Sjhay		}
26627244Sjhay	}
26727244Sjhay	asprintf(&lstr, "%s state", olstr);
26827244Sjhay	free(olstr);
26927244Sjhay	olstr = lstr;
27027244Sjhay	cp = "%s %s";
27127244Sjhay	for (first = 1, p = statebits; p->t_bits > 0; p++) {
27227244Sjhay		if ((rt->rt_state & p->t_bits) == 0)
27327244Sjhay			continue;
27427244Sjhay		asprintf(&lstr, cp, olstr, p->t_name);
27527244Sjhay		free(olstr);
27627244Sjhay		olstr = lstr;
27727244Sjhay		if (first) {
27827244Sjhay			cp = "%s|%s";
27927244Sjhay			first = 0;
28027244Sjhay		}
28127244Sjhay	}
28227244Sjhay	syslog(LOG_DEBUG, lstr);
28327244Sjhay	free(lstr);
28427244Sjhay}
28527244Sjhay
28627244Sjhayvoid
28727244Sjhaytracesapactionlog(action, sap)
28827244Sjhay	char *action;
28927244Sjhay	struct sap_entry *sap;
29027244Sjhay{
29127244Sjhay	syslog(LOG_DEBUG, "%-12.12s  service %04X %-20.20s "
29227244Sjhay		    "addr %s.%04X %c metric %d\n",
29327244Sjhay		     action,
29427244Sjhay		     ntohs(sap->sap.ServType),
29527244Sjhay		     sap->sap.ServName,
29627244Sjhay		     ipxdp_ntoa(&sap->sap.ipx),
29727244Sjhay		     ntohs(sap->sap.ipx.x_port),
29827244Sjhay		     (sap->clone ? 'C' : ' '),
29927244Sjhay		     ntohs(sap->sap.hops));
30027244Sjhay}
30127244Sjhay
30227244Sjhayvoid
30311820Sjuliandumpif(fd, ifp)
30411820Sjulian	register struct interface *ifp;
30511820Sjulian	FILE *fd;
30611820Sjulian{
30711820Sjulian	if (ifp->int_input.ifd_count || ifp->int_output.ifd_count) {
30811820Sjulian		fprintf(fd, "*** Packet history for interface %s ***\n",
30911820Sjulian			ifp->int_name);
31011820Sjulian		dumptrace(fd, "to", &ifp->int_output);
31111820Sjulian		dumptrace(fd, "from", &ifp->int_input);
31211820Sjulian		fprintf(fd, "*** end packet history ***\n");
31311820Sjulian	}
31411820Sjulian}
31511820Sjulian
31611820Sjulianvoid
31711820Sjuliandumptrace(fd, dir, ifd)
31811820Sjulian	FILE *fd;
31911820Sjulian	char *dir;
32011820Sjulian	register struct ifdebug *ifd;
32111820Sjulian{
32211820Sjulian	register struct iftrace *t;
32311820Sjulian	char *cp = !strcmp(dir, "to") ? "Output" : "Input";
32411820Sjulian
32511820Sjulian	if (ifd->ifd_front == ifd->ifd_records &&
32611820Sjulian	    ifd->ifd_front->ift_size == 0) {
32711820Sjulian		fprintf(fd, "%s: no packets.\n", cp);
32811820Sjulian		return;
32911820Sjulian	}
33011820Sjulian	fprintf(fd, "%s trace:\n", cp);
33111820Sjulian	t = ifd->ifd_front - ifd->ifd_count;
33211820Sjulian	if (t < ifd->ifd_records)
33311820Sjulian		t += NRECORDS;
33411820Sjulian	for ( ; ifd->ifd_count; ifd->ifd_count--, t++) {
33511820Sjulian		if (t >= ifd->ifd_records + NRECORDS)
33611820Sjulian			t = ifd->ifd_records;
33711820Sjulian		if (t->ift_size == 0)
33811820Sjulian			continue;
33911820Sjulian		fprintf(fd, "%.24s: metric=%d\n", ctime(&t->ift_stamp),
34011820Sjulian			t->ift_metric);
34111820Sjulian		dumppacket(fd, dir, &t->ift_who, t->ift_packet, t->ift_size);
34211820Sjulian	}
34311820Sjulian}
34411820Sjulian
34511820Sjulianvoid
34611820Sjuliandumppacket(fd, dir, source, cp, size)
34711820Sjulian	FILE *fd;
34811820Sjulian	char *dir;
34911820Sjulian	struct sockaddr *source;
35011820Sjulian	char *cp;
35111820Sjulian	register int size;
35211820Sjulian{
35311820Sjulian	register struct rip *msg = (struct rip *)cp;
35411820Sjulian	register struct netinfo *n;
35511820Sjulian	struct sockaddr_ipx *who = (struct sockaddr_ipx *)source;
35611820Sjulian
35711820Sjulian	if (msg->rip_cmd && ntohs(msg->rip_cmd) < RIPCMD_MAX)
35811820Sjulian		fprintf(fd, "%s %s %s#%x", ripcmds[ntohs(msg->rip_cmd)],
35911820Sjulian		    dir, ipxdp_ntoa(&who->sipx_addr),
36011820Sjulian		    ntohs(who->sipx_addr.x_port));
36111820Sjulian	else {
36211820Sjulian		fprintf(fd, "Bad cmd 0x%x %s %s#%x\n", ntohs(msg->rip_cmd),
36311820Sjulian		    dir, ipxdp_ntoa(&who->sipx_addr),
36411820Sjulian		    ntohs(who->sipx_addr.x_port));
36511820Sjulian		fprintf(fd, "size=%d cp=%x packet=%x\n", size,
36611820Sjulian			(u_int)cp, (u_int)packet);
36711820Sjulian		return;
36811820Sjulian	}
36911820Sjulian	switch (ntohs(msg->rip_cmd)) {
37011820Sjulian
37111820Sjulian	case RIPCMD_REQUEST:
37211820Sjulian	case RIPCMD_RESPONSE:
37311820Sjulian		fprintf(fd, ":\n");
37411820Sjulian		size -= sizeof (u_short);
37511820Sjulian		n = msg->rip_nets;
37611820Sjulian		for (; size > 0; n++, size -= sizeof (struct netinfo)) {
37711820Sjulian			if (size < sizeof (struct netinfo))
37811820Sjulian				break;
37911820Sjulian			fprintf(fd, "\tnet %s metric %d ticks %d\n",
38011820Sjulian			     ipxdp_nettoa(n->rip_dst),
38111820Sjulian			     ntohs(n->rip_metric),
38211820Sjulian			     ntohs(n->rip_ticks));
38311820Sjulian		}
38411820Sjulian		break;
38511820Sjulian
38611820Sjulian	}
38711820Sjulian}
38811820Sjulian
38911820Sjulianvoid
39011820Sjuliandumpsappacket(fd, dir, source, cp, size)
39111820Sjulian	FILE *fd;
39211820Sjulian	char *dir;
39311820Sjulian	struct sockaddr *source;
39411820Sjulian	char *cp;
39511820Sjulian	register int size;
39611820Sjulian{
39711820Sjulian	register struct sap_packet *msg = (struct sap_packet *)cp;
39811820Sjulian	register struct sap_info *n;
39911820Sjulian	struct sockaddr_ipx *who = (struct sockaddr_ipx *)source;
40011820Sjulian
40111820Sjulian	if (msg->sap_cmd && ntohs(msg->sap_cmd) < SAPCMD_MAX)
40211820Sjulian		fprintf(fd, "%s %s %s#%x", sapcmds[ntohs(msg->sap_cmd)],
40311820Sjulian		    dir, ipxdp_ntoa(&who->sipx_addr),
40411820Sjulian		    ntohs(who->sipx_addr.x_port));
40511820Sjulian	else {
40611820Sjulian		fprintf(fd, "Bad cmd 0x%x %s %s#%x\n", ntohs(msg->sap_cmd),
40711820Sjulian		    dir, ipxdp_ntoa(&who->sipx_addr),
40811820Sjulian		    ntohs(who->sipx_addr.x_port));
40911820Sjulian		fprintf(fd, "size=%d cp=%x packet=%x\n", size,
41011820Sjulian			(u_int)cp, (u_int)packet);
41111820Sjulian		return;
41211820Sjulian	}
41311820Sjulian	switch (ntohs(msg->sap_cmd)) {
41411820Sjulian
41511820Sjulian	case SAP_REQ:
41611820Sjulian	case SAP_RESP:
41711820Sjulian	case SAP_REQ_NEAR:
41811820Sjulian	case SAP_RESP_NEAR:
41911820Sjulian		fprintf(fd, ":\n");
42011820Sjulian		size -= sizeof (u_short);
42111820Sjulian		n = msg->sap;
42211820Sjulian		for (; size > 0; n++, size -= sizeof (struct sap_info)) {
42311820Sjulian			if (size < sizeof (struct sap_info))
42411820Sjulian				break;
42511820Sjulian			fprintf(fd, "  service %04X %-20.20s "
42611820Sjulian				    "addr %s.%04X metric %d\n",
42711820Sjulian			     ntohs(n->ServType),
42811820Sjulian			     n->ServName,
42911820Sjulian			     ipxdp_ntoa(&n->ipx),
43011820Sjulian			     ntohs(n->ipx.x_port),
43111820Sjulian			     ntohs(n->hops));
43211820Sjulian		}
43311820Sjulian		break;
43411820Sjulian
43511820Sjulian	}
43611820Sjulian}
43711820Sjulian
43811820Sjulianvoid
43911820Sjuliandumpsaptable(fd, sh)
44011820Sjulian	FILE *fd;
44111820Sjulian	struct sap_hash *sh;
44211820Sjulian{
44311820Sjulian	register struct sap_entry *sap;
44411820Sjulian	struct sap_hash *hash;
44511820Sjulian	int x = 0;
44611820Sjulian
44711820Sjulian	fprintf(fd, "------- SAP table dump. -------\n");
44811820Sjulian	for (hash = sh; hash < &sh[SAPHASHSIZ]; hash++, x++) {
44911820Sjulian		fprintf(fd, "HASH %d\n", x);
45011820Sjulian		sap = hash->forw;
45111820Sjulian		for (; sap != (struct sap_entry *)hash; sap = sap->forw) {
45211820Sjulian			fprintf(fd, "  service %04X %-20.20s "
45311820Sjulian				    "addr %s.%04X %c metric %d\n",
45411820Sjulian				     ntohs(sap->sap.ServType),
45511820Sjulian				     sap->sap.ServName,
45611820Sjulian				     ipxdp_ntoa(&sap->sap.ipx),
45711820Sjulian				     ntohs(sap->sap.ipx.x_port),
45811820Sjulian				     (sap->clone ? 'C' : ' '),
45911820Sjulian				     ntohs(sap->sap.hops));
46011820Sjulian		}
46111820Sjulian	}
46211820Sjulian	fprintf(fd, "\n");
46311820Sjulian}
46411820Sjulian
46515248Sjhayvoid
46615248Sjhaydumpriptable(fd)
46715248Sjhay	FILE *fd;
46815248Sjhay{
46915248Sjhay	register struct rt_entry *rip;
47015248Sjhay	struct rthash *hash;
47115248Sjhay	int x;
47215248Sjhay	struct rthash *rh = nethash;
47315248Sjhay
47415248Sjhay	fprintf(fd, "------- RIP table dump. -------\n");
47515248Sjhay	x = 0;
47615248Sjhay	fprintf(fd, "Network table.\n");
47715248Sjhay
47815248Sjhay	for (hash = rh; hash < &rh[ROUTEHASHSIZ]; hash++, x++) {
47915248Sjhay		fprintf(fd, "HASH %d\n", x);
48015248Sjhay		rip = hash->rt_forw;
48115248Sjhay		for (; rip != (struct rt_entry *)hash; rip = rip->rt_forw) {
48215248Sjhay			fprintf(fd, "  dest %s\t",
48315248Sjhay				ipxdp_ntoa(&satoipx_addr(rip->rt_dst)));
48415248Sjhay			fprintf(fd, "%s metric %d, ticks %d\n",
48515248Sjhay				ipxdp_ntoa(&satoipx_addr(rip->rt_router)),
48615248Sjhay				rip->rt_metric,
48715248Sjhay				rip->rt_ticks);
48815248Sjhay		}
48915248Sjhay	}
49015248Sjhay	fprintf(fd, "\n");
49115248Sjhay}
49215248Sjhay
49311820Sjulianunion ipx_net_u net;
49411820Sjulian
49511820Sjulianchar *
49611820Sjulianipxdp_nettoa(val)
49711820Sjulianunion ipx_net val;
49811820Sjulian{
49911820Sjulian	static char buf[100];
50011820Sjulian	net.net_e = val;
50111820Sjulian	(void)sprintf(buf, "%lx", ntohl(net.long_e));
50211820Sjulian	return (buf);
50311820Sjulian}
50411820Sjulian
50511820Sjulian
50611820Sjulianchar *
50711820Sjulianipxdp_ntoa(addr)
50811820Sjulianstruct ipx_addr *addr;
50911820Sjulian{
51011820Sjulian    static char buf[100];
51111820Sjulian
51211820Sjulian    (void)sprintf(buf, "%s#%x:%x:%x:%x:%x:%x",
51311820Sjulian	ipxdp_nettoa(addr->x_net),
51411820Sjulian	addr->x_host.c_host[0], addr->x_host.c_host[1],
51511820Sjulian	addr->x_host.c_host[2], addr->x_host.c_host[3],
51611820Sjulian	addr->x_host.c_host[4], addr->x_host.c_host[5]);
51711820Sjulian
51811820Sjulian    return(buf);
51911820Sjulian}
520