]>
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).
22 static const char rcsid
[] =
23 "@(#) $Header: /tcpdump/master/tcpdump/print-egp.c,v 1.33 2002-11-09 17:19:25 itojun Exp $ (LBL)";
30 #include <tcpdump-stdinc.h>
34 #include "interface.h"
35 #include "addrtoname.h"
43 #define EGPT_ACQUIRE 3
49 #define EGPC_REQUEST 0
50 #define EGPC_CONFIRM 1
53 #define EGPC_CEASEACK 4
59 #define EGPS_PASSIVE 2
68 #define EGPS_UNSOL 0x80
69 u_int16_t egp_checksum
;
71 u_int16_t egp_sequence
;
75 u_int16_t egpu_reason
;
77 #define EGPR_BADHEAD 1
78 #define EGPR_BADDATA 2
79 #define EGPR_NOREACH 3
82 #define EGPR_UVERSION 6
84 #define egp_hello egp_handg.egpu_hello
85 #define egp_intgw egp_handg.egpu_gws[0]
86 #define egp_extgw egp_handg.egpu_gws[1]
87 #define egp_reason egp_handg.egpu_reason
90 u_int32_t egpu_sourcenet
;
92 #define egp_poll egp_pands.egpu_poll
93 #define egp_sourcenet egp_pands.egpu_sourcenet
94 } __attribute__((packed
));
96 const char *egp_acquire_codes
[] = {
104 const char *egp_acquire_status
[] = {
108 "insufficient_resources",
109 "administratively_prohibited",
111 "parameter_violation",
115 const char *egp_reach_codes
[] = {
120 const char *egp_status_updown
[] = {
126 const char *egp_reasons
[] = {
128 "bad_EGP_header_format",
129 "bad_EGP_data_field_format",
130 "reachability_info_unavailable",
131 "excessive_polling_rate",
133 "unsupported_version"
137 egpnrprint(register const struct egp_packet
*egp
)
139 register const u_int8_t
*cp
;
141 register u_int32_t net
;
142 register u_int netlen
;
143 int gateways
, distances
, networks
;
147 addr
= egp
->egp_sourcenet
;
148 if (IN_CLASSA(addr
)) {
149 net
= addr
& IN_CLASSA_NET
;
151 } else if (IN_CLASSB(addr
)) {
152 net
= addr
& IN_CLASSB_NET
;
154 } else if (IN_CLASSC(addr
)) {
155 net
= addr
& IN_CLASSC_NET
;
161 cp
= (u_int8_t
*)(egp
+ 1);
163 t_gateways
= egp
->egp_intgw
+ egp
->egp_extgw
;
164 for (gateways
= 0; gateways
< t_gateways
; ++gateways
) {
165 /* Pickup host part of gateway address */
167 TCHECK2(cp
[0], 4 - netlen
);
174 addr
= (addr
<< 8) | *cp
++;
177 addr
= (addr
<< 8) | *cp
++;
183 gateways
< (int)egp
->egp_intgw
? "int" : "ext",
184 ipaddr_string(&addr
));
188 while (--distances
>= 0) {
190 printf("%sd%d:", comma
, (int)*cp
++);
193 while (--networks
>= 0) {
194 /* Pickup network number */
196 addr
= (u_int32_t
)*cp
++ << 24;
197 if (IN_CLASSB(addr
)) {
199 addr
|= (u_int32_t
)*cp
++ << 16;
200 } else if (!IN_CLASSA(addr
)) {
202 addr
|= (u_int32_t
)*cp
++ << 16;
203 addr
|= (u_int32_t
)*cp
++ << 8;
205 printf(" %s", ipaddr_string(&addr
));
212 fputs("[|]", stdout
);
216 egp_print(register const u_int8_t
*bp
)
218 register const struct egp_packet
*egp
;
223 egp
= (struct egp_packet
*)bp
;
228 (void)printf("egp: ");
230 if (egp
->egp_version
!= EGP_VERSION
) {
231 printf("[version %d]", egp
->egp_version
);
234 printf("as:%d seq:%d", ntohs(egp
->egp_as
), ntohs(egp
->egp_sequence
));
236 type
= egp
->egp_type
;
237 code
= egp
->egp_code
;
238 status
= egp
->egp_status
;
246 printf(" %s", egp_acquire_codes
[code
]);
251 printf(" %s", egp_acquire_status
[status
]);
255 printf(" [status %d]", status
);
258 printf(" hello:%d poll:%d",
259 ntohs(egp
->egp_hello
),
260 ntohs(egp
->egp_poll
));
266 printf(" %s", egp_acquire_codes
[code
]);
274 printf(" %s", egp_acquire_status
[status
]);
278 printf("[status %d]", status
);
284 printf("[code %d]", code
);
294 printf(" %s", egp_reach_codes
[code
]);
295 if (status
<= EGPS_DOWN
)
296 printf(" state:%s", egp_status_updown
[status
]);
298 printf(" [status %d]", status
);
302 printf("[reach code %d]", code
);
309 if (egp
->egp_status
<= EGPS_DOWN
)
310 printf(" state:%s", egp_status_updown
[status
]);
312 printf(" [status %d]", status
);
313 printf(" net:%s", ipaddr_string(&egp
->egp_sourcenet
));
318 if (status
& EGPS_UNSOL
) {
319 status
&= ~EGPS_UNSOL
;
320 printf(" unsolicited");
322 if (status
<= EGPS_DOWN
)
323 printf(" state:%s", egp_status_updown
[status
]);
325 printf(" [status %d]", status
);
326 printf(" %s int %d ext %d",
327 ipaddr_string(&egp
->egp_sourcenet
),
336 if (status
<= EGPS_DOWN
)
337 printf(" state:%s", egp_status_updown
[status
]);
339 printf(" [status %d]", status
);
341 if (ntohs(egp
->egp_reason
) <= EGPR_UVERSION
)
342 printf(" %s", egp_reasons
[ntohs(egp
->egp_reason
)]);
344 printf(" [reason %d]", ntohs(egp
->egp_reason
));
348 printf("[type %d]", type
);