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