117680Spst/* 239297Sfenner * Copyright (c) 1996, 1997 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 25127668Sbmsstatic const char rcsid[] _U_ = 26190207Srpaulo "@(#) $Header: /tcpdump/master/tcpdump/print-igrp.c,v 1.21 2005-04-20 21:01:56 guy Exp $ (LBL)"; 2717680Spst#endif 2817680Spst 2956893Sfenner#ifdef HAVE_CONFIG_H 3056893Sfenner#include "config.h" 3156893Sfenner#endif 3256893Sfenner 33127668Sbms#include <tcpdump-stdinc.h> 3417680Spst 3517680Spst#include <stdio.h> 3617680Spst 3739297Sfenner#include "interface.h" 3817680Spst#include "addrtoname.h" 3917680Spst#include "igrp.h" 4075115Sfenner#include "ip.h" 4117680Spst#include "extract.h" /* must come after interface.h */ 4217680Spst 4317680Spststatic void 4417680Spstigrp_entry_print(register struct igrprte *igr, register int is_interior, 4517680Spst register int is_exterior) 4617680Spst{ 4717680Spst register u_int delay, bandwidth; 4817680Spst u_int metric, mtu; 4917680Spst 5017680Spst if (is_interior) 5117680Spst printf(" *.%d.%d.%d", igr->igr_net[0], 5217680Spst igr->igr_net[1], igr->igr_net[2]); 5317680Spst else if (is_exterior) 5417680Spst printf(" X%d.%d.%d.0", igr->igr_net[0], 5517680Spst igr->igr_net[1], igr->igr_net[2]); 5617680Spst else 5717680Spst printf(" %d.%d.%d.0", igr->igr_net[0], 5817680Spst igr->igr_net[1], igr->igr_net[2]); 5917680Spst 6017680Spst delay = EXTRACT_24BITS(igr->igr_dly); 6117680Spst bandwidth = EXTRACT_24BITS(igr->igr_bw); 6217680Spst metric = bandwidth + delay; 6317680Spst if (metric > 0xffffff) 6417680Spst metric = 0xffffff; 6517680Spst mtu = EXTRACT_16BITS(igr->igr_mtu); 6617680Spst 6717680Spst printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops", 6817680Spst 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth, 6917680Spst igr->igr_rel, igr->igr_ld, metric, 7017680Spst mtu, igr->igr_hct); 7117680Spst} 7217680Spst 7317680Spststatic struct tok op2str[] = { 7417680Spst { IGRP_UPDATE, "update" }, 7517680Spst { IGRP_REQUEST, "request" }, 7617680Spst { 0, NULL } 7717680Spst}; 7817680Spst 7917680Spstvoid 80147899Ssamigrp_print(register const u_char *bp, u_int length, const u_char *bp2 _U_) 8117680Spst{ 8217680Spst register struct igrphdr *hdr; 8317680Spst register u_char *cp; 8417680Spst u_int nint, nsys, next; 8517680Spst 8617680Spst hdr = (struct igrphdr *)bp; 8717680Spst cp = (u_char *)(hdr + 1); 8898524Sfenner (void)printf("igrp:"); 8917680Spst 9017680Spst /* Header */ 9117680Spst TCHECK(*hdr); 9217680Spst nint = EXTRACT_16BITS(&hdr->ig_ni); 9317680Spst nsys = EXTRACT_16BITS(&hdr->ig_ns); 9417680Spst next = EXTRACT_16BITS(&hdr->ig_nx); 9517680Spst 9617680Spst (void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)", 9775115Sfenner tok2str(op2str, "op-#%d", IGRP_OP(hdr->ig_vop)), 9875115Sfenner IGRP_V(hdr->ig_vop), 9917680Spst hdr->ig_ed, 10017680Spst EXTRACT_16BITS(&hdr->ig_as), 10117680Spst nint, 10217680Spst nsys, 10317680Spst next); 10417680Spst 10517680Spst length -= sizeof(*hdr); 10617680Spst while (length >= IGRP_RTE_SIZE) { 10717680Spst if (nint > 0) { 10817680Spst TCHECK2(*cp, IGRP_RTE_SIZE); 10917680Spst igrp_entry_print((struct igrprte *)cp, 1, 0); 11017680Spst --nint; 11117680Spst } else if (nsys > 0) { 11217680Spst TCHECK2(*cp, IGRP_RTE_SIZE); 11317680Spst igrp_entry_print((struct igrprte *)cp, 0, 0); 11417680Spst --nsys; 11517680Spst } else if (next > 0) { 11617680Spst TCHECK2(*cp, IGRP_RTE_SIZE); 11717680Spst igrp_entry_print((struct igrprte *)cp, 0, 1); 11817680Spst --next; 11917680Spst } else { 12098524Sfenner (void)printf(" [extra bytes %d]", length); 12117680Spst break; 12217680Spst } 12317680Spst cp += IGRP_RTE_SIZE; 12417680Spst length -= IGRP_RTE_SIZE; 12517680Spst } 12617680Spst if (nint == 0 && nsys == 0 && next == 0) 12717680Spst return; 12817680Spsttrunc: 12998524Sfenner fputs(" [|igrp]", stdout); 13017680Spst} 131