]> The Tcpdump Group git mirrors - tcpdump/blob - print-igrp.c
Add Loris Digioanni, as he's credited as the main programmer on the
[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 #ifndef lint
25 static const char rcsid[] =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-igrp.c,v 1.17 2002-08-01 08:53:10 risso Exp $ (LBL)";
27 #endif
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <tcpdump-stdinc.h>
34
35 #include <errno.h>
36 #include <stdio.h>
37
38 #include "interface.h"
39 #include "addrtoname.h"
40 #include "igrp.h"
41 #include "ip.h"
42 #include "extract.h" /* must come after interface.h */
43
44 static void
45 igrp_entry_print(register struct igrprte *igr, register int is_interior,
46 register int is_exterior)
47 {
48 register u_int delay, bandwidth;
49 u_int metric, mtu;
50
51 if (is_interior)
52 printf(" *.%d.%d.%d", igr->igr_net[0],
53 igr->igr_net[1], igr->igr_net[2]);
54 else if (is_exterior)
55 printf(" X%d.%d.%d.0", igr->igr_net[0],
56 igr->igr_net[1], igr->igr_net[2]);
57 else
58 printf(" %d.%d.%d.0", igr->igr_net[0],
59 igr->igr_net[1], igr->igr_net[2]);
60
61 delay = EXTRACT_24BITS(igr->igr_dly);
62 bandwidth = EXTRACT_24BITS(igr->igr_bw);
63 metric = bandwidth + delay;
64 if (metric > 0xffffff)
65 metric = 0xffffff;
66 mtu = EXTRACT_16BITS(igr->igr_mtu);
67
68 printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops",
69 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
70 igr->igr_rel, igr->igr_ld, metric,
71 mtu, igr->igr_hct);
72 }
73
74 static struct tok op2str[] = {
75 { IGRP_UPDATE, "update" },
76 { IGRP_REQUEST, "request" },
77 { 0, NULL }
78 };
79
80 void
81 igrp_print(register const u_char *bp, u_int length, register const u_char *bp2)
82 {
83 register struct igrphdr *hdr;
84 register struct ip *ip;
85 register u_char *cp;
86 u_int nint, nsys, next;
87
88 hdr = (struct igrphdr *)bp;
89 ip = (struct ip *)bp2;
90 cp = (u_char *)(hdr + 1);
91 (void)printf("igrp:");
92
93 /* Header */
94 TCHECK(*hdr);
95 nint = EXTRACT_16BITS(&hdr->ig_ni);
96 nsys = EXTRACT_16BITS(&hdr->ig_ns);
97 next = EXTRACT_16BITS(&hdr->ig_nx);
98
99 (void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)",
100 tok2str(op2str, "op-#%d", IGRP_OP(hdr->ig_vop)),
101 IGRP_V(hdr->ig_vop),
102 hdr->ig_ed,
103 EXTRACT_16BITS(&hdr->ig_as),
104 nint,
105 nsys,
106 next);
107
108 length -= sizeof(*hdr);
109 while (length >= IGRP_RTE_SIZE) {
110 if (nint > 0) {
111 TCHECK2(*cp, IGRP_RTE_SIZE);
112 igrp_entry_print((struct igrprte *)cp, 1, 0);
113 --nint;
114 } else if (nsys > 0) {
115 TCHECK2(*cp, IGRP_RTE_SIZE);
116 igrp_entry_print((struct igrprte *)cp, 0, 0);
117 --nsys;
118 } else if (next > 0) {
119 TCHECK2(*cp, IGRP_RTE_SIZE);
120 igrp_entry_print((struct igrprte *)cp, 0, 1);
121 --next;
122 } else {
123 (void)printf(" [extra bytes %d]", length);
124 break;
125 }
126 cp += IGRP_RTE_SIZE;
127 length -= IGRP_RTE_SIZE;
128 }
129 if (nint == 0 && nsys == 0 && next == 0)
130 return;
131 trunc:
132 fputs(" [|igrp]", stdout);
133 }