]>
git.saurik.com Git - apple/network_cmds.git/blob - tcpdump.tproj/print-egp.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms are permitted
29 * provided that the above copyright notice and this paragraph are
30 * duplicated in all such forms and that any documentation,
31 * advertising materials, and other materials related to such
32 * distribution and use acknowledge that the software was developed
33 * by the University of California, Lawrence Berkeley Laboratory,
34 * Berkeley, CA. The name of the University may not be used to
35 * endorse or promote products derived from this software without
36 * specific prior written permission.
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
38 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
39 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
41 * Initial contribution from Jeff Honig (jch@MITCHELL.CIT.CORNELL.EDU).
45 static const char rcsid
[] =
46 "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-egp.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)";
49 #include <sys/param.h>
52 #include <sys/socket.h>
54 #include <netinet/in.h>
55 #include <netinet/in_systm.h>
56 #include <netinet/ip.h>
61 #include "interface.h"
62 #include "addrtoname.h"
68 #define EGPT_ACQUIRE 3
74 #define EGPC_REQUEST 0
75 #define EGPC_CONFIRM 1
78 #define EGPC_CEASEACK 4
84 #define EGPS_PASSIVE 2
93 #define EGPS_UNSOL 0x80
101 #define EGPR_UNSPEC 0
102 #define EGPR_BADHEAD 1
103 #define EGPR_BADDATA 2
104 #define EGPR_NOREACH 3
105 #define EGPR_XSPOLL 4
106 #define EGPR_NORESP 5
107 #define EGPR_UVERSION 6
109 #define egp_hello egp_handg.egpu_hello
110 #define egp_intgw egp_handg.egpu_gws[0]
111 #define egp_extgw egp_handg.egpu_gws[1]
112 #define egp_reason egp_handg.egpu_reason
115 u_int32_t egpu_sourcenet
;
117 #define egp_poll egp_pands.egpu_poll
118 #define egp_sourcenet egp_pands.egpu_sourcenet
121 char *egp_acquire_codes
[] = {
129 char *egp_acquire_status
[] = {
133 "insufficient_resources",
134 "administratively_prohibited",
136 "parameter_violation",
140 char *egp_reach_codes
[] = {
145 char *egp_status_updown
[] = {
151 char *egp_reasons
[] = {
153 "bad_EGP_header_format",
154 "bad_EGP_data_field_format",
155 "reachability_info_unavailable",
156 "excessive_polling_rate",
158 "unsupported_version"
162 egpnrprint(register const struct egp_packet
*egp
, register u_int length
)
164 register const u_char
*cp
;
166 register u_int32_t net
;
167 register u_int netlen
;
168 int gateways
, distances
, networks
;
172 addr
= egp
->egp_sourcenet
;
173 if (IN_CLASSA(addr
)) {
174 net
= addr
& IN_CLASSA_NET
;
176 } else if (IN_CLASSB(addr
)) {
177 net
= addr
& IN_CLASSB_NET
;
179 } else if (IN_CLASSC(addr
)) {
180 net
= addr
& IN_CLASSC_NET
;
186 cp
= (u_char
*)(egp
+ 1);
188 t_gateways
= egp
->egp_intgw
+ egp
->egp_extgw
;
189 for (gateways
= 0; gateways
< t_gateways
; ++gateways
) {
190 /* Pickup host part of gateway address */
192 TCHECK2(cp
[0], 4 - netlen
);
199 addr
= (addr
<< 8) | *cp
++;
202 addr
= (addr
<< 8) | *cp
++;
208 gateways
< (int)egp
->egp_intgw
? "int" : "ext",
209 ipaddr_string(&addr
));
213 while (--distances
>= 0) {
215 printf("%sd%d:", comma
, (int)*cp
++);
218 while (--networks
>= 0) {
219 /* Pickup network number */
221 addr
= (u_int32_t
)*cp
++ << 24;
222 if (IN_CLASSB(addr
)) {
224 addr
|= (u_int32_t
)*cp
++ << 16;
225 } else if (!IN_CLASSA(addr
)) {
227 addr
|= (u_int32_t
)*cp
++ << 16;
228 addr
|= (u_int32_t
)*cp
++ << 8;
230 printf(" %s", ipaddr_string(&addr
));
237 fputs("[|]", stdout
);
241 egp_print(register const u_char
*bp
, register u_int length
,
242 register const u_char
*bp2
)
244 register const struct egp_packet
*egp
;
245 register const struct ip
*ip
;
250 egp
= (struct egp_packet
*)bp
;
251 ip
= (struct ip
*)bp2
;
252 (void)printf("%s > %s: egp: ",
253 ipaddr_string(&ip
->ip_src
),
254 ipaddr_string(&ip
->ip_dst
));
256 if (egp
->egp_version
!= EGP_VERSION
) {
257 printf("[version %d]", egp
->egp_version
);
260 printf("as:%d seq:%d", ntohs(egp
->egp_as
), ntohs(egp
->egp_sequence
));
262 type
= egp
->egp_type
;
263 code
= egp
->egp_code
;
264 status
= egp
->egp_status
;
272 printf(" %s", egp_acquire_codes
[code
]);
277 printf(" %s", egp_acquire_status
[status
]);
281 printf(" [status %d]", status
);
284 printf(" hello:%d poll:%d",
285 ntohs(egp
->egp_hello
),
286 ntohs(egp
->egp_poll
));
292 printf(" %s", egp_acquire_codes
[code
]);
300 printf(" %s", egp_acquire_status
[status
]);
304 printf("[status %d]", status
);
310 printf("[code %d]", code
);
320 printf(" %s", egp_reach_codes
[code
]);
321 if (status
<= EGPS_DOWN
)
322 printf(" state:%s", egp_status_updown
[status
]);
324 printf(" [status %d]", status
);
328 printf("[reach code %d]", code
);
335 if (egp
->egp_status
<= EGPS_DOWN
)
336 printf(" state:%s", egp_status_updown
[status
]);
338 printf(" [status %d]", status
);
339 printf(" net:%s", ipaddr_string(&egp
->egp_sourcenet
));
344 if (status
& EGPS_UNSOL
) {
345 status
&= ~EGPS_UNSOL
;
346 printf(" unsolicited");
348 if (status
<= EGPS_DOWN
)
349 printf(" state:%s", egp_status_updown
[status
]);
351 printf(" [status %d]", status
);
352 printf(" %s int %d ext %d",
353 ipaddr_string(&egp
->egp_sourcenet
),
357 egpnrprint(egp
, length
);
362 if (status
<= EGPS_DOWN
)
363 printf(" state:%s", egp_status_updown
[status
]);
365 printf(" [status %d]", status
);
367 if (ntohs(egp
->egp_reason
) <= EGPR_UVERSION
)
368 printf(" %s", egp_reasons
[ntohs(egp
->egp_reason
)]);
370 printf(" [reason %d]", ntohs(egp
->egp_reason
));
374 printf("[type %d]", type
);