mcr | f555c16 | 1999-10-07 23:47:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1996, 1997 |
| 3 | * The Regents of the University of California. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that: (1) source code distributions |
| 7 | * retain the above copyright notice and this paragraph in its entirety, (2) |
| 8 | * distributions including binary code include the above copyright notice and |
| 9 | * this paragraph in its entirety in the documentation or other materials |
| 10 | * provided with the distribution, and (3) all advertising materials mentioning |
| 11 | * features or use of this software display the following acknowledgement: |
| 12 | * ``This product includes software developed by the University of California, |
| 13 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of |
| 14 | * the University nor the names of its contributors may be used to endorse |
| 15 | * or promote products derived from this software without specific prior |
| 16 | * written permission. |
| 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 20 | * |
| 21 | * Initial contribution from Francis Dupont (francis.dupont@inria.fr) |
| 22 | */ |
| 23 | |
| 24 | #ifndef lint |
| 25 | static const char rcsid[] = |
guy | 79877e9 | 2002-08-06 04:42:04 +0000 | [diff] [blame] | 26 | "@(#) $Header: /tcpdump/master/tcpdump/print-igrp.c,v 1.18 2002-08-06 04:42:05 guy Exp $ (LBL)"; |
fenner | b9ac23c | 1999-11-21 09:36:43 +0000 | [diff] [blame] | 27 | #endif |
| 28 | |
| 29 | #ifdef HAVE_CONFIG_H |
| 30 | #include "config.h" |
mcr | f555c16 | 1999-10-07 23:47:09 +0000 | [diff] [blame] | 31 | #endif |
| 32 | |
risso | 3d93249 | 2002-08-01 08:52:55 +0000 | [diff] [blame] | 33 | #include <tcpdump-stdinc.h> |
mcr | f555c16 | 1999-10-07 23:47:09 +0000 | [diff] [blame] | 34 | |
mcr | f555c16 | 1999-10-07 23:47:09 +0000 | [diff] [blame] | 35 | #include <stdio.h> |
| 36 | |
| 37 | #include "interface.h" |
| 38 | #include "addrtoname.h" |
| 39 | #include "igrp.h" |
guy | 536f512 | 2000-09-23 08:54:24 +0000 | [diff] [blame] | 40 | #include "ip.h" |
mcr | f555c16 | 1999-10-07 23:47:09 +0000 | [diff] [blame] | 41 | #include "extract.h" /* must come after interface.h */ |
| 42 | |
| 43 | static void |
| 44 | igrp_entry_print(register struct igrprte *igr, register int is_interior, |
| 45 | register int is_exterior) |
| 46 | { |
| 47 | register u_int delay, bandwidth; |
| 48 | u_int metric, mtu; |
| 49 | |
| 50 | if (is_interior) |
| 51 | printf(" *.%d.%d.%d", igr->igr_net[0], |
| 52 | igr->igr_net[1], igr->igr_net[2]); |
| 53 | else if (is_exterior) |
| 54 | printf(" X%d.%d.%d.0", igr->igr_net[0], |
| 55 | igr->igr_net[1], igr->igr_net[2]); |
| 56 | else |
| 57 | printf(" %d.%d.%d.0", igr->igr_net[0], |
| 58 | igr->igr_net[1], igr->igr_net[2]); |
| 59 | |
| 60 | delay = EXTRACT_24BITS(igr->igr_dly); |
| 61 | bandwidth = EXTRACT_24BITS(igr->igr_bw); |
| 62 | metric = bandwidth + delay; |
| 63 | if (metric > 0xffffff) |
| 64 | metric = 0xffffff; |
| 65 | mtu = EXTRACT_16BITS(igr->igr_mtu); |
| 66 | |
| 67 | printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops", |
| 68 | 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth, |
| 69 | igr->igr_rel, igr->igr_ld, metric, |
| 70 | mtu, igr->igr_hct); |
| 71 | } |
| 72 | |
| 73 | static struct tok op2str[] = { |
| 74 | { IGRP_UPDATE, "update" }, |
| 75 | { IGRP_REQUEST, "request" }, |
| 76 | { 0, NULL } |
| 77 | }; |
| 78 | |
| 79 | void |
| 80 | igrp_print(register const u_char *bp, u_int length, register const u_char *bp2) |
| 81 | { |
| 82 | register struct igrphdr *hdr; |
| 83 | register struct ip *ip; |
| 84 | register u_char *cp; |
| 85 | u_int nint, nsys, next; |
| 86 | |
| 87 | hdr = (struct igrphdr *)bp; |
| 88 | ip = (struct ip *)bp2; |
| 89 | cp = (u_char *)(hdr + 1); |
fenner | a11713d | 2001-06-15 22:17:31 +0000 | [diff] [blame] | 90 | (void)printf("igrp:"); |
mcr | f555c16 | 1999-10-07 23:47:09 +0000 | [diff] [blame] | 91 | |
| 92 | /* Header */ |
| 93 | TCHECK(*hdr); |
| 94 | nint = EXTRACT_16BITS(&hdr->ig_ni); |
| 95 | nsys = EXTRACT_16BITS(&hdr->ig_ns); |
| 96 | next = EXTRACT_16BITS(&hdr->ig_nx); |
| 97 | |
| 98 | (void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)", |
itojun | 9e560fa | 2000-04-28 11:01:49 +0000 | [diff] [blame] | 99 | tok2str(op2str, "op-#%d", IGRP_OP(hdr->ig_vop)), |
| 100 | IGRP_V(hdr->ig_vop), |
mcr | f555c16 | 1999-10-07 23:47:09 +0000 | [diff] [blame] | 101 | hdr->ig_ed, |
| 102 | EXTRACT_16BITS(&hdr->ig_as), |
| 103 | nint, |
| 104 | nsys, |
| 105 | next); |
| 106 | |
| 107 | length -= sizeof(*hdr); |
| 108 | while (length >= IGRP_RTE_SIZE) { |
| 109 | if (nint > 0) { |
| 110 | TCHECK2(*cp, IGRP_RTE_SIZE); |
| 111 | igrp_entry_print((struct igrprte *)cp, 1, 0); |
| 112 | --nint; |
| 113 | } else if (nsys > 0) { |
| 114 | TCHECK2(*cp, IGRP_RTE_SIZE); |
| 115 | igrp_entry_print((struct igrprte *)cp, 0, 0); |
| 116 | --nsys; |
| 117 | } else if (next > 0) { |
| 118 | TCHECK2(*cp, IGRP_RTE_SIZE); |
| 119 | igrp_entry_print((struct igrprte *)cp, 0, 1); |
| 120 | --next; |
| 121 | } else { |
fenner | a11713d | 2001-06-15 22:17:31 +0000 | [diff] [blame] | 122 | (void)printf(" [extra bytes %d]", length); |
mcr | f555c16 | 1999-10-07 23:47:09 +0000 | [diff] [blame] | 123 | break; |
| 124 | } |
| 125 | cp += IGRP_RTE_SIZE; |
| 126 | length -= IGRP_RTE_SIZE; |
| 127 | } |
| 128 | if (nint == 0 && nsys == 0 && next == 0) |
| 129 | return; |
| 130 | trunc: |
fenner | a11713d | 2001-06-15 22:17:31 +0000 | [diff] [blame] | 131 | fputs(" [|igrp]", stdout); |
mcr | f555c16 | 1999-10-07 23:47:09 +0000 | [diff] [blame] | 132 | } |