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.26 2000/09/29 04:58:36 guy 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 char *egp_acquire_codes[] = {
110 char *egp_acquire_status[] = {
114 "insufficient_resources",
115 "administratively_prohibited",
117 "parameter_violation",
121 char *egp_reach_codes[] = {
126 char *egp_status_updown[] = {
132 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("%s > %s: egp: ",
234 ipaddr_string(&ip->ip_src),
235 ipaddr_string(&ip->ip_dst));
237 if (egp->egp_version != EGP_VERSION) {
238 printf("[version %d]", egp->egp_version);
241 printf("as:%d seq:%d", ntohs(egp->egp_as), ntohs(egp->egp_sequence));
243 type = egp->egp_type;
244 code = egp->egp_code;
245 status = egp->egp_status;
253 printf(" %s", egp_acquire_codes[code]);
258 printf(" %s", egp_acquire_status[status]);
262 printf(" [status %d]", status);
265 printf(" hello:%d poll:%d",
266 ntohs(egp->egp_hello),
267 ntohs(egp->egp_poll));
273 printf(" %s", egp_acquire_codes[code]);
281 printf(" %s", egp_acquire_status[status]);
285 printf("[status %d]", status);
291 printf("[code %d]", code);
301 printf(" %s", egp_reach_codes[code]);
302 if (status <= EGPS_DOWN)
303 printf(" state:%s", egp_status_updown[status]);
305 printf(" [status %d]", status);
309 printf("[reach code %d]", code);
316 if (egp->egp_status <= EGPS_DOWN)
317 printf(" state:%s", egp_status_updown[status]);
319 printf(" [status %d]", status);
320 printf(" net:%s", ipaddr_string(&egp->egp_sourcenet));
325 if (status & EGPS_UNSOL) {
326 status &= ~EGPS_UNSOL;
327 printf(" unsolicited");
329 if (status <= EGPS_DOWN)
330 printf(" state:%s", egp_status_updown[status]);
332 printf(" [status %d]", status);
333 printf(" %s int %d ext %d",
334 ipaddr_string(&egp->egp_sourcenet),
338 egpnrprint(egp, length);
343 if (status <= EGPS_DOWN)
344 printf(" state:%s", egp_status_updown[status]);
346 printf(" [status %d]", status);
348 if (ntohs(egp->egp_reason) <= EGPR_UVERSION)
349 printf(" %s", egp_reasons[ntohs(egp->egp_reason)]);
351 printf(" [reason %d]", ntohs(egp->egp_reason));
355 printf("[type %d]", type);