]>
The Tcpdump Group git mirrors - tcpdump/blob - print-egp.c
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).
25 #include <tcpdump-stdinc.h>
29 #include "interface.h"
30 #include "addrtoname.h"
39 #define EGPT_ACQUIRE 3
45 #define EGPC_REQUEST 0
46 #define EGPC_CONFIRM 1
49 #define EGPC_CEASEACK 4
55 #define EGPS_PASSIVE 2
64 #define EGPS_UNSOL 0x80
65 u_int16_t egp_checksum
;
67 u_int16_t egp_sequence
;
71 u_int16_t egpu_reason
;
73 #define EGPR_BADHEAD 1
74 #define EGPR_BADDATA 2
75 #define EGPR_NOREACH 3
78 #define EGPR_UVERSION 6
80 #define egp_hello egp_handg.egpu_hello
81 #define egp_intgw egp_handg.egpu_gws[0]
82 #define egp_extgw egp_handg.egpu_gws[1]
83 #define egp_reason egp_handg.egpu_reason
86 u_int32_t egpu_sourcenet
;
88 #define egp_poll egp_pands.egpu_poll
89 #define egp_sourcenet egp_pands.egpu_sourcenet
92 static const char *egp_acquire_codes
[] = {
100 static const char *egp_acquire_status
[] = {
104 "insufficient_resources",
105 "administratively_prohibited",
107 "parameter_violation",
111 static const char *egp_reach_codes
[] = {
116 static const char *egp_status_updown
[] = {
122 static const char *egp_reasons
[] = {
124 "bad_EGP_header_format",
125 "bad_EGP_data_field_format",
126 "reachability_info_unavailable",
127 "excessive_polling_rate",
129 "unsupported_version"
133 egpnrprint(register const struct egp_packet
*egp
)
135 register const u_int8_t
*cp
;
137 register u_int32_t net
;
138 register u_int netlen
;
139 int gateways
, distances
, networks
;
143 addr
= egp
->egp_sourcenet
;
144 if (IN_CLASSA(addr
)) {
145 net
= addr
& IN_CLASSA_NET
;
147 } else if (IN_CLASSB(addr
)) {
148 net
= addr
& IN_CLASSB_NET
;
150 } else if (IN_CLASSC(addr
)) {
151 net
= addr
& IN_CLASSC_NET
;
157 cp
= (u_int8_t
*)(egp
+ 1);
159 t_gateways
= egp
->egp_intgw
+ egp
->egp_extgw
;
160 for (gateways
= 0; gateways
< t_gateways
; ++gateways
) {
161 /* Pickup host part of gateway address */
163 TCHECK2(cp
[0], 4 - netlen
);
170 addr
= (addr
<< 8) | *cp
++;
173 addr
= (addr
<< 8) | *cp
++;
179 gateways
< (int)egp
->egp_intgw
? "int" : "ext",
180 ipaddr_string(&addr
));
184 while (--distances
>= 0) {
186 printf("%sd%d:", comma
, (int)*cp
++);
189 while (--networks
>= 0) {
190 /* Pickup network number */
192 addr
= (u_int32_t
)*cp
++ << 24;
193 if (IN_CLASSB(addr
)) {
195 addr
|= (u_int32_t
)*cp
++ << 16;
196 } else if (!IN_CLASSA(addr
)) {
198 addr
|= (u_int32_t
)*cp
++ << 16;
199 addr
|= (u_int32_t
)*cp
++ << 8;
201 printf(" %s", ipaddr_string(&addr
));
208 fputs("[|]", stdout
);
212 egp_print(register const u_int8_t
*bp
, register u_int length
)
214 register const struct egp_packet
*egp
;
219 egp
= (struct egp_packet
*)bp
;
220 if (!TTEST2(*egp
, length
)) {
226 printf("EGPv%u, AS %u, seq %u, length %u",
228 EXTRACT_16BITS(&egp
->egp_as
),
229 EXTRACT_16BITS(&egp
->egp_sequence
),
233 printf("EGPv%u, length %u",
237 if (egp
->egp_version
!= EGP_VERSION
) {
238 printf("[version %d]", egp
->egp_version
);
242 type
= egp
->egp_type
;
243 code
= egp
->egp_code
;
244 status
= egp
->egp_status
;
252 printf(" %s", egp_acquire_codes
[code
]);
257 printf(" %s", egp_acquire_status
[status
]);
261 printf(" [status %d]", status
);
264 printf(" hello:%d poll:%d",
265 EXTRACT_16BITS(&egp
->egp_hello
),
266 EXTRACT_16BITS(&egp
->egp_poll
));
272 printf(" %s", egp_acquire_codes
[code
]);
280 printf(" %s", egp_acquire_status
[status
]);
284 printf("[status %d]", status
);
290 printf("[code %d]", code
);
300 printf(" %s", egp_reach_codes
[code
]);
301 if (status
<= EGPS_DOWN
)
302 printf(" state:%s", egp_status_updown
[status
]);
304 printf(" [status %d]", status
);
308 printf("[reach code %d]", code
);
315 if (egp
->egp_status
<= EGPS_DOWN
)
316 printf(" state:%s", egp_status_updown
[status
]);
318 printf(" [status %d]", status
);
319 printf(" net:%s", ipaddr_string(&egp
->egp_sourcenet
));
324 if (status
& EGPS_UNSOL
) {
325 status
&= ~EGPS_UNSOL
;
326 printf(" unsolicited");
328 if (status
<= EGPS_DOWN
)
329 printf(" state:%s", egp_status_updown
[status
]);
331 printf(" [status %d]", status
);
332 printf(" %s int %d ext %d",
333 ipaddr_string(&egp
->egp_sourcenet
),
342 if (status
<= EGPS_DOWN
)
343 printf(" state:%s", egp_status_updown
[status
]);
345 printf(" [status %d]", status
);
347 if (EXTRACT_16BITS(&egp
->egp_reason
) <= EGPR_UVERSION
)
348 printf(" %s", egp_reasons
[EXTRACT_16BITS(&egp
->egp_reason
)]);
350 printf(" [reason %d]", EXTRACT_16BITS(&egp
->egp_reason
));
354 printf("[type %d]", type
);