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