print-igrp.c revision 17680
117680Spst/*
217680Spst * Copyright (c) 1996
317680Spst *	The Regents of the University of California.  All rights reserved.
417680Spst *
517680Spst * Redistribution and use in source and binary forms, with or without
617680Spst * modification, are permitted provided that: (1) source code distributions
717680Spst * retain the above copyright notice and this paragraph in its entirety, (2)
817680Spst * distributions including binary code include the above copyright notice and
917680Spst * this paragraph in its entirety in the documentation or other materials
1017680Spst * provided with the distribution, and (3) all advertising materials mentioning
1117680Spst * features or use of this software display the following acknowledgement:
1217680Spst * ``This product includes software developed by the University of California,
1317680Spst * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1417680Spst * the University nor the names of its contributors may be used to endorse
1517680Spst * or promote products derived from this software without specific prior
1617680Spst * written permission.
1717680Spst * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1817680Spst * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1917680Spst * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2017680Spst *
2117680Spst * Initial contribution from Francis Dupont (francis.dupont@inria.fr)
2217680Spst */
2317680Spst
2417680Spst#ifndef lint
2517680Spststatic char rcsid[] =
2617680Spst"@(#) $Header: print-igrp.c,v 1.4 96/07/23 14:04:55 leres Exp $ (LBL)";
2717680Spst#endif
2817680Spst
2917680Spst#include <sys/param.h>
3017680Spst#include <sys/socket.h>
3117680Spst
3217680Spst#include <netinet/in.h>
3317680Spst#include <netinet/in_systm.h>
3417680Spst#include <netinet/ip.h>
3517680Spst#include <netinet/ip_var.h>
3617680Spst#include <netinet/udp.h>
3717680Spst#include <netinet/udp_var.h>
3817680Spst
3917680Spst#include <errno.h>
4017680Spst#include <stdio.h>
4117680Spst
4217680Spst#include "addrtoname.h"
4317680Spst#include "interface.h"
4417680Spst#include "igrp.h"
4517680Spst#include "extract.h"			/* must come after interface.h */
4617680Spst
4717680Spststatic void
4817680Spstigrp_entry_print(register struct igrprte *igr, register int is_interior,
4917680Spst    register int is_exterior)
5017680Spst{
5117680Spst	register u_int delay, bandwidth;
5217680Spst	u_int metric, mtu;
5317680Spst
5417680Spst	if (is_interior)
5517680Spst		printf(" *.%d.%d.%d", igr->igr_net[0],
5617680Spst		    igr->igr_net[1], igr->igr_net[2]);
5717680Spst	else if (is_exterior)
5817680Spst		printf(" X%d.%d.%d.0", igr->igr_net[0],
5917680Spst		    igr->igr_net[1], igr->igr_net[2]);
6017680Spst	else
6117680Spst		printf(" %d.%d.%d.0", igr->igr_net[0],
6217680Spst		    igr->igr_net[1], igr->igr_net[2]);
6317680Spst
6417680Spst	delay = EXTRACT_24BITS(igr->igr_dly);
6517680Spst	bandwidth = EXTRACT_24BITS(igr->igr_bw);
6617680Spst	metric = bandwidth + delay;
6717680Spst	if (metric > 0xffffff)
6817680Spst		metric = 0xffffff;
6917680Spst	mtu = EXTRACT_16BITS(igr->igr_mtu);
7017680Spst
7117680Spst	printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops",
7217680Spst	    10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
7317680Spst	    igr->igr_rel, igr->igr_ld, metric,
7417680Spst	    mtu, igr->igr_hct);
7517680Spst}
7617680Spst
7717680Spststatic struct tok op2str[] = {
7817680Spst	{ IGRP_UPDATE,		"update" },
7917680Spst	{ IGRP_REQUEST,		"request" },
8017680Spst	{ 0,			NULL }
8117680Spst};
8217680Spst
8317680Spstvoid
8417680Spstigrp_print(register const u_char *bp, u_int length, register const u_char *bp2)
8517680Spst{
8617680Spst	register struct igrphdr *hdr;
8717680Spst	register struct ip *ip;
8817680Spst	register u_char *cp;
8917680Spst	u_int nint, nsys, next;
9017680Spst
9117680Spst	hdr = (struct igrphdr *)bp;
9217680Spst	ip = (struct ip *)bp2;
9317680Spst	cp = (u_char *)(hdr + 1);
9417680Spst        (void)printf("%s > %s: igrp: ",
9517680Spst	    ipaddr_string(&ip->ip_src),
9617680Spst	    ipaddr_string(&ip->ip_dst));
9717680Spst
9817680Spst	/* Header */
9917680Spst	TCHECK(*hdr);
10017680Spst	nint = EXTRACT_16BITS(&hdr->ig_ni);
10117680Spst	nsys = EXTRACT_16BITS(&hdr->ig_ns);
10217680Spst	next = EXTRACT_16BITS(&hdr->ig_nx);
10317680Spst
10417680Spst	(void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)",
10517680Spst	    tok2str(op2str, "op-#%d", hdr->ig_op),
10617680Spst	    hdr->ig_v,
10717680Spst	    hdr->ig_ed,
10817680Spst	    EXTRACT_16BITS(&hdr->ig_as),
10917680Spst	    nint,
11017680Spst	    nsys,
11117680Spst	    next);
11217680Spst
11317680Spst	length -= sizeof(*hdr);
11417680Spst	while (length >= IGRP_RTE_SIZE) {
11517680Spst		if (nint > 0) {
11617680Spst			TCHECK2(*cp, IGRP_RTE_SIZE);
11717680Spst			igrp_entry_print((struct igrprte *)cp, 1, 0);
11817680Spst			--nint;
11917680Spst		} else if (nsys > 0) {
12017680Spst			TCHECK2(*cp, IGRP_RTE_SIZE);
12117680Spst			igrp_entry_print((struct igrprte *)cp, 0, 0);
12217680Spst			--nsys;
12317680Spst		} else if (next > 0) {
12417680Spst			TCHECK2(*cp, IGRP_RTE_SIZE);
12517680Spst			igrp_entry_print((struct igrprte *)cp, 0, 1);
12617680Spst			--next;
12717680Spst		} else {
12817680Spst			(void)printf("[extra bytes %d]", length);
12917680Spst			break;
13017680Spst		}
13117680Spst		cp += IGRP_RTE_SIZE;
13217680Spst		length -= IGRP_RTE_SIZE;
13317680Spst	}
13417680Spst	if (nint == 0 && nsys == 0 && next == 0)
13517680Spst		return;
13617680Spsttrunc:
13717680Spst	fputs("[|igrp]", stdout);
13817680Spst}
139