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[] _U_ =
23 "@(#) $Header: /tcpdump/master/tcpdump/print-egp.c,v 1.37 2005/01/12 11:19:09 hannes Exp $ (LBL)";
30 #include <tcpdump-stdinc.h>
34 #include "interface.h"
35 #include "addrtoname.h"
44 #define EGPT_ACQUIRE 3
50 #define EGPC_REQUEST 0
51 #define EGPC_CONFIRM 1
54 #define EGPC_CEASEACK 4
60 #define EGPS_PASSIVE 2
69 #define EGPS_UNSOL 0x80
70 u_int16_t egp_checksum;
72 u_int16_t egp_sequence;
76 u_int16_t egpu_reason;
78 #define EGPR_BADHEAD 1
79 #define EGPR_BADDATA 2
80 #define EGPR_NOREACH 3
83 #define EGPR_UVERSION 6
85 #define egp_hello egp_handg.egpu_hello
86 #define egp_intgw egp_handg.egpu_gws[0]
87 #define egp_extgw egp_handg.egpu_gws[1]
88 #define egp_reason egp_handg.egpu_reason
91 u_int32_t egpu_sourcenet;
93 #define egp_poll egp_pands.egpu_poll
94 #define egp_sourcenet egp_pands.egpu_sourcenet
97 const char *egp_acquire_codes[] = {
105 const char *egp_acquire_status[] = {
109 "insufficient_resources",
110 "administratively_prohibited",
112 "parameter_violation",
116 const char *egp_reach_codes[] = {
121 const char *egp_status_updown[] = {
127 const char *egp_reasons[] = {
129 "bad_EGP_header_format",
130 "bad_EGP_data_field_format",
131 "reachability_info_unavailable",
132 "excessive_polling_rate",
134 "unsupported_version"
138 egpnrprint(register const struct egp_packet *egp)
140 register const u_int8_t *cp;
142 register u_int32_t net;
143 register u_int netlen;
144 int gateways, distances, networks;
148 addr = egp->egp_sourcenet;
149 if (IN_CLASSA(addr)) {
150 net = addr & IN_CLASSA_NET;
152 } else if (IN_CLASSB(addr)) {
153 net = addr & IN_CLASSB_NET;
155 } else if (IN_CLASSC(addr)) {
156 net = addr & IN_CLASSC_NET;
162 cp = (u_int8_t *)(egp + 1);
164 t_gateways = egp->egp_intgw + egp->egp_extgw;
165 for (gateways = 0; gateways < t_gateways; ++gateways) {
166 /* Pickup host part of gateway address */
168 TCHECK2(cp[0], 4 - netlen);
175 addr = (addr << 8) | *cp++;
178 addr = (addr << 8) | *cp++;
184 gateways < (int)egp->egp_intgw ? "int" : "ext",
185 ipaddr_string(&addr));
189 while (--distances >= 0) {
191 printf("%sd%d:", comma, (int)*cp++);
194 while (--networks >= 0) {
195 /* Pickup network number */
197 addr = (u_int32_t)*cp++ << 24;
198 if (IN_CLASSB(addr)) {
200 addr |= (u_int32_t)*cp++ << 16;
201 } else if (!IN_CLASSA(addr)) {
203 addr |= (u_int32_t)*cp++ << 16;
204 addr |= (u_int32_t)*cp++ << 8;
206 printf(" %s", ipaddr_string(&addr));
213 fputs("[|]", stdout);
217 egp_print(register const u_int8_t *bp, register u_int length)
219 register const struct egp_packet *egp;
224 egp = (struct egp_packet *)bp;
225 if (!TTEST2(*egp, length)) {
229 (void)printf("egp: ");
231 if (egp->egp_version != EGP_VERSION) {
232 printf("[version %d]", egp->egp_version);
235 printf("as:%d seq:%d", EXTRACT_16BITS(&egp->egp_as), EXTRACT_16BITS(&egp->egp_sequence));
237 type = egp->egp_type;
238 code = egp->egp_code;
239 status = egp->egp_status;
247 printf(" %s", egp_acquire_codes[code]);
252 printf(" %s", egp_acquire_status[status]);
256 printf(" [status %d]", status);
259 printf(" hello:%d poll:%d",
260 EXTRACT_16BITS(&egp->egp_hello),
261 EXTRACT_16BITS(&egp->egp_poll));
267 printf(" %s", egp_acquire_codes[code]);
275 printf(" %s", egp_acquire_status[status]);
279 printf("[status %d]", status);
285 printf("[code %d]", code);
295 printf(" %s", egp_reach_codes[code]);
296 if (status <= EGPS_DOWN)
297 printf(" state:%s", egp_status_updown[status]);
299 printf(" [status %d]", status);
303 printf("[reach code %d]", code);
310 if (egp->egp_status <= EGPS_DOWN)
311 printf(" state:%s", egp_status_updown[status]);
313 printf(" [status %d]", status);
314 printf(" net:%s", ipaddr_string(&egp->egp_sourcenet));
319 if (status & EGPS_UNSOL) {
320 status &= ~EGPS_UNSOL;
321 printf(" unsolicited");
323 if (status <= EGPS_DOWN)
324 printf(" state:%s", egp_status_updown[status]);
326 printf(" [status %d]", status);
327 printf(" %s int %d ext %d",
328 ipaddr_string(&egp->egp_sourcenet),
337 if (status <= EGPS_DOWN)
338 printf(" state:%s", egp_status_updown[status]);
340 printf(" [status %d]", status);
342 if (EXTRACT_16BITS(&egp->egp_reason) <= EGPR_UVERSION)
343 printf(" %s", egp_reasons[EXTRACT_16BITS(&egp->egp_reason)]);
345 printf(" [reason %d]", EXTRACT_16BITS(&egp->egp_reason));
349 printf("[type %d]", type);