4 * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by the University of California, Lawrence Berkeley Laboratory,
13 * Berkeley, CA. The name of the University may not be used to
14 * endorse or promote products derived from this software without
15 * specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 * Initial contribution from Jeff Honig (jch@MITCHELL.CIT.CORNELL.EDU).
23 #include <sys/cdefs.h>
26 static const char rcsid
[] _U_
=
27 "@(#) Header: /tcpdump/master/tcpdump/print-egp.c,v 1.37 2005/01/12 11:19:09 hannes Exp (LBL)";
29 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
37 #include <tcpdump-stdinc.h>
41 #include "interface.h"
42 #include "addrtoname.h"
51 #define EGPT_ACQUIRE 3
57 #define EGPC_REQUEST 0
58 #define EGPC_CONFIRM 1
61 #define EGPC_CEASEACK 4
67 #define EGPS_PASSIVE 2
76 #define EGPS_UNSOL 0x80
77 u_int16_t egp_checksum
;
79 u_int16_t egp_sequence
;
83 u_int16_t egpu_reason
;
85 #define EGPR_BADHEAD 1
86 #define EGPR_BADDATA 2
87 #define EGPR_NOREACH 3
90 #define EGPR_UVERSION 6
92 #define egp_hello egp_handg.egpu_hello
93 #define egp_intgw egp_handg.egpu_gws[0]
94 #define egp_extgw egp_handg.egpu_gws[1]
95 #define egp_reason egp_handg.egpu_reason
98 u_int32_t egpu_sourcenet
;
100 #define egp_poll egp_pands.egpu_poll
101 #define egp_sourcenet egp_pands.egpu_sourcenet
104 const char *egp_acquire_codes
[] = {
112 const char *egp_acquire_status
[] = {
116 "insufficient_resources",
117 "administratively_prohibited",
119 "parameter_violation",
123 const char *egp_reach_codes
[] = {
128 const char *egp_status_updown
[] = {
134 const char *egp_reasons
[] = {
136 "bad_EGP_header_format",
137 "bad_EGP_data_field_format",
138 "reachability_info_unavailable",
139 "excessive_polling_rate",
141 "unsupported_version"
145 egpnrprint(register const struct egp_packet
*egp
)
147 register const u_int8_t
*cp
;
149 register u_int32_t net
;
150 register u_int netlen
;
151 int gateways
, distances
, networks
;
155 addr
= egp
->egp_sourcenet
;
156 if (IN_CLASSA(addr
)) {
157 net
= addr
& IN_CLASSA_NET
;
159 } else if (IN_CLASSB(addr
)) {
160 net
= addr
& IN_CLASSB_NET
;
162 } else if (IN_CLASSC(addr
)) {
163 net
= addr
& IN_CLASSC_NET
;
169 cp
= (u_int8_t
*)(egp
+ 1);
171 t_gateways
= egp
->egp_intgw
+ egp
->egp_extgw
;
172 for (gateways
= 0; gateways
< t_gateways
; ++gateways
) {
173 /* Pickup host part of gateway address */
175 TCHECK2(cp
[0], 4 - netlen
);
182 addr
= (addr
<< 8) | *cp
++;
185 addr
= (addr
<< 8) | *cp
++;
191 gateways
< (int)egp
->egp_intgw
? "int" : "ext",
192 ipaddr_string(&addr
));
196 while (--distances
>= 0) {
198 printf("%sd%d:", comma
, (int)*cp
++);
201 while (--networks
>= 0) {
202 /* Pickup network number */
204 addr
= (u_int32_t
)*cp
++ << 24;
205 if (IN_CLASSB(addr
)) {
207 addr
|= (u_int32_t
)*cp
++ << 16;
208 } else if (!IN_CLASSA(addr
)) {
210 addr
|= (u_int32_t
)*cp
++ << 16;
211 addr
|= (u_int32_t
)*cp
++ << 8;
213 printf(" %s", ipaddr_string(&addr
));
220 fputs("[|]", stdout
);
224 egp_print(register const u_int8_t
*bp
, register u_int length
)
226 register const struct egp_packet
*egp
;
231 egp
= (struct egp_packet
*)bp
;
232 if (!TTEST2(*egp
, length
)) {
236 (void)printf("egp: ");
238 if (egp
->egp_version
!= EGP_VERSION
) {
239 printf("[version %d]", egp
->egp_version
);
242 printf("as:%d seq:%d", EXTRACT_16BITS(&egp
->egp_as
), EXTRACT_16BITS(&egp
->egp_sequence
));
244 type
= egp
->egp_type
;
245 code
= egp
->egp_code
;
246 status
= egp
->egp_status
;
254 printf(" %s", egp_acquire_codes
[code
]);
259 printf(" %s", egp_acquire_status
[status
]);
263 printf(" [status %d]", status
);
266 printf(" hello:%d poll:%d",
267 EXTRACT_16BITS(&egp
->egp_hello
),
268 EXTRACT_16BITS(&egp
->egp_poll
));
274 printf(" %s", egp_acquire_codes
[code
]);
282 printf(" %s", egp_acquire_status
[status
]);
286 printf("[status %d]", status
);
292 printf("[code %d]", code
);
302 printf(" %s", egp_reach_codes
[code
]);
303 if (status
<= EGPS_DOWN
)
304 printf(" state:%s", egp_status_updown
[status
]);
306 printf(" [status %d]", status
);
310 printf("[reach code %d]", code
);
317 if (egp
->egp_status
<= EGPS_DOWN
)
318 printf(" state:%s", egp_status_updown
[status
]);
320 printf(" [status %d]", status
);
321 printf(" net:%s", ipaddr_string(&egp
->egp_sourcenet
));
326 if (status
& EGPS_UNSOL
) {
327 status
&= ~EGPS_UNSOL
;
328 printf(" unsolicited");
330 if (status
<= EGPS_DOWN
)
331 printf(" state:%s", egp_status_updown
[status
]);
333 printf(" [status %d]", status
);
334 printf(" %s int %d ext %d",
335 ipaddr_string(&egp
->egp_sourcenet
),
344 if (status
<= EGPS_DOWN
)
345 printf(" state:%s", egp_status_updown
[status
]);
347 printf(" [status %d]", status
);
349 if (EXTRACT_16BITS(&egp
->egp_reason
) <= EGPR_UVERSION
)
350 printf(" %s", egp_reasons
[EXTRACT_16BITS(&egp
->egp_reason
)]);
352 printf(" [reason %d]", EXTRACT_16BITS(&egp
->egp_reason
));
356 printf("[type %d]", type
);