]>
The Tcpdump Group git mirrors - tcpdump/blob - print-egp.c
57eb0aa08c94764c6b7f016b9317df792a32cbef
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.29 2002-06-01 23:50:31 guy Exp $ (LBL)";
30 #include <sys/param.h>
32 #include <sys/socket.h>
34 #include <netinet/in.h>
39 #include "interface.h"
40 #include "addrtoname.h"
48 #define EGPT_ACQUIRE 3
54 #define EGPC_REQUEST 0
55 #define EGPC_CONFIRM 1
58 #define EGPC_CEASEACK 4
64 #define EGPS_PASSIVE 2
73 #define EGPS_UNSOL 0x80
82 #define EGPR_BADHEAD 1
83 #define EGPR_BADDATA 2
84 #define EGPR_NOREACH 3
87 #define EGPR_UVERSION 6
89 #define egp_hello egp_handg.egpu_hello
90 #define egp_intgw egp_handg.egpu_gws[0]
91 #define egp_extgw egp_handg.egpu_gws[1]
92 #define egp_reason egp_handg.egpu_reason
95 u_int32_t egpu_sourcenet
;
97 #define egp_poll egp_pands.egpu_poll
98 #define egp_sourcenet egp_pands.egpu_sourcenet
101 const char *egp_acquire_codes
[] = {
109 const char *egp_acquire_status
[] = {
113 "insufficient_resources",
114 "administratively_prohibited",
116 "parameter_violation",
120 const char *egp_reach_codes
[] = {
125 const char *egp_status_updown
[] = {
131 const char *egp_reasons
[] = {
133 "bad_EGP_header_format",
134 "bad_EGP_data_field_format",
135 "reachability_info_unavailable",
136 "excessive_polling_rate",
138 "unsupported_version"
142 egpnrprint(register const struct egp_packet
*egp
, register u_int length
)
144 register const u_char
*cp
;
146 register u_int32_t net
;
147 register u_int netlen
;
148 int gateways
, distances
, networks
;
152 addr
= egp
->egp_sourcenet
;
153 if (IN_CLASSA(addr
)) {
154 net
= addr
& IN_CLASSA_NET
;
156 } else if (IN_CLASSB(addr
)) {
157 net
= addr
& IN_CLASSB_NET
;
159 } else if (IN_CLASSC(addr
)) {
160 net
= addr
& IN_CLASSC_NET
;
166 cp
= (u_char
*)(egp
+ 1);
168 t_gateways
= egp
->egp_intgw
+ egp
->egp_extgw
;
169 for (gateways
= 0; gateways
< t_gateways
; ++gateways
) {
170 /* Pickup host part of gateway address */
172 TCHECK2(cp
[0], 4 - netlen
);
179 addr
= (addr
<< 8) | *cp
++;
182 addr
= (addr
<< 8) | *cp
++;
188 gateways
< (int)egp
->egp_intgw
? "int" : "ext",
189 ipaddr_string(&addr
));
193 while (--distances
>= 0) {
195 printf("%sd%d:", comma
, (int)*cp
++);
198 while (--networks
>= 0) {
199 /* Pickup network number */
201 addr
= (u_int32_t
)*cp
++ << 24;
202 if (IN_CLASSB(addr
)) {
204 addr
|= (u_int32_t
)*cp
++ << 16;
205 } else if (!IN_CLASSA(addr
)) {
207 addr
|= (u_int32_t
)*cp
++ << 16;
208 addr
|= (u_int32_t
)*cp
++ << 8;
210 printf(" %s", ipaddr_string(&addr
));
217 fputs("[|]", stdout
);
221 egp_print(register const u_char
*bp
, register u_int length
,
222 register const u_char
*bp2
)
224 register const struct egp_packet
*egp
;
225 register const struct ip
*ip
;
230 egp
= (struct egp_packet
*)bp
;
231 ip
= (struct ip
*)bp2
;
232 (void)printf("egp: ");
234 if (egp
->egp_version
!= EGP_VERSION
) {
235 printf("[version %d]", egp
->egp_version
);
238 printf("as:%d seq:%d", ntohs(egp
->egp_as
), ntohs(egp
->egp_sequence
));
240 type
= egp
->egp_type
;
241 code
= egp
->egp_code
;
242 status
= egp
->egp_status
;
250 printf(" %s", egp_acquire_codes
[code
]);
255 printf(" %s", egp_acquire_status
[status
]);
259 printf(" [status %d]", status
);
262 printf(" hello:%d poll:%d",
263 ntohs(egp
->egp_hello
),
264 ntohs(egp
->egp_poll
));
270 printf(" %s", egp_acquire_codes
[code
]);
278 printf(" %s", egp_acquire_status
[status
]);
282 printf("[status %d]", status
);
288 printf("[code %d]", code
);
298 printf(" %s", egp_reach_codes
[code
]);
299 if (status
<= EGPS_DOWN
)
300 printf(" state:%s", egp_status_updown
[status
]);
302 printf(" [status %d]", status
);
306 printf("[reach code %d]", code
);
313 if (egp
->egp_status
<= EGPS_DOWN
)
314 printf(" state:%s", egp_status_updown
[status
]);
316 printf(" [status %d]", status
);
317 printf(" net:%s", ipaddr_string(&egp
->egp_sourcenet
));
322 if (status
& EGPS_UNSOL
) {
323 status
&= ~EGPS_UNSOL
;
324 printf(" unsolicited");
326 if (status
<= EGPS_DOWN
)
327 printf(" state:%s", egp_status_updown
[status
]);
329 printf(" [status %d]", status
);
330 printf(" %s int %d ext %d",
331 ipaddr_string(&egp
->egp_sourcenet
),
335 egpnrprint(egp
, length
);
340 if (status
<= EGPS_DOWN
)
341 printf(" state:%s", egp_status_updown
[status
]);
343 printf(" [status %d]", status
);
345 if (ntohs(egp
->egp_reason
) <= EGPR_UVERSION
)
346 printf(" %s", egp_reasons
[ntohs(egp
->egp_reason
)]);
348 printf(" [reason %d]", ntohs(egp
->egp_reason
));
352 printf("[type %d]", type
);