4 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * Original code by Greg Stark <gsstark@mit.edu>
26 #include <sys/cdefs.h>
29 static const char rcsid
[] _U_
=
30 "@(#) Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.30.2.1 2005/04/26 19:48:56 guy Exp (LBL)";
32 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
40 #include <tcpdump-stdinc.h>
45 #include "interface.h"
46 #include "addrtoname.h"
48 #include "ethertype.h"
50 #include "extract.h" /* must come after interface.h */
61 static struct tok pppoecode2str
[] = {
62 { PPPOE_PADI
, "PADI" },
63 { PPPOE_PADO
, "PADO" },
64 { PPPOE_PADR
, "PADR" },
65 { PPPOE_PADS
, "PADS" },
66 { PPPOE_PADT
, "PADT" },
67 { 0, "" }, /* PPP Data */
74 PPPOE_SERVICE_NAME
= 0x0101,
75 PPPOE_AC_NAME
= 0x0102,
76 PPPOE_HOST_UNIQ
= 0x0103,
77 PPPOE_AC_COOKIE
= 0x0104,
78 PPPOE_VENDOR
= 0x0105,
79 PPPOE_RELAY_SID
= 0x0110,
80 PPPOE_SERVICE_NAME_ERROR
= 0x0201,
81 PPPOE_AC_SYSTEM_ERROR
= 0x0202,
82 PPPOE_GENERIC_ERROR
= 0x0203
85 static struct tok pppoetag2str
[] = {
87 { PPPOE_SERVICE_NAME
, "Service-Name" },
88 { PPPOE_AC_NAME
, "AC-Name" },
89 { PPPOE_HOST_UNIQ
, "Host-Uniq" },
90 { PPPOE_AC_COOKIE
, "AC-Cookie" },
91 { PPPOE_VENDOR
, "Vendor-Specific" },
92 { PPPOE_RELAY_SID
, "Relay-Session-ID" },
93 { PPPOE_SERVICE_NAME_ERROR
, "Service-Name-Error" },
94 { PPPOE_AC_SYSTEM_ERROR
, "AC-System-Error" },
95 { PPPOE_GENERIC_ERROR
, "Generic-Error" },
99 #define PPPOE_HDRLEN 6
100 #define MAXTAGPRINT 80
103 pppoe_if_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
105 return (pppoe_print(p
, h
->len
));
109 pppoe_print(register const u_char
*bp
, u_int length
)
111 u_int16_t pppoe_ver
, pppoe_type
, pppoe_code
, pppoe_sessionid
;
113 const u_char
*pppoe_packet
, *pppoe_payload
;
115 if (length
< PPPOE_HDRLEN
) {
116 (void)printf("truncated-pppoe %u", length
);
119 length
-= PPPOE_HDRLEN
;
121 TCHECK2(*pppoe_packet
, PPPOE_HDRLEN
);
122 pppoe_ver
= (pppoe_packet
[0] & 0xF0) >> 4;
123 pppoe_type
= (pppoe_packet
[0] & 0x0F);
124 pppoe_code
= pppoe_packet
[1];
125 pppoe_sessionid
= EXTRACT_16BITS(pppoe_packet
+ 2);
126 pppoe_length
= EXTRACT_16BITS(pppoe_packet
+ 4);
127 pppoe_payload
= pppoe_packet
+ PPPOE_HDRLEN
;
129 if (pppoe_ver
!= 1) {
130 printf(" [ver %d]",pppoe_ver
);
132 if (pppoe_type
!= 1) {
133 printf(" [type %d]",pppoe_type
);
136 printf("PPPoE %s", tok2str(pppoecode2str
, "PAD-%x", pppoe_code
));
137 if (pppoe_code
== PPPOE_PADI
&& pppoe_length
> 1484 - PPPOE_HDRLEN
) {
138 printf(" [len %u!]",pppoe_length
);
140 if (pppoe_length
> length
) {
141 printf(" [len %u > %u!]", pppoe_length
, length
);
142 pppoe_length
= length
;
144 if (pppoe_sessionid
) {
145 printf(" [ses 0x%x]", pppoe_sessionid
);
149 /* PPP session packets don't contain tags */
150 u_short tag_type
= 0xffff, tag_len
;
151 const u_char
*p
= pppoe_payload
;
155 * p points to current tag,
156 * tag_type is previous tag or 0xffff for first iteration
158 while (tag_type
&& p
< pppoe_payload
+ pppoe_length
) {
160 tag_type
= EXTRACT_16BITS(p
);
161 tag_len
= EXTRACT_16BITS(p
+ 2);
163 /* p points to tag_value */
166 unsigned isascii
= 0, isgarbage
= 0;
168 char tag_str
[MAXTAGPRINT
];
169 unsigned tag_str_len
= 0;
171 /* TODO print UTF-8 decoded text */
172 TCHECK2(*p
, tag_len
);
173 for (v
= p
; v
< p
+ tag_len
&& tag_str_len
< MAXTAGPRINT
-1; v
++)
174 if (*v
>= 32 && *v
< 127) {
175 tag_str
[tag_str_len
++] = *v
;
178 tag_str
[tag_str_len
++] = '.';
181 tag_str
[tag_str_len
] = 0;
183 if (isascii
> isgarbage
) {
184 printf(" [%s \"%*.*s\"]",
185 tok2str(pppoetag2str
, "TAG-0x%x", tag_type
),
190 /* Print hex, not fast to abuse printf but this doesn't get used much */
191 printf(" [%s 0x", tok2str(pppoetag2str
, "TAG-0x%x", tag_type
));
192 for (v
=p
; v
<p
+tag_len
; v
++) {
200 printf(" [%s]", tok2str(pppoetag2str
,
201 "TAG-0x%x", tag_type
));
204 /* p points to next tag */
210 return (PPPOE_HDRLEN
+ ppp_print(pppoe_payload
, pppoe_length
));
215 return (PPPOE_HDRLEN
);