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.38 2006-02-11 22:13:24 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
)) {
231 printf("EGPv%u, AS %u, seq %u, length %u",
233 EXTRACT_16BITS(&egp
->egp_as
),
234 EXTRACT_16BITS(&egp
->egp_sequence
),
238 printf("EGPv%u, length %u",
242 if (egp
->egp_version
!= EGP_VERSION
) {
243 printf("[version %d]", egp
->egp_version
);
247 type
= egp
->egp_type
;
248 code
= egp
->egp_code
;
249 status
= egp
->egp_status
;
257 printf(" %s", egp_acquire_codes
[code
]);
262 printf(" %s", egp_acquire_status
[status
]);
266 printf(" [status %d]", status
);
269 printf(" hello:%d poll:%d",
270 EXTRACT_16BITS(&egp
->egp_hello
),
271 EXTRACT_16BITS(&egp
->egp_poll
));
277 printf(" %s", egp_acquire_codes
[code
]);
285 printf(" %s", egp_acquire_status
[status
]);
289 printf("[status %d]", status
);
295 printf("[code %d]", code
);
305 printf(" %s", egp_reach_codes
[code
]);
306 if (status
<= EGPS_DOWN
)
307 printf(" state:%s", egp_status_updown
[status
]);
309 printf(" [status %d]", status
);
313 printf("[reach code %d]", code
);
320 if (egp
->egp_status
<= EGPS_DOWN
)
321 printf(" state:%s", egp_status_updown
[status
]);
323 printf(" [status %d]", status
);
324 printf(" net:%s", ipaddr_string(&egp
->egp_sourcenet
));
329 if (status
& EGPS_UNSOL
) {
330 status
&= ~EGPS_UNSOL
;
331 printf(" unsolicited");
333 if (status
<= EGPS_DOWN
)
334 printf(" state:%s", egp_status_updown
[status
]);
336 printf(" [status %d]", status
);
337 printf(" %s int %d ext %d",
338 ipaddr_string(&egp
->egp_sourcenet
),
347 if (status
<= EGPS_DOWN
)
348 printf(" state:%s", egp_status_updown
[status
]);
350 printf(" [status %d]", status
);
352 if (EXTRACT_16BITS(&egp
->egp_reason
) <= EGPR_UVERSION
)
353 printf(" %s", egp_reasons
[EXTRACT_16BITS(&egp
->egp_reason
)]);
355 printf(" [reason %d]", EXTRACT_16BITS(&egp
->egp_reason
));
359 printf("[type %d]", type
);