print-igrp.c revision 56893
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 2526180Sfennerstatic const char rcsid[] = 2656893Sfenner "@(#) $Header: /tcpdump/master/tcpdump/print-igrp.c,v 1.11 1999/11/21 09:36:53 fenner Exp $ (LBL)"; 2717680Spst#endif 2817680Spst 2956893Sfenner#ifdef HAVE_CONFIG_H 3056893Sfenner#include "config.h" 3156893Sfenner#endif 3256893Sfenner 3317680Spst#include <sys/param.h> 3439297Sfenner#include <sys/types.h> /* concession to AIX */ 3517680Spst#include <sys/socket.h> 3617680Spst 3717680Spst#include <netinet/in.h> 3817680Spst#include <netinet/in_systm.h> 3917680Spst#include <netinet/ip.h> 4017680Spst#include <netinet/ip_var.h> 4117680Spst#include <netinet/udp.h> 4217680Spst#include <netinet/udp_var.h> 4317680Spst 4417680Spst#include <errno.h> 4517680Spst#include <stdio.h> 4617680Spst 4739297Sfenner#include "interface.h" 4817680Spst#include "addrtoname.h" 4917680Spst#include "igrp.h" 5017680Spst#include "extract.h" /* must come after interface.h */ 5117680Spst 5217680Spststatic void 5317680Spstigrp_entry_print(register struct igrprte *igr, register int is_interior, 5417680Spst register int is_exterior) 5517680Spst{ 5617680Spst register u_int delay, bandwidth; 5717680Spst u_int metric, mtu; 5817680Spst 5917680Spst if (is_interior) 6017680Spst printf(" *.%d.%d.%d", igr->igr_net[0], 6117680Spst igr->igr_net[1], igr->igr_net[2]); 6217680Spst else if (is_exterior) 6317680Spst printf(" X%d.%d.%d.0", igr->igr_net[0], 6417680Spst igr->igr_net[1], igr->igr_net[2]); 6517680Spst else 6617680Spst printf(" %d.%d.%d.0", igr->igr_net[0], 6717680Spst igr->igr_net[1], igr->igr_net[2]); 6817680Spst 6917680Spst delay = EXTRACT_24BITS(igr->igr_dly); 7017680Spst bandwidth = EXTRACT_24BITS(igr->igr_bw); 7117680Spst metric = bandwidth + delay; 7217680Spst if (metric > 0xffffff) 7317680Spst metric = 0xffffff; 7417680Spst mtu = EXTRACT_16BITS(igr->igr_mtu); 7517680Spst 7617680Spst printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops", 7717680Spst 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth, 7817680Spst igr->igr_rel, igr->igr_ld, metric, 7917680Spst mtu, igr->igr_hct); 8017680Spst} 8117680Spst 8217680Spststatic struct tok op2str[] = { 8317680Spst { IGRP_UPDATE, "update" }, 8417680Spst { IGRP_REQUEST, "request" }, 8517680Spst { 0, NULL } 8617680Spst}; 8717680Spst 8817680Spstvoid 8917680Spstigrp_print(register const u_char *bp, u_int length, register const u_char *bp2) 9017680Spst{ 9117680Spst register struct igrphdr *hdr; 9217680Spst register struct ip *ip; 9317680Spst register u_char *cp; 9417680Spst u_int nint, nsys, next; 9517680Spst 9617680Spst hdr = (struct igrphdr *)bp; 9717680Spst ip = (struct ip *)bp2; 9817680Spst cp = (u_char *)(hdr + 1); 9917680Spst (void)printf("%s > %s: igrp: ", 10017680Spst ipaddr_string(&ip->ip_src), 10117680Spst ipaddr_string(&ip->ip_dst)); 10217680Spst 10317680Spst /* Header */ 10417680Spst TCHECK(*hdr); 10517680Spst nint = EXTRACT_16BITS(&hdr->ig_ni); 10617680Spst nsys = EXTRACT_16BITS(&hdr->ig_ns); 10717680Spst next = EXTRACT_16BITS(&hdr->ig_nx); 10817680Spst 10917680Spst (void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)", 11017680Spst tok2str(op2str, "op-#%d", hdr->ig_op), 11117680Spst hdr->ig_v, 11217680Spst hdr->ig_ed, 11317680Spst EXTRACT_16BITS(&hdr->ig_as), 11417680Spst nint, 11517680Spst nsys, 11617680Spst next); 11717680Spst 11817680Spst length -= sizeof(*hdr); 11917680Spst while (length >= IGRP_RTE_SIZE) { 12017680Spst if (nint > 0) { 12117680Spst TCHECK2(*cp, IGRP_RTE_SIZE); 12217680Spst igrp_entry_print((struct igrprte *)cp, 1, 0); 12317680Spst --nint; 12417680Spst } else if (nsys > 0) { 12517680Spst TCHECK2(*cp, IGRP_RTE_SIZE); 12617680Spst igrp_entry_print((struct igrprte *)cp, 0, 0); 12717680Spst --nsys; 12817680Spst } else if (next > 0) { 12917680Spst TCHECK2(*cp, IGRP_RTE_SIZE); 13017680Spst igrp_entry_print((struct igrprte *)cp, 0, 1); 13117680Spst --next; 13217680Spst } else { 13317680Spst (void)printf("[extra bytes %d]", length); 13417680Spst break; 13517680Spst } 13617680Spst cp += IGRP_RTE_SIZE; 13717680Spst length -= IGRP_RTE_SIZE; 13817680Spst } 13917680Spst if (nint == 0 && nsys == 0 && next == 0) 14017680Spst return; 14117680Spsttrunc: 14217680Spst fputs("[|igrp]", stdout); 14317680Spst} 144