]>
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.23 1999-10-07 23:47:11 mcr Exp $ (LBL)";
26 #include <sys/param.h>
29 #include <sys/socket.h>
31 #include <netinet/in.h>
32 #include <netinet/in_systm.h>
33 #include <netinet/ip.h>
38 #include "interface.h"
39 #include "addrtoname.h"
45 #define EGPT_ACQUIRE 3
51 #define EGPC_REQUEST 0
52 #define EGPC_CONFIRM 1
55 #define EGPC_CEASEACK 4
61 #define EGPS_PASSIVE 2
70 #define EGPS_UNSOL 0x80
79 #define EGPR_BADHEAD 1
80 #define EGPR_BADDATA 2
81 #define EGPR_NOREACH 3
84 #define EGPR_UVERSION 6
86 #define egp_hello egp_handg.egpu_hello
87 #define egp_intgw egp_handg.egpu_gws[0]
88 #define egp_extgw egp_handg.egpu_gws[1]
89 #define egp_reason egp_handg.egpu_reason
92 u_int32_t egpu_sourcenet
;
94 #define egp_poll egp_pands.egpu_poll
95 #define egp_sourcenet egp_pands.egpu_sourcenet
98 char *egp_acquire_codes
[] = {
106 char *egp_acquire_status
[] = {
110 "insufficient_resources",
111 "administratively_prohibited",
113 "parameter_violation",
117 char *egp_reach_codes
[] = {
122 char *egp_status_updown
[] = {
128 char *egp_reasons
[] = {
130 "bad_EGP_header_format",
131 "bad_EGP_data_field_format",
132 "reachability_info_unavailable",
133 "excessive_polling_rate",
135 "unsupported_version"
139 egpnrprint(register const struct egp_packet
*egp
, register u_int length
)
141 register const u_char
*cp
;
143 register u_int32_t net
;
144 register u_int netlen
;
145 int gateways
, distances
, networks
;
149 addr
= egp
->egp_sourcenet
;
150 if (IN_CLASSA(addr
)) {
151 net
= addr
& IN_CLASSA_NET
;
153 } else if (IN_CLASSB(addr
)) {
154 net
= addr
& IN_CLASSB_NET
;
156 } else if (IN_CLASSC(addr
)) {
157 net
= addr
& IN_CLASSC_NET
;
163 cp
= (u_char
*)(egp
+ 1);
165 t_gateways
= egp
->egp_intgw
+ egp
->egp_extgw
;
166 for (gateways
= 0; gateways
< t_gateways
; ++gateways
) {
167 /* Pickup host part of gateway address */
169 TCHECK2(cp
[0], 4 - netlen
);
176 addr
= (addr
<< 8) | *cp
++;
179 addr
= (addr
<< 8) | *cp
++;
185 gateways
< (int)egp
->egp_intgw
? "int" : "ext",
186 ipaddr_string(&addr
));
190 while (--distances
>= 0) {
192 printf("%sd%d:", comma
, (int)*cp
++);
195 while (--networks
>= 0) {
196 /* Pickup network number */
198 addr
= (u_int32_t
)*cp
++ << 24;
199 if (IN_CLASSB(addr
)) {
201 addr
|= (u_int32_t
)*cp
++ << 16;
202 } else if (!IN_CLASSA(addr
)) {
204 addr
|= (u_int32_t
)*cp
++ << 16;
205 addr
|= (u_int32_t
)*cp
++ << 8;
207 printf(" %s", ipaddr_string(&addr
));
214 fputs("[|]", stdout
);
218 egp_print(register const u_char
*bp
, register u_int length
,
219 register const u_char
*bp2
)
221 register const struct egp_packet
*egp
;
222 register const struct ip
*ip
;
227 egp
= (struct egp_packet
*)bp
;
228 ip
= (struct ip
*)bp2
;
229 (void)printf("%s > %s: egp: ",
230 ipaddr_string(&ip
->ip_src
),
231 ipaddr_string(&ip
->ip_dst
));
233 if (egp
->egp_version
!= EGP_VERSION
) {
234 printf("[version %d]", egp
->egp_version
);
237 printf("as:%d seq:%d", ntohs(egp
->egp_as
), ntohs(egp
->egp_sequence
));
239 type
= egp
->egp_type
;
240 code
= egp
->egp_code
;
241 status
= egp
->egp_status
;
249 printf(" %s", egp_acquire_codes
[code
]);
254 printf(" %s", egp_acquire_status
[status
]);
258 printf(" [status %d]", status
);
261 printf(" hello:%d poll:%d",
262 ntohs(egp
->egp_hello
),
263 ntohs(egp
->egp_poll
));
269 printf(" %s", egp_acquire_codes
[code
]);
277 printf(" %s", egp_acquire_status
[status
]);
281 printf("[status %d]", status
);
287 printf("[code %d]", code
);
297 printf(" %s", egp_reach_codes
[code
]);
298 if (status
<= EGPS_DOWN
)
299 printf(" state:%s", egp_status_updown
[status
]);
301 printf(" [status %d]", status
);
305 printf("[reach code %d]", code
);
312 if (egp
->egp_status
<= EGPS_DOWN
)
313 printf(" state:%s", egp_status_updown
[status
]);
315 printf(" [status %d]", status
);
316 printf(" net:%s", ipaddr_string(&egp
->egp_sourcenet
));
321 if (status
& EGPS_UNSOL
) {
322 status
&= ~EGPS_UNSOL
;
323 printf(" unsolicited");
325 if (status
<= EGPS_DOWN
)
326 printf(" state:%s", egp_status_updown
[status
]);
328 printf(" [status %d]", status
);
329 printf(" %s int %d ext %d",
330 ipaddr_string(&egp
->egp_sourcenet
),
334 egpnrprint(egp
, length
);
339 if (status
<= EGPS_DOWN
)
340 printf(" state:%s", egp_status_updown
[status
]);
342 printf(" [status %d]", status
);
344 if (ntohs(egp
->egp_reason
) <= EGPR_UVERSION
)
345 printf(" %s", egp_reasons
[ntohs(egp
->egp_reason
)]);
347 printf(" [reason %d]", ntohs(egp
->egp_reason
));
351 printf("[type %d]", type
);