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.
21 * Original code by Greg Stark <gsstark@mit.edu>
25 static const char rcsid[] _U_ =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.31 2005-04-26 19:48:38 guy Exp $ (LBL)";
33 #include <tcpdump-stdinc.h>
38 #include "interface.h"
39 #include "addrtoname.h"
41 #include "ethertype.h"
43 #include "extract.h" /* must come after interface.h */
54 static struct tok pppoecode2str[] = {
55 { PPPOE_PADI, "PADI" },
56 { PPPOE_PADO, "PADO" },
57 { PPPOE_PADR, "PADR" },
58 { PPPOE_PADS, "PADS" },
59 { PPPOE_PADT, "PADT" },
60 { 0, "" }, /* PPP Data */
67 PPPOE_SERVICE_NAME = 0x0101,
68 PPPOE_AC_NAME = 0x0102,
69 PPPOE_HOST_UNIQ = 0x0103,
70 PPPOE_AC_COOKIE = 0x0104,
71 PPPOE_VENDOR = 0x0105,
72 PPPOE_RELAY_SID = 0x0110,
73 PPPOE_MAX_PAYLOAD = 0x0120,
74 PPPOE_SERVICE_NAME_ERROR = 0x0201,
75 PPPOE_AC_SYSTEM_ERROR = 0x0202,
76 PPPOE_GENERIC_ERROR = 0x0203
79 static struct tok pppoetag2str[] = {
81 { PPPOE_SERVICE_NAME, "Service-Name" },
82 { PPPOE_AC_NAME, "AC-Name" },
83 { PPPOE_HOST_UNIQ, "Host-Uniq" },
84 { PPPOE_AC_COOKIE, "AC-Cookie" },
85 { PPPOE_VENDOR, "Vendor-Specific" },
86 { PPPOE_RELAY_SID, "Relay-Session-ID" },
87 { PPPOE_MAX_PAYLOAD, "PPP-Max-Payload" },
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
95 #define MAXTAGPRINT 80
98 pppoe_if_print(const struct pcap_pkthdr *h, register const u_char *p)
100 return (pppoe_print(p, h->len));
104 pppoe_print(register const u_char *bp, u_int length)
106 u_int16_t pppoe_ver, pppoe_type, pppoe_code, pppoe_sessionid;
108 const u_char *pppoe_packet, *pppoe_payload;
110 if (length < PPPOE_HDRLEN) {
111 (void)printf("truncated-pppoe %u", length);
114 length -= PPPOE_HDRLEN;
116 TCHECK2(*pppoe_packet, PPPOE_HDRLEN);
117 pppoe_ver = (pppoe_packet[0] & 0xF0) >> 4;
118 pppoe_type = (pppoe_packet[0] & 0x0F);
119 pppoe_code = pppoe_packet[1];
120 pppoe_sessionid = EXTRACT_16BITS(pppoe_packet + 2);
121 pppoe_length = EXTRACT_16BITS(pppoe_packet + 4);
122 pppoe_payload = pppoe_packet + PPPOE_HDRLEN;
124 if (pppoe_ver != 1) {
125 printf(" [ver %d]",pppoe_ver);
127 if (pppoe_type != 1) {
128 printf(" [type %d]",pppoe_type);
131 printf("PPPoE %s", tok2str(pppoecode2str, "PAD-%x", pppoe_code));
132 if (pppoe_code == PPPOE_PADI && pppoe_length > 1484 - PPPOE_HDRLEN) {
133 printf(" [len %u!]",pppoe_length);
135 if (pppoe_length > length) {
136 printf(" [len %u > %u!]", pppoe_length, length);
137 pppoe_length = length;
139 if (pppoe_sessionid) {
140 printf(" [ses 0x%x]", pppoe_sessionid);
144 /* PPP session packets don't contain tags */
145 u_short tag_type = 0xffff, tag_len;
146 const u_char *p = pppoe_payload;
150 * p points to current tag,
151 * tag_type is previous tag or 0xffff for first iteration
153 while (tag_type && p < pppoe_payload + pppoe_length) {
155 tag_type = EXTRACT_16BITS(p);
156 tag_len = EXTRACT_16BITS(p + 2);
158 /* p points to tag_value */
161 unsigned isascii = 0, isgarbage = 0;
163 char tag_str[MAXTAGPRINT];
164 unsigned tag_str_len = 0;
166 /* TODO print UTF-8 decoded text */
167 TCHECK2(*p, tag_len);
168 for (v = p; v < p + tag_len && tag_str_len < MAXTAGPRINT-1; v++)
169 if (*v >= 32 && *v < 127) {
170 tag_str[tag_str_len++] = *v;
173 tag_str[tag_str_len++] = '.';
176 tag_str[tag_str_len] = 0;
178 if (isascii > isgarbage) {
179 printf(" [%s \"%*.*s\"]",
180 tok2str(pppoetag2str, "TAG-0x%x", tag_type),
185 /* Print hex, not fast to abuse printf but this doesn't get used much */
186 printf(" [%s 0x", tok2str(pppoetag2str, "TAG-0x%x", tag_type));
187 for (v=p; v<p+tag_len; v++) {
195 printf(" [%s]", tok2str(pppoetag2str,
196 "TAG-0x%x", tag_type));
199 /* p points to next tag */
205 return (PPPOE_HDRLEN + ppp_print(pppoe_payload, pppoe_length));
210 return (PPPOE_HDRLEN);