12949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project/* 22949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * Copyright (c) 1996, 1997 32949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * The Regents of the University of California. All rights reserved. 42949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * 52949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * Redistribution and use in source and binary forms, with or without 62949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * modification, are permitted provided that: (1) source code distributions 72949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * retain the above copyright notice and this paragraph in its entirety, (2) 82949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * distributions including binary code include the above copyright notice and 92949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * this paragraph in its entirety in the documentation or other materials 102949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * provided with the distribution, and (3) all advertising materials mentioning 112949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * features or use of this software display the following acknowledgement: 122949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * ``This product includes software developed by the University of California, 132949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 142949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * the University nor the names of its contributors may be used to endorse 152949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * or promote products derived from this software without specific prior 162949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * written permission. 172949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 182949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 192949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 202949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * 212949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project * Initial contribution from Francis Dupont (francis.dupont@inria.fr) 222949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project */ 232949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 242949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#ifndef lint 252949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Projectstatic const char rcsid[] _U_ = 262949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project "@(#) $Header: /tcpdump/master/tcpdump/print-igrp.c,v 1.20.2.1 2005/04/20 21:02:15 guy Exp $ (LBL)"; 272949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#endif 282949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 292949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#ifdef HAVE_CONFIG_H 302949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include "config.h" 312949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#endif 322949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 332949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include <tcpdump-stdinc.h> 342949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 352949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include <stdio.h> 362949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 372949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include "interface.h" 382949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include "addrtoname.h" 392949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include "igrp.h" 402949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include "ip.h" 412949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include "extract.h" /* must come after interface.h */ 422949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 432949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Projectstatic void 442949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Projectigrp_entry_print(register struct igrprte *igr, register int is_interior, 452949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project register int is_exterior) 462949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project{ 472949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project register u_int delay, bandwidth; 482949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project u_int metric, mtu; 492949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 502949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project if (is_interior) 512949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project printf(" *.%d.%d.%d", igr->igr_net[0], 522949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project igr->igr_net[1], igr->igr_net[2]); 532949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project else if (is_exterior) 542949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project printf(" X%d.%d.%d.0", igr->igr_net[0], 552949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project igr->igr_net[1], igr->igr_net[2]); 562949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project else 572949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project printf(" %d.%d.%d.0", igr->igr_net[0], 582949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project igr->igr_net[1], igr->igr_net[2]); 592949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 602949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project delay = EXTRACT_24BITS(igr->igr_dly); 612949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project bandwidth = EXTRACT_24BITS(igr->igr_bw); 622949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project metric = bandwidth + delay; 632949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project if (metric > 0xffffff) 642949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project metric = 0xffffff; 652949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project mtu = EXTRACT_16BITS(igr->igr_mtu); 662949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 672949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops", 682949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth, 692949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project igr->igr_rel, igr->igr_ld, metric, 702949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project mtu, igr->igr_hct); 712949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project} 722949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 732949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Projectstatic struct tok op2str[] = { 742949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project { IGRP_UPDATE, "update" }, 752949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project { IGRP_REQUEST, "request" }, 762949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project { 0, NULL } 772949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project}; 782949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 792949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Projectvoid 802949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Projectigrp_print(register const u_char *bp, u_int length, const u_char *bp2 _U_) 812949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project{ 822949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project register struct igrphdr *hdr; 832949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project register u_char *cp; 842949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project u_int nint, nsys, next; 852949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 862949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project hdr = (struct igrphdr *)bp; 872949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project cp = (u_char *)(hdr + 1); 882949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project (void)printf("igrp:"); 892949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 902949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project /* Header */ 912949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project TCHECK(*hdr); 922949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project nint = EXTRACT_16BITS(&hdr->ig_ni); 932949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project nsys = EXTRACT_16BITS(&hdr->ig_ns); 942949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project next = EXTRACT_16BITS(&hdr->ig_nx); 952949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 962949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project (void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)", 972949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project tok2str(op2str, "op-#%d", IGRP_OP(hdr->ig_vop)), 982949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project IGRP_V(hdr->ig_vop), 992949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project hdr->ig_ed, 1002949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project EXTRACT_16BITS(&hdr->ig_as), 1012949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project nint, 1022949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project nsys, 1032949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project next); 1042949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project 1052949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project length -= sizeof(*hdr); 1062949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project while (length >= IGRP_RTE_SIZE) { 1072949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project if (nint > 0) { 1082949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project TCHECK2(*cp, IGRP_RTE_SIZE); 1092949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project igrp_entry_print((struct igrprte *)cp, 1, 0); 1102949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project --nint; 1112949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project } else if (nsys > 0) { 1122949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project TCHECK2(*cp, IGRP_RTE_SIZE); 1132949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project igrp_entry_print((struct igrprte *)cp, 0, 0); 1142949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project --nsys; 1152949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project } else if (next > 0) { 1162949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project TCHECK2(*cp, IGRP_RTE_SIZE); 1172949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project igrp_entry_print((struct igrprte *)cp, 0, 1); 1182949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project --next; 1192949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project } else { 1202949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project (void)printf(" [extra bytes %d]", length); 1212949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project break; 1222949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project } 1232949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project cp += IGRP_RTE_SIZE; 1242949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project length -= IGRP_RTE_SIZE; 1252949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project } 1262949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project if (nint == 0 && nsys == 0 && next == 0) 1272949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project return; 1282949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Projecttrunc: 1292949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project fputs(" [|igrp]", stdout); 1302949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project} 131