]>
The Tcpdump Group git mirrors - tcpdump/blob - print-lcp.c
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static const char rcsid
[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/Attic/print-lcp.c,v 1.6 2000-07-01 03:39:06 assar Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <netinet/if_ether.h>
45 #include "interface.h"
46 #include "addrtoname.h"
47 #include "extract.h" /* must come after interface.h */
65 static struct tok lcpcode2str
[] = {
66 { LCP_CONFREQ
, "ConfReq" },
67 { LCP_CONFACK
, "ConfAck" },
68 { LCP_CONFNAK
, "ConfNak" },
69 { LCP_CONFREJ
, "ConfRej" },
70 { LCP_TERMREQ
, "TermReq" },
71 { LCP_TERMACK
, "TermAck" },
72 { LCP_CODEREJ
, "CodeRej" },
73 { LCP_PROTREJ
, "ProtRej" },
74 { LCP_ECHOREQ
, "EchoReq" },
75 { LCP_ECHOREP
, "EchoRep" },
76 { LCP_DISCARD
, "Discard" },
93 static struct tok lcpoption2str
[] = {
94 { LCP_RESERVED
, "reserved"},
96 { LCP_ASYNCMAP
, "asyncmap"},
97 { LCP_AUTHPROTO
, "auth"},
98 { LCP_QUALPROTO
, "qual"},
99 { LCP_MAGICNUM
, "magic"},
100 { LCP_PCOMP
, "pcomp"},
101 { LCP_ACFCOMP
, "acfcomp"},
102 { LCP_CALLBACK
, "callback"},
106 static struct tok lcpauth2str
[] = {
112 static struct tok lcpqual2str
[] = {
117 static struct tok lcpchap2str
[] = {
124 lcp_print(register const u_char
*bp
, u_int length
)
126 u_short lcp_code
, lcp_id
, lcp_length
;
127 const u_char
*lcp_data
;
131 if (snapend
< lcp_data
) {
138 lcp_length
= EXTRACT_16BITS(bp
+2);
140 printf("LCP %s id=0x%x", tok2str(lcpcode2str
, "LCP-#%d", lcp_code
), lcp_id
);
149 u_char lcpopt_type
, lcpopt_length
;
150 const u_char
*p
=lcp_data
;
151 while (p
+2 < lcp_data
+lcp_length
&& p
+2 < snapend
) {
153 lcpopt_length
= p
[1];
155 printf(" <%s ",tok2str(lcpoption2str
, "option-#%d", lcpopt_type
));
157 switch (lcpopt_type
) {
159 if (snapend
< p
+2) return;
160 printf("%d",ntohs(*(u_short
*)p
));
161 if (lcpopt_length
!= 4) printf(" len=%d!",lcpopt_length
);
164 if (snapend
< p
+2) return;
165 printf("%s",tok2str(lcpauth2str
, "AUTH-%#x", ntohs(*(u_short
*)p
)));
166 if (lcpopt_length
< 4) printf(" len=%d!",lcpopt_length
);
167 if (lcpopt_length
>= 5 && p
< snapend
)
168 printf(" %s",tok2str(lcpchap2str
, "%#x", p
[0]));
171 if (snapend
< p
+2) return;
172 printf("%s",tok2str(lcpqual2str
, "QUAL-%#x", ntohs(*(u_short
*)p
)));
173 if (lcpopt_length
< 4) printf(" len=%d!",lcpopt_length
);
174 /* Print data field of auth? */
178 if (snapend
< p
+4) return;
179 printf("%#x", (unsigned)ntohl(*(u_long
*)p
));
180 if (lcpopt_length
!= 6) printf(" len=%d!",lcpopt_length
);
185 if (lcpopt_length
!= 2) printf(" len=%d!",lcpopt_length
);
188 if (lcpopt_length
!= 2) printf(" len=%d",lcpopt_length
);
199 if (snapend
< lcp_data
+4) return;
200 printf(" magic=%#x", (unsigned)ntohl(*(u_long
*) lcp_data
));
204 if (snapend
< lcp_data
+2) return;
205 printf(" prot=%s", tok2str(ppptype2str
, "PROT-%#x", ntohs(*(u_short
*) lcp_data
)));
206 /* TODO print rejected packet too ? */
209 if (snapend
< lcp_data
+4) return;
211 lcp_print(lcp_data
, (lcp_length
+lcp_data
> snapend
? snapend
-lcp_data
: lcp_length
));