]> git.saurik.com Git - apple/network_cmds.git/blob - tcpdump.tproj/print-igrp.c
a35e6ac4618fa596f828ff5f05d0b62c9c1f960f
[apple/network_cmds.git] / tcpdump.tproj / print-igrp.c
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License."
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /*
25 * Copyright (c) 1996
26 * The Regents of the University of California. All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that: (1) source code distributions
30 * retain the above copyright notice and this paragraph in its entirety, (2)
31 * distributions including binary code include the above copyright notice and
32 * this paragraph in its entirety in the documentation or other materials
33 * provided with the distribution, and (3) all advertising materials mentioning
34 * features or use of this software display the following acknowledgement:
35 * ``This product includes software developed by the University of California,
36 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
37 * the University nor the names of its contributors may be used to endorse
38 * or promote products derived from this software without specific prior
39 * written permission.
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
41 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
43 *
44 * Initial contribution from Francis Dupont (francis.dupont@inria.fr)
45 */
46
47 #ifndef lint
48 static const char rcsid[] =
49 "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-igrp.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)";
50 #endif
51
52 #include <sys/param.h>
53 #include <sys/socket.h>
54
55 #include <netinet/in.h>
56 #include <netinet/in_systm.h>
57 #include <netinet/ip.h>
58 #include <netinet/ip_var.h>
59 #include <netinet/udp.h>
60 #include <netinet/udp_var.h>
61
62 #include <errno.h>
63 #include <stdio.h>
64
65 #include "addrtoname.h"
66 #include "interface.h"
67 #include "igrp.h"
68 #include "extract.h" /* must come after interface.h */
69
70 static void
71 igrp_entry_print(register struct igrprte *igr, register int is_interior,
72 register int is_exterior)
73 {
74 register u_int delay, bandwidth;
75 u_int metric, mtu;
76
77 if (is_interior)
78 printf(" *.%d.%d.%d", igr->igr_net[0],
79 igr->igr_net[1], igr->igr_net[2]);
80 else if (is_exterior)
81 printf(" X%d.%d.%d.0", igr->igr_net[0],
82 igr->igr_net[1], igr->igr_net[2]);
83 else
84 printf(" %d.%d.%d.0", igr->igr_net[0],
85 igr->igr_net[1], igr->igr_net[2]);
86
87 delay = EXTRACT_24BITS(igr->igr_dly);
88 bandwidth = EXTRACT_24BITS(igr->igr_bw);
89 metric = bandwidth + delay;
90 if (metric > 0xffffff)
91 metric = 0xffffff;
92 mtu = EXTRACT_16BITS(igr->igr_mtu);
93
94 printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops",
95 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
96 igr->igr_rel, igr->igr_ld, metric,
97 mtu, igr->igr_hct);
98 }
99
100 static struct tok op2str[] = {
101 { IGRP_UPDATE, "update" },
102 { IGRP_REQUEST, "request" },
103 { 0, NULL }
104 };
105
106 void
107 igrp_print(register const u_char *bp, u_int length, register const u_char *bp2)
108 {
109 register struct igrphdr *hdr;
110 register struct ip *ip;
111 register u_char *cp;
112 u_int nint, nsys, next;
113
114 hdr = (struct igrphdr *)bp;
115 ip = (struct ip *)bp2;
116 cp = (u_char *)(hdr + 1);
117 (void)printf("%s > %s: igrp: ",
118 ipaddr_string(&ip->ip_src),
119 ipaddr_string(&ip->ip_dst));
120
121 /* Header */
122 TCHECK(*hdr);
123 nint = EXTRACT_16BITS(&hdr->ig_ni);
124 nsys = EXTRACT_16BITS(&hdr->ig_ns);
125 next = EXTRACT_16BITS(&hdr->ig_nx);
126
127 (void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)",
128 tok2str(op2str, "op-#%d", hdr->ig_op),
129 hdr->ig_v,
130 hdr->ig_ed,
131 EXTRACT_16BITS(&hdr->ig_as),
132 nint,
133 nsys,
134 next);
135
136 length -= sizeof(*hdr);
137 while (length >= IGRP_RTE_SIZE) {
138 if (nint > 0) {
139 TCHECK2(*cp, IGRP_RTE_SIZE);
140 igrp_entry_print((struct igrprte *)cp, 1, 0);
141 --nint;
142 } else if (nsys > 0) {
143 TCHECK2(*cp, IGRP_RTE_SIZE);
144 igrp_entry_print((struct igrprte *)cp, 0, 0);
145 --nsys;
146 } else if (next > 0) {
147 TCHECK2(*cp, IGRP_RTE_SIZE);
148 igrp_entry_print((struct igrprte *)cp, 0, 1);
149 --next;
150 } else {
151 (void)printf("[extra bytes %d]", length);
152 break;
153 }
154 cp += IGRP_RTE_SIZE;
155 length -= IGRP_RTE_SIZE;
156 }
157 if (nint == 0 && nsys == 0 && next == 0)
158 return;
159 trunc:
160 fputs("[|igrp]", stdout);
161 }