print-igrp.c revision 98524
1164190Sjkoshy/*
2164190Sjkoshy * Copyright (c) 1996, 1997
3164190Sjkoshy *	The Regents of the University of California.  All rights reserved.
4164190Sjkoshy *
5164190Sjkoshy * Redistribution and use in source and binary forms, with or without
6164190Sjkoshy * modification, are permitted provided that: (1) source code distributions
7164190Sjkoshy * retain the above copyright notice and this paragraph in its entirety, (2)
8164190Sjkoshy * distributions including binary code include the above copyright notice and
9164190Sjkoshy * this paragraph in its entirety in the documentation or other materials
10164190Sjkoshy * provided with the distribution, and (3) all advertising materials mentioning
11164190Sjkoshy * features or use of this software display the following acknowledgement:
12164190Sjkoshy * ``This product includes software developed by the University of California,
13164190Sjkoshy * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14164190Sjkoshy * the University nor the names of its contributors may be used to endorse
15164190Sjkoshy * or promote products derived from this software without specific prior
16164190Sjkoshy * written permission.
17164190Sjkoshy * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18164190Sjkoshy * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19164190Sjkoshy * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20164190Sjkoshy *
21164190Sjkoshy * Initial contribution from Francis Dupont (francis.dupont@inria.fr)
22164190Sjkoshy */
23164190Sjkoshy
24164190Sjkoshy#ifndef lint
25164190Sjkoshystatic const char rcsid[] =
26164190Sjkoshy    "@(#) $Header: /tcpdump/master/tcpdump/print-igrp.c,v 1.16 2001/06/15 22:17:32 fenner Exp $ (LBL)";
27164190Sjkoshy#endif
28164190Sjkoshy
29164190Sjkoshy#ifdef HAVE_CONFIG_H
30164190Sjkoshy#include "config.h"
31164190Sjkoshy#endif
32164190Sjkoshy
33164190Sjkoshy#include <sys/param.h>
34164190Sjkoshy#include <sys/types.h>			/* concession to AIX */
35164190Sjkoshy#include <sys/socket.h>
36164190Sjkoshy
37164190Sjkoshy#include <netinet/in.h>
38164190Sjkoshy
39164190Sjkoshy#include <errno.h>
40164190Sjkoshy#include <stdio.h>
41164190Sjkoshy
42164190Sjkoshy#include "interface.h"
43164190Sjkoshy#include "addrtoname.h"
44164190Sjkoshy#include "igrp.h"
45164190Sjkoshy#include "ip.h"
46164190Sjkoshy#include "extract.h"			/* must come after interface.h */
47164190Sjkoshy
48164190Sjkoshystatic void
49164190Sjkoshyigrp_entry_print(register struct igrprte *igr, register int is_interior,
50164190Sjkoshy    register int is_exterior)
51164190Sjkoshy{
52164190Sjkoshy	register u_int delay, bandwidth;
53164190Sjkoshy	u_int metric, mtu;
54164190Sjkoshy
55164190Sjkoshy	if (is_interior)
56164190Sjkoshy		printf(" *.%d.%d.%d", igr->igr_net[0],
57164190Sjkoshy		    igr->igr_net[1], igr->igr_net[2]);
58164190Sjkoshy	else if (is_exterior)
59		printf(" X%d.%d.%d.0", igr->igr_net[0],
60		    igr->igr_net[1], igr->igr_net[2]);
61	else
62		printf(" %d.%d.%d.0", igr->igr_net[0],
63		    igr->igr_net[1], igr->igr_net[2]);
64
65	delay = EXTRACT_24BITS(igr->igr_dly);
66	bandwidth = EXTRACT_24BITS(igr->igr_bw);
67	metric = bandwidth + delay;
68	if (metric > 0xffffff)
69		metric = 0xffffff;
70	mtu = EXTRACT_16BITS(igr->igr_mtu);
71
72	printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops",
73	    10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
74	    igr->igr_rel, igr->igr_ld, metric,
75	    mtu, igr->igr_hct);
76}
77
78static struct tok op2str[] = {
79	{ IGRP_UPDATE,		"update" },
80	{ IGRP_REQUEST,		"request" },
81	{ 0,			NULL }
82};
83
84void
85igrp_print(register const u_char *bp, u_int length, register const u_char *bp2)
86{
87	register struct igrphdr *hdr;
88	register struct ip *ip;
89	register u_char *cp;
90	u_int nint, nsys, next;
91
92	hdr = (struct igrphdr *)bp;
93	ip = (struct ip *)bp2;
94	cp = (u_char *)(hdr + 1);
95        (void)printf("igrp:");
96
97	/* Header */
98	TCHECK(*hdr);
99	nint = EXTRACT_16BITS(&hdr->ig_ni);
100	nsys = EXTRACT_16BITS(&hdr->ig_ns);
101	next = EXTRACT_16BITS(&hdr->ig_nx);
102
103	(void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)",
104	    tok2str(op2str, "op-#%d", IGRP_OP(hdr->ig_vop)),
105	    IGRP_V(hdr->ig_vop),
106	    hdr->ig_ed,
107	    EXTRACT_16BITS(&hdr->ig_as),
108	    nint,
109	    nsys,
110	    next);
111
112	length -= sizeof(*hdr);
113	while (length >= IGRP_RTE_SIZE) {
114		if (nint > 0) {
115			TCHECK2(*cp, IGRP_RTE_SIZE);
116			igrp_entry_print((struct igrprte *)cp, 1, 0);
117			--nint;
118		} else if (nsys > 0) {
119			TCHECK2(*cp, IGRP_RTE_SIZE);
120			igrp_entry_print((struct igrprte *)cp, 0, 0);
121			--nsys;
122		} else if (next > 0) {
123			TCHECK2(*cp, IGRP_RTE_SIZE);
124			igrp_entry_print((struct igrprte *)cp, 0, 1);
125			--next;
126		} else {
127			(void)printf(" [extra bytes %d]", length);
128			break;
129		}
130		cp += IGRP_RTE_SIZE;
131		length -= IGRP_RTE_SIZE;
132	}
133	if (nint == 0 && nsys == 0 && next == 0)
134		return;
135trunc:
136	fputs(" [|igrp]", stdout);
137}
138