]> The Tcpdump Group git mirrors - tcpdump/blob - print-igrp.c
don't include addrtoname.h needlessly
[tcpdump] / print-igrp.c
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 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <tcpdump-stdinc.h>
29
30 #include <stdio.h>
31
32 #include "interface.h"
33 #include "ip.h"
34 #include "extract.h" /* must come after interface.h */
35
36 /* Cisco IGRP definitions */
37
38 /* IGRP Header */
39
40 struct igrphdr {
41 u_int8_t ig_vop; /* protocol version number / opcode */
42 #define IGRP_V(x) (((x) & 0xf0) >> 4)
43 #define IGRP_OP(x) ((x) & 0x0f)
44 u_int8_t ig_ed; /* edition number */
45 u_int16_t ig_as; /* autonomous system number */
46 u_int16_t ig_ni; /* number of subnet in local net */
47 u_int16_t ig_ns; /* number of networks in AS */
48 u_int16_t ig_nx; /* number of networks ouside AS */
49 u_int16_t ig_sum; /* checksum of IGRP header & data */
50 };
51
52 #define IGRP_UPDATE 1
53 #define IGRP_REQUEST 2
54
55 /* IGRP routing entry */
56
57 struct igrprte {
58 u_int8_t igr_net[3]; /* 3 significant octets of IP address */
59 u_int8_t igr_dly[3]; /* delay in tens of microseconds */
60 u_int8_t igr_bw[3]; /* bandwidth in units of 1 kb/s */
61 u_int8_t igr_mtu[2]; /* MTU in octets */
62 u_int8_t igr_rel; /* percent packets successfully tx/rx */
63 u_int8_t igr_ld; /* percent of channel occupied */
64 u_int8_t igr_hct; /* hop count */
65 };
66
67 #define IGRP_RTE_SIZE 14 /* don't believe sizeof ! */
68
69 static void
70 igrp_entry_print(register struct igrprte *igr, register int is_interior,
71 register int is_exterior)
72 {
73 register u_int delay, bandwidth;
74 u_int metric, mtu;
75
76 if (is_interior)
77 printf(" *.%d.%d.%d", igr->igr_net[0],
78 igr->igr_net[1], igr->igr_net[2]);
79 else if (is_exterior)
80 printf(" X%d.%d.%d.0", igr->igr_net[0],
81 igr->igr_net[1], igr->igr_net[2]);
82 else
83 printf(" %d.%d.%d.0", igr->igr_net[0],
84 igr->igr_net[1], igr->igr_net[2]);
85
86 delay = EXTRACT_24BITS(igr->igr_dly);
87 bandwidth = EXTRACT_24BITS(igr->igr_bw);
88 metric = bandwidth + delay;
89 if (metric > 0xffffff)
90 metric = 0xffffff;
91 mtu = EXTRACT_16BITS(igr->igr_mtu);
92
93 printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops",
94 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
95 igr->igr_rel, igr->igr_ld, metric,
96 mtu, igr->igr_hct);
97 }
98
99 static const struct tok op2str[] = {
100 { IGRP_UPDATE, "update" },
101 { IGRP_REQUEST, "request" },
102 { 0, NULL }
103 };
104
105 void
106 igrp_print(register const u_char *bp, u_int length, const u_char *bp2 _U_)
107 {
108 register struct igrphdr *hdr;
109 register u_char *cp;
110 u_int nint, nsys, next;
111
112 hdr = (struct igrphdr *)bp;
113 cp = (u_char *)(hdr + 1);
114 (void)printf("igrp:");
115
116 /* Header */
117 TCHECK(*hdr);
118 nint = EXTRACT_16BITS(&hdr->ig_ni);
119 nsys = EXTRACT_16BITS(&hdr->ig_ns);
120 next = EXTRACT_16BITS(&hdr->ig_nx);
121
122 (void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)",
123 tok2str(op2str, "op-#%d", IGRP_OP(hdr->ig_vop)),
124 IGRP_V(hdr->ig_vop),
125 hdr->ig_ed,
126 EXTRACT_16BITS(&hdr->ig_as),
127 nint,
128 nsys,
129 next);
130
131 length -= sizeof(*hdr);
132 while (length >= IGRP_RTE_SIZE) {
133 if (nint > 0) {
134 TCHECK2(*cp, IGRP_RTE_SIZE);
135 igrp_entry_print((struct igrprte *)cp, 1, 0);
136 --nint;
137 } else if (nsys > 0) {
138 TCHECK2(*cp, IGRP_RTE_SIZE);
139 igrp_entry_print((struct igrprte *)cp, 0, 0);
140 --nsys;
141 } else if (next > 0) {
142 TCHECK2(*cp, IGRP_RTE_SIZE);
143 igrp_entry_print((struct igrprte *)cp, 0, 1);
144 --next;
145 } else {
146 (void)printf(" [extra bytes %d]", length);
147 break;
148 }
149 cp += IGRP_RTE_SIZE;
150 length -= IGRP_RTE_SIZE;
151 }
152 if (nint == 0 && nsys == 0 && next == 0)
153 return;
154 trunc:
155 fputs(" [|igrp]", stdout);
156 }