]>
The Tcpdump Group git mirrors - tcpdump/blob - print-pppoe.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/print-pppoe.c,v 1.14 2001-06-20 07:40:44 guy Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
35 #include <netinet/in.h>
40 #include "interface.h"
41 #include "addrtoname.h"
43 #include "ethertype.h"
45 #include "extract.h" /* must come after interface.h */
56 static struct tok pppoecode2str
[] = {
57 { PPPOE_PADI
, "PADI" },
58 { PPPOE_PADO
, "PADO" },
59 { PPPOE_PADR
, "PADR" },
60 { PPPOE_PADS
, "PADS" },
61 { PPPOE_PADT
, "PADT" },
62 { 0, "" }, /* PPP Data */
69 PPPOE_SERVICE_NAME
= 0x0101,
70 PPPOE_AC_NAME
= 0x0102,
71 PPPOE_HOST_UNIQ
= 0x0103,
72 PPPOE_AC_COOKIE
= 0x0104,
73 PPPOE_VENDOR
= 0x0105,
74 PPPOE_RELAY_SID
= 0x0110,
75 PPPOE_SERVICE_NAME_ERROR
= 0x0201,
76 PPPOE_AC_SYSTEM_ERROR
= 0x0202,
77 PPPOE_GENERIC_ERROR
= 0x0203
80 static struct tok pppoetag2str
[] = {
82 { PPPOE_SERVICE_NAME
, "Service-Name" },
83 { PPPOE_AC_NAME
, "AC-Name" },
84 { PPPOE_HOST_UNIQ
, "Host-Uniq" },
85 { PPPOE_AC_COOKIE
, "AC-Cookie" },
86 { PPPOE_VENDOR
, "Vendor-Specific" },
87 { PPPOE_RELAY_SID
, "Relay-Session-ID" },
88 { PPPOE_SERVICE_NAME_ERROR
, "Service-Name-Error" },
89 { PPPOE_AC_SYSTEM_ERROR
, "AC-System-Error" },
90 { PPPOE_GENERIC_ERROR
, "Generic-Error" },
94 #define PPPOE_HDRLEN 6
97 pppoe_if_print(u_char
*user
, const struct pcap_pkthdr
*h
,
98 register const u_char
*p
)
100 register u_int length
= h
->len
;
101 register u_int caplen
= h
->caplen
;
106 * Some printers want to get back at the link level addresses,
107 * and/or check that they're not walking off the end of the packet.
108 * Rather than pass them all the way down, we set these globals.
111 snapend
= p
+ caplen
;
113 pppoe_print(p
, length
);
117 pppoe_print(register const u_char
*bp
, u_int length
)
119 u_short pppoe_ver
, pppoe_type
, pppoe_code
, pppoe_sessionid
, pppoe_length
;
120 const u_char
*pppoe_packet
, *pppoe_payload
;
123 if (pppoe_packet
> snapend
) {
128 pppoe_ver
= (pppoe_packet
[0] & 0xF0) >> 4;
129 pppoe_type
= (pppoe_packet
[0] & 0x0F);
130 pppoe_code
= pppoe_packet
[1];
131 pppoe_sessionid
= EXTRACT_16BITS(pppoe_packet
+ 2);
132 pppoe_length
= EXTRACT_16BITS(pppoe_packet
+ 4);
133 pppoe_payload
= pppoe_packet
+ PPPOE_HDRLEN
;
135 if (snapend
< pppoe_payload
) {
136 printf(" truncated PPPoE");
140 if (pppoe_ver
!= 1) {
141 printf(" [ver %d]",pppoe_ver
);
143 if (pppoe_type
!= 1) {
144 printf(" [type %d]",pppoe_type
);
147 printf("PPPoE %s", tok2str(pppoecode2str
, "PAD-%x", pppoe_code
));
148 if (pppoe_code
== PPPOE_PADI
&& pppoe_length
> 1484 - PPPOE_HDRLEN
) {
149 printf(" [len %d!]",pppoe_length
);
151 if (pppoe_sessionid
) {
152 printf(" [ses 0x%x]", pppoe_sessionid
);
155 if (pppoe_payload
+ pppoe_length
< snapend
) {
157 const u_char
*x
= pppoe_payload
+ pppoe_length
;
158 printf(" [length %d (%d extra bytes)]",
159 pppoe_length
, snapend
- pppoe_payload
- pppoe_length
);
160 default_print(x
, snapend
- x
);
162 snapend
= pppoe_payload
+pppoe_length
;
166 /* PPP session packets don't contain tags */
167 u_short tag_type
= 0xffff, tag_len
;
168 const u_char
*p
= pppoe_payload
;
172 * p points to next tag,
173 * tag_type is previous tag or 0xffff for first iteration
175 while (tag_type
&& p
+ 4 < pppoe_payload
+ length
&&
177 tag_type
= EXTRACT_16BITS(p
);
178 tag_len
= EXTRACT_16BITS(p
+ 2);
180 /* p points to tag_value */
187 for (v
= p
; v
< p
+ tag_len
; v
++)
188 if (*v
>= 127 || *v
< 32) {
193 /* TODO print UTF8 decoded text */
195 l
= (tag_len
< 80 ? tag_len
: 80);
196 printf(" [%s \"%*.*s\"]",
197 tok2str(pppoetag2str
, "TAG-0x%x", tag_type
),
201 tok2str(pppoetag2str
, "TAG-0x%x", tag_type
));
203 printf(" [%s]", tok2str(pppoetag2str
,
204 "TAG-0x%x", tag_type
));
207 /* p points to next tag */
211 ppp_print(pppoe_payload
, pppoe_length
);