2 * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Lawrence Berkeley Laboratory,
11 * Berkeley, CA. The name of the University may not be used to
12 * endorse or promote products derived from this software without
13 * specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 * Initial contribution from Jeff Honig (jch@MITCHELL.CIT.CORNELL.EDU).
22 static const char rcsid[] =
23 "@(#) $Header: /tcpdump/master/tcpdump/print-egp.c,v 1.28 2001/09/17 21:58:01 fenner Exp $ (LBL)";
30 #include <sys/param.h>
33 #include <sys/socket.h>
35 #include <netinet/in.h>
40 #include "interface.h"
41 #include "addrtoname.h"
49 #define EGPT_ACQUIRE 3
55 #define EGPC_REQUEST 0
56 #define EGPC_CONFIRM 1
59 #define EGPC_CEASEACK 4
65 #define EGPS_PASSIVE 2
74 #define EGPS_UNSOL 0x80
83 #define EGPR_BADHEAD 1
84 #define EGPR_BADDATA 2
85 #define EGPR_NOREACH 3
88 #define EGPR_UVERSION 6
90 #define egp_hello egp_handg.egpu_hello
91 #define egp_intgw egp_handg.egpu_gws[0]
92 #define egp_extgw egp_handg.egpu_gws[1]
93 #define egp_reason egp_handg.egpu_reason
96 u_int32_t egpu_sourcenet;
98 #define egp_poll egp_pands.egpu_poll
99 #define egp_sourcenet egp_pands.egpu_sourcenet
102 const char *egp_acquire_codes[] = {
110 const char *egp_acquire_status[] = {
114 "insufficient_resources",
115 "administratively_prohibited",
117 "parameter_violation",
121 const char *egp_reach_codes[] = {
126 const char *egp_status_updown[] = {
132 const char *egp_reasons[] = {
134 "bad_EGP_header_format",
135 "bad_EGP_data_field_format",
136 "reachability_info_unavailable",
137 "excessive_polling_rate",
139 "unsupported_version"
143 egpnrprint(register const struct egp_packet *egp, register u_int length)
145 register const u_char *cp;
147 register u_int32_t net;
148 register u_int netlen;
149 int gateways, distances, networks;
153 addr = egp->egp_sourcenet;
154 if (IN_CLASSA(addr)) {
155 net = addr & IN_CLASSA_NET;
157 } else if (IN_CLASSB(addr)) {
158 net = addr & IN_CLASSB_NET;
160 } else if (IN_CLASSC(addr)) {
161 net = addr & IN_CLASSC_NET;
167 cp = (u_char *)(egp + 1);
169 t_gateways = egp->egp_intgw + egp->egp_extgw;
170 for (gateways = 0; gateways < t_gateways; ++gateways) {
171 /* Pickup host part of gateway address */
173 TCHECK2(cp[0], 4 - netlen);
180 addr = (addr << 8) | *cp++;
183 addr = (addr << 8) | *cp++;
189 gateways < (int)egp->egp_intgw ? "int" : "ext",
190 ipaddr_string(&addr));
194 while (--distances >= 0) {
196 printf("%sd%d:", comma, (int)*cp++);
199 while (--networks >= 0) {
200 /* Pickup network number */
202 addr = (u_int32_t)*cp++ << 24;
203 if (IN_CLASSB(addr)) {
205 addr |= (u_int32_t)*cp++ << 16;
206 } else if (!IN_CLASSA(addr)) {
208 addr |= (u_int32_t)*cp++ << 16;
209 addr |= (u_int32_t)*cp++ << 8;
211 printf(" %s", ipaddr_string(&addr));
218 fputs("[|]", stdout);
222 egp_print(register const u_char *bp, register u_int length,
223 register const u_char *bp2)
225 register const struct egp_packet *egp;
226 register const struct ip *ip;
231 egp = (struct egp_packet *)bp;
232 ip = (struct ip *)bp2;
233 (void)printf("egp: ");
235 if (egp->egp_version != EGP_VERSION) {
236 printf("[version %d]", egp->egp_version);
239 printf("as:%d seq:%d", ntohs(egp->egp_as), ntohs(egp->egp_sequence));
241 type = egp->egp_type;
242 code = egp->egp_code;
243 status = egp->egp_status;
251 printf(" %s", egp_acquire_codes[code]);
256 printf(" %s", egp_acquire_status[status]);
260 printf(" [status %d]", status);
263 printf(" hello:%d poll:%d",
264 ntohs(egp->egp_hello),
265 ntohs(egp->egp_poll));
271 printf(" %s", egp_acquire_codes[code]);
279 printf(" %s", egp_acquire_status[status]);
283 printf("[status %d]", status);
289 printf("[code %d]", code);
299 printf(" %s", egp_reach_codes[code]);
300 if (status <= EGPS_DOWN)
301 printf(" state:%s", egp_status_updown[status]);
303 printf(" [status %d]", status);
307 printf("[reach code %d]", code);
314 if (egp->egp_status <= EGPS_DOWN)
315 printf(" state:%s", egp_status_updown[status]);
317 printf(" [status %d]", status);
318 printf(" net:%s", ipaddr_string(&egp->egp_sourcenet));
323 if (status & EGPS_UNSOL) {
324 status &= ~EGPS_UNSOL;
325 printf(" unsolicited");
327 if (status <= EGPS_DOWN)
328 printf(" state:%s", egp_status_updown[status]);
330 printf(" [status %d]", status);
331 printf(" %s int %d ext %d",
332 ipaddr_string(&egp->egp_sourcenet),
336 egpnrprint(egp, length);
341 if (status <= EGPS_DOWN)
342 printf(" state:%s", egp_status_updown[status]);
344 printf(" [status %d]", status);
346 if (ntohs(egp->egp_reason) <= EGPR_UVERSION)
347 printf(" %s", egp_reasons[ntohs(egp->egp_reason)]);
349 printf(" [reason %d]", ntohs(egp->egp_reason));
353 printf("[type %d]", type);