]> The Tcpdump Group git mirrors - tcpdump/blob - print-ppp.c
4a84fc955452972a161d128c5aee6e7e5d902f34
[tcpdump] / print-ppp.c
1 /*
2 * Copyright (c) 1990, 1991, 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/print-ppp.c,v 1.26 1999-10-07 23:47:12 mcr Exp $ (LBL)";
25 #endif
26
27 #include <sys/param.h>
28 #include <sys/time.h>
29 #include <sys/socket.h>
30 #include <sys/file.h>
31 #include <sys/ioctl.h>
32
33 #if __STDC__
34 struct mbuf;
35 struct rtentry;
36 #endif
37 #include <net/if.h>
38
39 #include <netinet/in.h>
40 #include <netinet/in_systm.h>
41 #include <netinet/ip.h>
42
43 #include <ctype.h>
44 #include <netdb.h>
45 #include <pcap.h>
46 #include <stdio.h>
47
48 #include "interface.h"
49 #include "addrtoname.h"
50 #include "ppp.h"
51
52 /* XXX This goes somewhere else. */
53 #define PPP_HDRLEN 4
54
55 /* Standard PPP printer */
56 void
57 ppp_if_print(u_char *user, const struct pcap_pkthdr *h,
58 register const u_char *p)
59 {
60 register u_int length = h->len;
61 register u_int caplen = h->caplen;
62 const struct ip *ip;
63
64 ts_print(&h->ts);
65
66 if (caplen < PPP_HDRLEN) {
67 printf("[|ppp]");
68 goto out;
69 }
70
71 /*
72 * Some printers want to get back at the link level addresses,
73 * and/or check that they're not walking off the end of the packet.
74 * Rather than pass them all the way down, we set these globals.
75 */
76 packetp = p;
77 snapend = p + caplen;
78
79 if (eflag)
80 printf("%c %4d %02x %04x: ", p[0] ? 'O' : 'I', length,
81 p[1], ntohs(*(u_short *)&p[2]));
82
83 length -= PPP_HDRLEN;
84 ip = (struct ip *)(p + PPP_HDRLEN);
85 ip_print((const u_char *)ip, length);
86
87 if (xflag)
88 default_print((const u_char *)ip, caplen - PPP_HDRLEN);
89 out:
90 putchar('\n');
91 }
92
93 /* proto type to string mapping */
94 static struct tok ptype2str[] = {
95 { PPP_VJC, "VJC" },
96 { PPP_VJNC, "VJNC" },
97 { PPP_OSI, "OSI" },
98 { PPP_LCP, "LCP" },
99 { PPP_IPCP, "IPCP" },
100 { 0, NULL }
101 };
102
103 #define PPP_BSDI_HDRLEN 24
104
105 /* BSD/OS specific PPP printer */
106 void
107 ppp_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h,
108 register const u_char *p)
109 {
110 register u_int length = h->len;
111 register u_int caplen = h->caplen;
112 register int hdrlength;
113 u_short ptype;
114
115 ts_print(&h->ts);
116
117 if (caplen < PPP_BSDI_HDRLEN) {
118 printf("[|ppp]");
119 goto out;
120 }
121
122 /*
123 * Some printers want to get back at the link level addresses,
124 * and/or check that they're not walking off the end of the packet.
125 * Rather than pass them all the way down, we set these globals.
126 */
127 packetp = p;
128 snapend = p + caplen;
129 hdrlength = 0;
130
131 if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) {
132 if (eflag)
133 printf("%02x %02x ", p[0], p[1]);
134 p += 2;
135 hdrlength = 2;
136 }
137
138 if (eflag)
139 printf("%d ", length);
140 /* Retrieve the protocol type */
141 if (*p & 01) {
142 /* Compressed protocol field */
143 ptype = *p;
144 if (eflag)
145 printf("%02x ", ptype);
146 p++;
147 hdrlength += 1;
148 } else {
149 /* Un-compressed protocol field */
150 ptype = ntohs(*(u_short *)p);
151 if (eflag)
152 printf("%04x ", ptype);
153 p += 2;
154 hdrlength += 2;
155 }
156
157 length -= hdrlength;
158
159 if (ptype == PPP_IP)
160 ip_print(p, length);
161 else
162 printf("%s ", tok2str(ptype2str, "proto-#%d", ptype));
163
164 if (xflag)
165 default_print((const u_char *)p, caplen - hdrlength);
166 out:
167 putchar('\n');
168 }