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