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 */
3811820Sjulian
3911820Sjulian#ifndef lint
4097632Swollman#if 0
4111820Sjulianstatic char sccsid[] = "@(#)trace.c	8.1 (Berkeley) 6/5/93";
4297632Swollman#endif
4397632Swollmanstatic const char rcsid[] =
4497632Swollman  "$FreeBSD$";
4511820Sjulian#endif /* not lint */
4611820Sjulian
4711820Sjulian/*
4811820Sjulian * Routing Table Management Daemon
4911820Sjulian */
5011820Sjulian#define	RIPCMDS
5111820Sjulian#define	SAPCMDS
5211820Sjulian#include <stdlib.h>
5311820Sjulian#include <unistd.h>
5411820Sjulian#include <sys/types.h>
5511820Sjulian#include <time.h>
5611820Sjulian#include "defs.h"
5711820Sjulian
5811820Sjulian#define	NRECORDS	50		/* size of circular trace buffer */
5911820Sjulian#ifdef DEBUG
6011820SjulianFILE	*ftrace = stdout;
6111820Sjulianint	tracing = 1;
6297632Swollman#else /* DEBUG */
6311820SjulianFILE	*ftrace = NULL;
6411820Sjulianint	tracing = 0;
6511820Sjulian#endif
6611820Sjulian
6711820Sjulianvoid dumpif(FILE *fd, struct interface *ifp);
6811820Sjulianvoid dumptrace(FILE *fd, char *dir, struct ifdebug *ifd);
69148716Sstefanfstatic int iftraceinit(struct interface *ifp, struct ifdebug *ifd);
7011820Sjulian
7111820Sjulianvoid
7211820Sjuliantraceinit(ifp)
7311820Sjulian	register struct interface *ifp;
7411820Sjulian{
7511820Sjulian	if (iftraceinit(ifp, &ifp->int_input) &&
7611820Sjulian	    iftraceinit(ifp, &ifp->int_output))
7711820Sjulian		return;
7811820Sjulian	tracing = 0;
7911820Sjulian	syslog(LOG_ERR, "traceinit: can't init %s\n", ifp->int_name);
8011820Sjulian}
8111820Sjulian
8211820Sjulianstatic int
8311820Sjulianiftraceinit(ifp, ifd)
8411820Sjulian	struct interface *ifp;
8511820Sjulian	register struct ifdebug *ifd;
8611820Sjulian{
8711820Sjulian	register struct iftrace *t;
8811820Sjulian
8911820Sjulian	ifd->ifd_records =
9011820Sjulian	  (struct iftrace *)malloc(NRECORDS * sizeof (struct iftrace));
9111820Sjulian	if (ifd->ifd_records == 0)
9211820Sjulian		return (0);
9311820Sjulian	ifd->ifd_front = ifd->ifd_records;
9411820Sjulian	ifd->ifd_count = 0;
9511820Sjulian	for (t = ifd->ifd_records; t < ifd->ifd_records + NRECORDS; t++) {
9611820Sjulian		t->ift_size = 0;
9711820Sjulian		t->ift_packet = 0;
9811820Sjulian	}
9911820Sjulian	ifd->ifd_if = ifp;
10011820Sjulian	return (1);
10111820Sjulian}
10211820Sjulian
10311820Sjulianvoid
10411820Sjuliantraceon(file)
10511820Sjulian	char *file;
10611820Sjulian{
10711820Sjulian
10811820Sjulian	if (ftrace != NULL)
10911820Sjulian		return;
11011820Sjulian	ftrace = fopen(file, "a");
11111820Sjulian	if (ftrace == NULL)
11211820Sjulian		return;
11311820Sjulian	dup2(fileno(ftrace), 1);
11411820Sjulian	dup2(fileno(ftrace), 2);
11511820Sjulian	tracing = 1;
11611820Sjulian}
11711820Sjulian
11811820Sjulianvoid
11911820Sjuliantraceoff(void)
12011820Sjulian{
12111820Sjulian	if (!tracing)
12211820Sjulian		return;
12311820Sjulian	if (ftrace != NULL)
12411820Sjulian		fclose(ftrace);
12511820Sjulian	ftrace = NULL;
12611820Sjulian	tracing = 0;
12711820Sjulian}
12811820Sjulian
12911820Sjulianvoid
13011820Sjuliantrace(ifd, who, p, len, m)
13111820Sjulian	register struct ifdebug *ifd;
13211820Sjulian	struct sockaddr *who;
13311820Sjulian	char *p;
13411820Sjulian	int len, m;
13511820Sjulian{
13611820Sjulian	register struct iftrace *t;
13711820Sjulian
13811820Sjulian	if (ifd->ifd_records == 0)
13911820Sjulian		return;
14011820Sjulian	t = ifd->ifd_front++;
14111820Sjulian	if (ifd->ifd_front >= ifd->ifd_records + NRECORDS)
14211820Sjulian		ifd->ifd_front = ifd->ifd_records;
14311820Sjulian	if (ifd->ifd_count < NRECORDS)
14411820Sjulian		ifd->ifd_count++;
14511820Sjulian	if (t->ift_size > 0 && t->ift_packet)
14611820Sjulian		free(t->ift_packet);
14711820Sjulian	t->ift_packet = 0;
14811820Sjulian	t->ift_stamp = time(0);
14911820Sjulian	t->ift_who = *who;
15011820Sjulian	if (len > 0) {
15111820Sjulian		t->ift_packet = malloc(len);
15211820Sjulian		if (t->ift_packet)
15311820Sjulian			bcopy(p, t->ift_packet, len);
15411820Sjulian		else
15511820Sjulian			len = 0;
15611820Sjulian	}
15711820Sjulian	t->ift_size = len;
15811820Sjulian	t->ift_metric = m;
15911820Sjulian}
16011820Sjulian
16111820Sjulianvoid
16211820Sjuliantraceaction(fd, action, rt)
16311820Sjulian	FILE *fd;
16411820Sjulian	char *action;
16511820Sjulian	struct rt_entry *rt;
16611820Sjulian{
16711820Sjulian	struct sockaddr_ipx *dst, *gate;
16811820Sjulian	static struct bits {
16911820Sjulian		int	t_bits;
17011820Sjulian		char	*t_name;
17111820Sjulian	} flagbits[] = {
17211820Sjulian		{ RTF_UP,	"UP" },
17311820Sjulian		{ RTF_GATEWAY,	"GATEWAY" },
17411820Sjulian		{ RTF_HOST,	"HOST" },
17511820Sjulian		{ 0 }
17611820Sjulian	}, statebits[] = {
17711820Sjulian		{ RTS_PASSIVE,	"PASSIVE" },
17811820Sjulian		{ RTS_REMOTE,	"REMOTE" },
17911820Sjulian		{ RTS_INTERFACE,"INTERFACE" },
18011820Sjulian		{ RTS_CHANGED,	"CHANGED" },
18111820Sjulian		{ 0 }
18211820Sjulian	};
18311820Sjulian	register struct bits *p;
18411820Sjulian	register int first;
18511820Sjulian	char *cp;
18611820Sjulian
18711820Sjulian	if (fd == NULL)
18811820Sjulian		return;
18911820Sjulian	fprintf(fd, "%s ", action);
19011820Sjulian	dst = (struct sockaddr_ipx *)&rt->rt_dst;
19111820Sjulian	gate = (struct sockaddr_ipx *)&rt->rt_router;
19211820Sjulian	fprintf(fd, "dst %s, ", ipxdp_ntoa(&dst->sipx_addr));
19311820Sjulian	fprintf(fd, "router %s, metric %d, ticks %d, flags",
19411820Sjulian	     ipxdp_ntoa(&gate->sipx_addr), rt->rt_metric, rt->rt_ticks);
19511820Sjulian	cp = " %s";
19611820Sjulian	for (first = 1, p = flagbits; p->t_bits > 0; p++) {
19711820Sjulian		if ((rt->rt_flags & p->t_bits) == 0)
19811820Sjulian			continue;
19911820Sjulian		fprintf(fd, cp, p->t_name);
20011820Sjulian		if (first) {
20111820Sjulian			cp = "|%s";
20211820Sjulian			first = 0;
20311820Sjulian		}
20411820Sjulian	}
20511820Sjulian	fprintf(fd, " state");
20611820Sjulian	cp = " %s";
20711820Sjulian	for (first = 1, p = statebits; p->t_bits > 0; p++) {
20811820Sjulian		if ((rt->rt_state & p->t_bits) == 0)
20911820Sjulian			continue;
21011820Sjulian		fprintf(fd, cp, p->t_name);
21111820Sjulian		if (first) {
21211820Sjulian			cp = "|%s";
21311820Sjulian			first = 0;
21411820Sjulian		}
21511820Sjulian	}
21611820Sjulian	putc('\n', fd);
21711820Sjulian	if (!tracepackets && (rt->rt_state & RTS_PASSIVE) == 0 && rt->rt_ifp)
21811820Sjulian		dumpif(fd, rt->rt_ifp);
21911820Sjulian	fflush(fd);
22011820Sjulian}
22111820Sjulian
22211820Sjulianvoid
22327244Sjhaytraceactionlog(action, rt)
22427244Sjhay	char *action;
22527244Sjhay	struct rt_entry *rt;
22627244Sjhay{
22727244Sjhay	struct sockaddr_ipx *dst, *gate;
22827244Sjhay	static struct bits {
22927244Sjhay		int	t_bits;
23027244Sjhay		char	*t_name;
23127244Sjhay	} flagbits[] = {
23227244Sjhay		{ RTF_UP,	"UP" },
23327244Sjhay		{ RTF_GATEWAY,	"GATEWAY" },
23427244Sjhay		{ RTF_HOST,	"HOST" },
23527244Sjhay		{ 0 }
23627244Sjhay	}, statebits[] = {
23727244Sjhay		{ RTS_PASSIVE,	"PASSIVE" },
23827244Sjhay		{ RTS_REMOTE,	"REMOTE" },
23927244Sjhay		{ RTS_INTERFACE,"INTERFACE" },
24027244Sjhay		{ RTS_CHANGED,	"CHANGED" },
24127244Sjhay		{ 0 }
24227244Sjhay	};
24327244Sjhay	register struct bits *p;
24427244Sjhay	register int first;
24527244Sjhay	char *cp;
24627244Sjhay	char *lstr, *olstr;
24727244Sjhay
24827244Sjhay	dst = (struct sockaddr_ipx *)&rt->rt_dst;
24927244Sjhay	gate = (struct sockaddr_ipx *)&rt->rt_router;
25027244Sjhay	asprintf(&lstr, "%s dst %s,", action, ipxdp_ntoa(&dst->sipx_addr));
25127244Sjhay	olstr = lstr;
25227244Sjhay	asprintf(&lstr, "%s router %s, metric %d, ticks %d, flags",
25327244Sjhay	     olstr, ipxdp_ntoa(&gate->sipx_addr), rt->rt_metric, rt->rt_ticks);
25427244Sjhay	free(olstr);
25527244Sjhay	olstr = lstr;
25627244Sjhay	cp = "%s %s";
25727244Sjhay	for (first = 1, p = flagbits; p->t_bits > 0; p++) {
25827244Sjhay		if ((rt->rt_flags & p->t_bits) == 0)
25927244Sjhay			continue;
26027244Sjhay		asprintf(&lstr, cp, olstr, p->t_name);
26127244Sjhay		free(olstr);
26227244Sjhay		olstr = lstr;
26327244Sjhay		if (first) {
26427244Sjhay			cp = "%s|%s";
26527244Sjhay			first = 0;
26627244Sjhay		}
26727244Sjhay	}
26827244Sjhay	asprintf(&lstr, "%s state", olstr);
26927244Sjhay	free(olstr);
27027244Sjhay	olstr = lstr;
27127244Sjhay	cp = "%s %s";
27227244Sjhay	for (first = 1, p = statebits; p->t_bits > 0; p++) {
27327244Sjhay		if ((rt->rt_state & p->t_bits) == 0)
27427244Sjhay			continue;
27527244Sjhay		asprintf(&lstr, cp, olstr, p->t_name);
27627244Sjhay		free(olstr);
27727244Sjhay		olstr = lstr;
27827244Sjhay		if (first) {
27927244Sjhay			cp = "%s|%s";
28027244Sjhay			first = 0;
28127244Sjhay		}
28227244Sjhay	}
28362984Skris	syslog(LOG_DEBUG, "%s", lstr);
28427244Sjhay	free(lstr);
28527244Sjhay}
28627244Sjhay
28727244Sjhayvoid
28827244Sjhaytracesapactionlog(action, sap)
28927244Sjhay	char *action;
29027244Sjhay	struct sap_entry *sap;
29127244Sjhay{
29227244Sjhay	syslog(LOG_DEBUG, "%-12.12s  service %04X %-20.20s "
29327244Sjhay		    "addr %s.%04X %c metric %d\n",
29427244Sjhay		     action,
29527244Sjhay		     ntohs(sap->sap.ServType),
29627244Sjhay		     sap->sap.ServName,
29727244Sjhay		     ipxdp_ntoa(&sap->sap.ipx),
29827244Sjhay		     ntohs(sap->sap.ipx.x_port),
29927244Sjhay		     (sap->clone ? 'C' : ' '),
30027244Sjhay		     ntohs(sap->sap.hops));
30127244Sjhay}
30227244Sjhay
30327244Sjhayvoid
30411820Sjuliandumpif(fd, ifp)
30511820Sjulian	register struct interface *ifp;
30611820Sjulian	FILE *fd;
30711820Sjulian{
30811820Sjulian	if (ifp->int_input.ifd_count || ifp->int_output.ifd_count) {
30911820Sjulian		fprintf(fd, "*** Packet history for interface %s ***\n",
31011820Sjulian			ifp->int_name);
31111820Sjulian		dumptrace(fd, "to", &ifp->int_output);
31211820Sjulian		dumptrace(fd, "from", &ifp->int_input);
31311820Sjulian		fprintf(fd, "*** end packet history ***\n");
31411820Sjulian	}
31511820Sjulian}
31611820Sjulian
31711820Sjulianvoid
31811820Sjuliandumptrace(fd, dir, ifd)
31911820Sjulian	FILE *fd;
32011820Sjulian	char *dir;
32111820Sjulian	register struct ifdebug *ifd;
32211820Sjulian{
32311820Sjulian	register struct iftrace *t;
32411820Sjulian	char *cp = !strcmp(dir, "to") ? "Output" : "Input";
32511820Sjulian
32611820Sjulian	if (ifd->ifd_front == ifd->ifd_records &&
32711820Sjulian	    ifd->ifd_front->ift_size == 0) {
32811820Sjulian		fprintf(fd, "%s: no packets.\n", cp);
32911820Sjulian		return;
33011820Sjulian	}
33111820Sjulian	fprintf(fd, "%s trace:\n", cp);
33211820Sjulian	t = ifd->ifd_front - ifd->ifd_count;
33311820Sjulian	if (t < ifd->ifd_records)
33411820Sjulian		t += NRECORDS;
33511820Sjulian	for ( ; ifd->ifd_count; ifd->ifd_count--, t++) {
33611820Sjulian		if (t >= ifd->ifd_records + NRECORDS)
33711820Sjulian			t = ifd->ifd_records;
33811820Sjulian		if (t->ift_size == 0)
33911820Sjulian			continue;
34011820Sjulian		fprintf(fd, "%.24s: metric=%d\n", ctime(&t->ift_stamp),
34111820Sjulian			t->ift_metric);
34211820Sjulian		dumppacket(fd, dir, &t->ift_who, t->ift_packet, t->ift_size);
34311820Sjulian	}
34411820Sjulian}
34511820Sjulian
34611820Sjulianvoid
34711820Sjuliandumppacket(fd, dir, source, cp, size)
34811820Sjulian	FILE *fd;
34911820Sjulian	char *dir;
35011820Sjulian	struct sockaddr *source;
35111820Sjulian	char *cp;
35211820Sjulian	register int size;
35311820Sjulian{
35411820Sjulian	register struct rip *msg = (struct rip *)cp;
35511820Sjulian	register struct netinfo *n;
35611820Sjulian	struct sockaddr_ipx *who = (struct sockaddr_ipx *)source;
35711820Sjulian
35811820Sjulian	if (msg->rip_cmd && ntohs(msg->rip_cmd) < RIPCMD_MAX)
35911820Sjulian		fprintf(fd, "%s %s %s#%x", ripcmds[ntohs(msg->rip_cmd)],
36011820Sjulian		    dir, ipxdp_ntoa(&who->sipx_addr),
36111820Sjulian		    ntohs(who->sipx_addr.x_port));
36211820Sjulian	else {
36311820Sjulian		fprintf(fd, "Bad cmd 0x%x %s %s#%x\n", ntohs(msg->rip_cmd),
36411820Sjulian		    dir, ipxdp_ntoa(&who->sipx_addr),
36511820Sjulian		    ntohs(who->sipx_addr.x_port));
366173709Sjb		fprintf(fd, "size=%d cp=%p packet=%p\n", size,
367173709Sjb			cp, packet);
36811820Sjulian		return;
36911820Sjulian	}
37011820Sjulian	switch (ntohs(msg->rip_cmd)) {
37111820Sjulian
37211820Sjulian	case RIPCMD_REQUEST:
37311820Sjulian	case RIPCMD_RESPONSE:
37411820Sjulian		fprintf(fd, ":\n");
37511820Sjulian		size -= sizeof (u_short);
37611820Sjulian		n = msg->rip_nets;
37711820Sjulian		for (; size > 0; n++, size -= sizeof (struct netinfo)) {
37811820Sjulian			if (size < sizeof (struct netinfo))
37911820Sjulian				break;
38011820Sjulian			fprintf(fd, "\tnet %s metric %d ticks %d\n",
38111820Sjulian			     ipxdp_nettoa(n->rip_dst),
38211820Sjulian			     ntohs(n->rip_metric),
38311820Sjulian			     ntohs(n->rip_ticks));
38411820Sjulian		}
38511820Sjulian		break;
38611820Sjulian
38711820Sjulian	}
38811820Sjulian}
38911820Sjulian
39011820Sjulianvoid
39111820Sjuliandumpsappacket(fd, dir, source, cp, size)
39211820Sjulian	FILE *fd;
39311820Sjulian	char *dir;
39411820Sjulian	struct sockaddr *source;
39511820Sjulian	char *cp;
39611820Sjulian	register int size;
39711820Sjulian{
39811820Sjulian	register struct sap_packet *msg = (struct sap_packet *)cp;
39911820Sjulian	register struct sap_info *n;
40011820Sjulian	struct sockaddr_ipx *who = (struct sockaddr_ipx *)source;
40111820Sjulian
40211820Sjulian	if (msg->sap_cmd && ntohs(msg->sap_cmd) < SAPCMD_MAX)
40311820Sjulian		fprintf(fd, "%s %s %s#%x", sapcmds[ntohs(msg->sap_cmd)],
40411820Sjulian		    dir, ipxdp_ntoa(&who->sipx_addr),
40511820Sjulian		    ntohs(who->sipx_addr.x_port));
40611820Sjulian	else {
40711820Sjulian		fprintf(fd, "Bad cmd 0x%x %s %s#%x\n", ntohs(msg->sap_cmd),
40811820Sjulian		    dir, ipxdp_ntoa(&who->sipx_addr),
40911820Sjulian		    ntohs(who->sipx_addr.x_port));
410173709Sjb		fprintf(fd, "size=%d cp=%p packet=%p\n", size,
411173709Sjb			cp, packet);
41211820Sjulian		return;
41311820Sjulian	}
41411820Sjulian	switch (ntohs(msg->sap_cmd)) {
41511820Sjulian
41611820Sjulian	case SAP_REQ:
41711820Sjulian	case SAP_RESP:
41811820Sjulian	case SAP_REQ_NEAR:
41911820Sjulian	case SAP_RESP_NEAR:
42011820Sjulian		fprintf(fd, ":\n");
42111820Sjulian		size -= sizeof (u_short);
42211820Sjulian		n = msg->sap;
42311820Sjulian		for (; size > 0; n++, size -= sizeof (struct sap_info)) {
42411820Sjulian			if (size < sizeof (struct sap_info))
42511820Sjulian				break;
42611820Sjulian			fprintf(fd, "  service %04X %-20.20s "
42711820Sjulian				    "addr %s.%04X metric %d\n",
42811820Sjulian			     ntohs(n->ServType),
42911820Sjulian			     n->ServName,
43011820Sjulian			     ipxdp_ntoa(&n->ipx),
43111820Sjulian			     ntohs(n->ipx.x_port),
43211820Sjulian			     ntohs(n->hops));
43311820Sjulian		}
43411820Sjulian		break;
43511820Sjulian
43611820Sjulian	}
43711820Sjulian}
43811820Sjulian
43911820Sjulianvoid
44011820Sjuliandumpsaptable(fd, sh)
44111820Sjulian	FILE *fd;
44211820Sjulian	struct sap_hash *sh;
44311820Sjulian{
44411820Sjulian	register struct sap_entry *sap;
44511820Sjulian	struct sap_hash *hash;
44611820Sjulian	int x = 0;
44711820Sjulian
44811820Sjulian	fprintf(fd, "------- SAP table dump. -------\n");
44911820Sjulian	for (hash = sh; hash < &sh[SAPHASHSIZ]; hash++, x++) {
45011820Sjulian		fprintf(fd, "HASH %d\n", x);
45111820Sjulian		sap = hash->forw;
45211820Sjulian		for (; sap != (struct sap_entry *)hash; sap = sap->forw) {
45311820Sjulian			fprintf(fd, "  service %04X %-20.20s "
45411820Sjulian				    "addr %s.%04X %c metric %d\n",
45511820Sjulian				     ntohs(sap->sap.ServType),
45611820Sjulian				     sap->sap.ServName,
45711820Sjulian				     ipxdp_ntoa(&sap->sap.ipx),
45811820Sjulian				     ntohs(sap->sap.ipx.x_port),
45911820Sjulian				     (sap->clone ? 'C' : ' '),
46011820Sjulian				     ntohs(sap->sap.hops));
46111820Sjulian		}
46211820Sjulian	}
46311820Sjulian	fprintf(fd, "\n");
46411820Sjulian}
46511820Sjulian
46615248Sjhayvoid
46715248Sjhaydumpriptable(fd)
46815248Sjhay	FILE *fd;
46915248Sjhay{
47015248Sjhay	register struct rt_entry *rip;
47115248Sjhay	struct rthash *hash;
47215248Sjhay	int x;
47315248Sjhay	struct rthash *rh = nethash;
47415248Sjhay
47515248Sjhay	fprintf(fd, "------- RIP table dump. -------\n");
47615248Sjhay	x = 0;
47715248Sjhay	fprintf(fd, "Network table.\n");
47815248Sjhay
47915248Sjhay	for (hash = rh; hash < &rh[ROUTEHASHSIZ]; hash++, x++) {
48015248Sjhay		fprintf(fd, "HASH %d\n", x);
48115248Sjhay		rip = hash->rt_forw;
48215248Sjhay		for (; rip != (struct rt_entry *)hash; rip = rip->rt_forw) {
48315248Sjhay			fprintf(fd, "  dest %s\t",
48415248Sjhay				ipxdp_ntoa(&satoipx_addr(rip->rt_dst)));
48515248Sjhay			fprintf(fd, "%s metric %d, ticks %d\n",
48615248Sjhay				ipxdp_ntoa(&satoipx_addr(rip->rt_router)),
48715248Sjhay				rip->rt_metric,
48815248Sjhay				rip->rt_ticks);
48915248Sjhay		}
49015248Sjhay	}
49115248Sjhay	fprintf(fd, "\n");
49215248Sjhay}
49315248Sjhay
49411820Sjulianunion ipx_net_u net;
49511820Sjulian
49611820Sjulianchar *
49711820Sjulianipxdp_nettoa(val)
49811820Sjulianunion ipx_net val;
49911820Sjulian{
50011820Sjulian	static char buf[100];
50111820Sjulian	net.net_e = val;
502122760Strhodes	(void)sprintf(buf, "%u", ntohl(net.long_e));
50311820Sjulian	return (buf);
50411820Sjulian}
50511820Sjulian
50611820Sjulian
50711820Sjulianchar *
50811820Sjulianipxdp_ntoa(addr)
50911820Sjulianstruct ipx_addr *addr;
51011820Sjulian{
51111820Sjulian    static char buf[100];
51211820Sjulian
51311820Sjulian    (void)sprintf(buf, "%s#%x:%x:%x:%x:%x:%x",
51411820Sjulian	ipxdp_nettoa(addr->x_net),
51511820Sjulian	addr->x_host.c_host[0], addr->x_host.c_host[1],
51611820Sjulian	addr->x_host.c_host[2], addr->x_host.c_host[3],
51711820Sjulian	addr->x_host.c_host[4], addr->x_host.c_host[5]);
51811820Sjulian
51911820Sjulian    return(buf);
52011820Sjulian}
521