]> The Tcpdump Group git mirrors - tcpdump/blob - print-lcp.c
ee0a3a49450070a1f5b6a6510ffcf234158ecc5b
[tcpdump] / print-lcp.c
1 /*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
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
16 * written permission.
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.
20 */
21
22 #ifndef lint
23 static const char rcsid[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/Attic/print-lcp.c,v 1.11 2002-08-01 08:53:17 risso Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <tcpdump-stdinc.h>
32
33 #include <stdio.h>
34 #include <string.h>
35
36 #include "interface.h"
37 #include "addrtoname.h"
38 #include "extract.h" /* must come after interface.h */
39 #include "ppp.h"
40
41 /* Codes */
42 enum {
43 LCP_CONFREQ = 1,
44 LCP_CONFACK = 2,
45 LCP_CONFNAK = 3,
46 LCP_CONFREJ = 4,
47 LCP_TERMREQ = 5,
48 LCP_TERMACK = 6,
49 LCP_CODEREJ = 7,
50 LCP_PROTREJ = 8,
51 LCP_ECHOREQ = 9,
52 LCP_ECHOREP = 10,
53 LCP_DISCARD = 11
54 };
55
56 static struct tok lcpcode2str[] = {
57 { LCP_CONFREQ, "ConfReq" },
58 { LCP_CONFACK, "ConfAck" },
59 { LCP_CONFNAK, "ConfNak" },
60 { LCP_CONFREJ, "ConfRej" },
61 { LCP_TERMREQ, "TermReq" },
62 { LCP_TERMACK, "TermAck" },
63 { LCP_CODEREJ, "CodeRej" },
64 { LCP_PROTREJ, "ProtRej" },
65 { LCP_ECHOREQ, "EchoReq" },
66 { LCP_ECHOREP, "EchoRep" },
67 { LCP_DISCARD, "Discard" },
68 { 0, NULL }
69 };
70
71
72 enum {
73 LCP_RESERVED = 0,
74 LCP_MRU = 1,
75 LCP_ASYNCMAP = 2,
76 LCP_AUTHPROTO = 3,
77 LCP_QUALPROTO = 4,
78 LCP_MAGICNUM = 5,
79 LCP_PCOMP = 7,
80 LCP_ACFCOMP = 8,
81 LCP_CALLBACK = 13
82 };
83
84 static struct tok lcpoption2str[] = {
85 { LCP_RESERVED, "reserved"},
86 { LCP_MRU, "mru"},
87 { LCP_ASYNCMAP, "asyncmap"},
88 { LCP_AUTHPROTO, "auth"},
89 { LCP_QUALPROTO, "qual"},
90 { LCP_MAGICNUM, "magic"},
91 { LCP_PCOMP, "pcomp"},
92 { LCP_ACFCOMP, "acfcomp"},
93 { LCP_CALLBACK, "callback"},
94 { 0, NULL }
95 };
96
97 static struct tok lcpauth2str[] = {
98 {0xc023, "PAP"},
99 {0xc223, "CHAP"},
100 { 0, NULL }
101 };
102
103 static struct tok lcpqual2str[] = {
104 {0xc025, "LQR"},
105 { 0, NULL }
106 };
107
108 static struct tok lcpchap2str[] = {
109 {0x05, "MD5"},
110 {0x80, "MS"},
111 { 0, NULL }
112 };
113
114 void
115 lcp_print(register const u_char *bp, u_int length)
116 {
117 u_short lcp_code, lcp_id, lcp_length;
118 const u_char *lcp_data;
119
120 lcp_data = bp+4;
121
122 if (snapend < lcp_data) {
123 printf(" [LCP|]");
124 return;
125 }
126
127 lcp_code = bp[0];
128 lcp_id = bp[1];
129 lcp_length = EXTRACT_16BITS(bp+2);
130
131 printf("LCP %s id=0x%x", tok2str(lcpcode2str, "LCP-#%d", lcp_code), lcp_id);
132
133 switch (lcp_code) {
134 case LCP_CONFREQ:
135 case LCP_CONFACK:
136 case LCP_CONFNAK:
137 case LCP_CONFREJ:
138 /* Print Options */
139 {
140 u_char lcpopt_type, lcpopt_length;
141 const u_char *p=lcp_data;
142 while (p+2 < lcp_data+lcp_length && p+2 < snapend) {
143 lcpopt_type = p[0];
144 lcpopt_length = p[1];
145 p+=2;
146 printf(" <%s ",tok2str(lcpoption2str, "option-#%d", lcpopt_type));
147 if (lcpopt_length)
148 switch (lcpopt_type) {
149 case LCP_MRU:
150 if (snapend < p+2) return;
151 printf("%d",ntohs(*(u_short*)p));
152 if (lcpopt_length != 4) printf(" len=%d!",lcpopt_length);
153 break;
154 case LCP_AUTHPROTO:
155 if (snapend < p+2) return;
156 printf("%s",tok2str(lcpauth2str, "AUTH-%#x", ntohs(*(u_short*)p)));
157 if (lcpopt_length < 4) printf(" len=%d!",lcpopt_length);
158 if (lcpopt_length >= 5 && p < snapend)
159 printf(" %s",tok2str(lcpchap2str, "%#x", p[0]));
160 break;
161 case LCP_QUALPROTO:
162 if (snapend < p+2) return;
163 printf("%s",tok2str(lcpqual2str, "QUAL-%#x", ntohs(*(u_short*)p)));
164 if (lcpopt_length < 4) printf(" len=%d!",lcpopt_length);
165 /* Print data field of auth? */
166 break;
167 case LCP_ASYNCMAP:
168 case LCP_MAGICNUM:
169 if (snapend < p+4) return;
170 printf("%#x", (unsigned)ntohl(*(u_long*)p));
171 if (lcpopt_length != 6) printf(" len=%d!",lcpopt_length);
172 break;
173 case LCP_PCOMP:
174 case LCP_ACFCOMP:
175 case LCP_RESERVED:
176 if (lcpopt_length != 2) printf(" len=%d!",lcpopt_length);
177 break;
178 default:
179 if (lcpopt_length != 2) printf(" len=%d",lcpopt_length);
180 break;
181 }
182 printf(">");
183 p+=lcpopt_length-2;
184 }
185 }
186 break;
187 case LCP_ECHOREQ:
188 case LCP_ECHOREP:
189 case LCP_DISCARD:
190 if (snapend < lcp_data+4) return;
191 printf(" magic=%#x", (unsigned)ntohl(*(u_long *) lcp_data));
192 lcp_data +=4;
193 break;
194 case LCP_PROTREJ:
195 if (snapend < lcp_data+2) return;
196 printf(" prot=%s", tok2str(ppptype2str, "PROT-%#x", ntohs(*(u_short *) lcp_data)));
197 /* TODO print rejected packet too ? */
198 break;
199 case LCP_CODEREJ:
200 if (snapend < lcp_data+4) return;
201 printf(" ");
202 lcp_print(lcp_data, (lcp_length+lcp_data > snapend ? snapend-lcp_data : lcp_length));
203 break;
204 case LCP_TERMREQ:
205 case LCP_TERMACK:
206 break;
207 default:
208 break;
209 }
210
211 return;
212 }