Deleted Added
full compact
print-pppoe.c (127668) print-pppoe.c (146773)
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 unchanged lines hidden (view full) ---

18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * Original code by Greg Stark <gsstark@mit.edu>
22 */
23
24#ifndef lint
25static const char rcsid[] _U_ =
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 unchanged lines hidden (view full) ---

18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * Original code by Greg Stark <gsstark@mit.edu>
22 */
23
24#ifndef lint
25static const char rcsid[] _U_ =
26"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.24.2.4 2004/03/24 03:04:22 guy Exp $ (LBL)";
26"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.30 2004/08/27 03:57:41 guy Exp $ (LBL)";
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <tcpdump-stdinc.h>
34

--- 61 unchanged lines hidden (view full) ---

96pppoe_if_print(const struct pcap_pkthdr *h, register const u_char *p)
97{
98 return (pppoe_print(p, h->len));
99}
100
101u_int
102pppoe_print(register const u_char *bp, u_int length)
103{
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <tcpdump-stdinc.h>
34

--- 61 unchanged lines hidden (view full) ---

96pppoe_if_print(const struct pcap_pkthdr *h, register const u_char *p)
97{
98 return (pppoe_print(p, h->len));
99}
100
101u_int
102pppoe_print(register const u_char *bp, u_int length)
103{
104 u_short pppoe_ver, pppoe_type, pppoe_code, pppoe_sessionid, pppoe_length;
104 u_int16_t pppoe_ver, pppoe_type, pppoe_code, pppoe_sessionid;
105 u_int pppoe_length;
105 const u_char *pppoe_packet, *pppoe_payload;
106
106 const u_char *pppoe_packet, *pppoe_payload;
107
108 if (length < PPPOE_HDRLEN) {
109 (void)printf("truncated-pppoe %u", length);
110 return (length);
111 }
112 length -= PPPOE_HDRLEN;
107 pppoe_packet = bp;
108 TCHECK2(*pppoe_packet, PPPOE_HDRLEN);
109 pppoe_ver = (pppoe_packet[0] & 0xF0) >> 4;
110 pppoe_type = (pppoe_packet[0] & 0x0F);
111 pppoe_code = pppoe_packet[1];
112 pppoe_sessionid = EXTRACT_16BITS(pppoe_packet + 2);
113 pppoe_length = EXTRACT_16BITS(pppoe_packet + 4);
114 pppoe_payload = pppoe_packet + PPPOE_HDRLEN;
115
113 pppoe_packet = bp;
114 TCHECK2(*pppoe_packet, PPPOE_HDRLEN);
115 pppoe_ver = (pppoe_packet[0] & 0xF0) >> 4;
116 pppoe_type = (pppoe_packet[0] & 0x0F);
117 pppoe_code = pppoe_packet[1];
118 pppoe_sessionid = EXTRACT_16BITS(pppoe_packet + 2);
119 pppoe_length = EXTRACT_16BITS(pppoe_packet + 4);
120 pppoe_payload = pppoe_packet + PPPOE_HDRLEN;
121
116 if (snapend < pppoe_payload) {
117 printf(" truncated PPPoE");
118 return (PPPOE_HDRLEN);
119 }
120
121 if (pppoe_ver != 1) {
122 printf(" [ver %d]",pppoe_ver);
123 }
124 if (pppoe_type != 1) {
125 printf(" [type %d]",pppoe_type);
126 }
127
128 printf("PPPoE %s", tok2str(pppoecode2str, "PAD-%x", pppoe_code));
129 if (pppoe_code == PPPOE_PADI && pppoe_length > 1484 - PPPOE_HDRLEN) {
122 if (pppoe_ver != 1) {
123 printf(" [ver %d]",pppoe_ver);
124 }
125 if (pppoe_type != 1) {
126 printf(" [type %d]",pppoe_type);
127 }
128
129 printf("PPPoE %s", tok2str(pppoecode2str, "PAD-%x", pppoe_code));
130 if (pppoe_code == PPPOE_PADI && pppoe_length > 1484 - PPPOE_HDRLEN) {
130 printf(" [len %d!]",pppoe_length);
131 printf(" [len %u!]",pppoe_length);
131 }
132 }
133 if (pppoe_length > length) {
134 printf(" [len %u > %u!]", pppoe_length, length);
135 pppoe_length = length;
136 }
132 if (pppoe_sessionid) {
133 printf(" [ses 0x%x]", pppoe_sessionid);
134 }
135
137 if (pppoe_sessionid) {
138 printf(" [ses 0x%x]", pppoe_sessionid);
139 }
140
136 if (pppoe_payload + pppoe_length < snapend && snapend-pppoe_payload+14 > 64) {
141 if (pppoe_length < length && length + ETHER_HDRLEN > 60) {
137 /* (small packets are probably just padded up to the ethernet
142 /* (small packets are probably just padded up to the ethernet
138 minimum of 64 bytes) */
139 printf(" [length %d (%d extra bytes)]",
140 pppoe_length, snapend - pppoe_payload - pppoe_length);
143 minimum of 60 bytes of data + 4 bytes of CRC) */
144 printf(" [length %u (%u extra bytes)]",
145 pppoe_length, length - pppoe_length);
141#if RESPECT_PAYLOAD_LENGTH
146#if RESPECT_PAYLOAD_LENGTH
142 snapend = pppoe_payload+pppoe_length;
147 if (snaplend > pppoe_payload+pppoe_length)
148 snapend = pppoe_payload+pppoe_length;
143#else
144 /* Actual PPPoE implementations appear to ignore the payload
145 length and use the full ethernet frame anyways */
149#else
150 /* Actual PPPoE implementations appear to ignore the payload
151 length and use the full ethernet frame anyways */
146 pppoe_length = snapend-pppoe_payload;
152 pppoe_length = length;
147#endif
153#endif
148
149 }
150
151 if (pppoe_code) {
152 /* PPP session packets don't contain tags */
153 u_short tag_type = 0xffff, tag_len;
154 const u_char *p = pppoe_payload;
155
156 /*
157 * loop invariant:
154 }
155
156 if (pppoe_code) {
157 /* PPP session packets don't contain tags */
158 u_short tag_type = 0xffff, tag_len;
159 const u_char *p = pppoe_payload;
160
161 /*
162 * loop invariant:
158 * p points to next tag,
163 * p points to current tag,
159 * tag_type is previous tag or 0xffff for first iteration
160 */
164 * tag_type is previous tag or 0xffff for first iteration
165 */
161 while (tag_type && p + 4 < pppoe_payload + length &&
162 p + 4 < snapend) {
166 while (tag_type && p < pppoe_payload + pppoe_length) {
167 TCHECK2(*p, 4);
163 tag_type = EXTRACT_16BITS(p);
164 tag_len = EXTRACT_16BITS(p + 2);
165 p += 4;
166 /* p points to tag_value */
167
168 if (tag_len) {
169 unsigned isascii = 0, isgarbage = 0;
170 const u_char *v = p;
171 char tag_str[MAXTAGPRINT];
172 unsigned tag_str_len = 0;
173
174 /* TODO print UTF-8 decoded text */
168 tag_type = EXTRACT_16BITS(p);
169 tag_len = EXTRACT_16BITS(p + 2);
170 p += 4;
171 /* p points to tag_value */
172
173 if (tag_len) {
174 unsigned isascii = 0, isgarbage = 0;
175 const u_char *v = p;
176 char tag_str[MAXTAGPRINT];
177 unsigned tag_str_len = 0;
178
179 /* TODO print UTF-8 decoded text */
180 TCHECK2(*p, tag_len);
175 for (v = p; v < p + tag_len && tag_str_len < MAXTAGPRINT-1; v++)
176 if (*v >= 32 && *v < 127) {
177 tag_str[tag_str_len++] = *v;
178 isascii++;
179 } else {
180 tag_str[tag_str_len++] = '.';
181 isgarbage++;
182 }

--- 36 unchanged lines hidden ---
181 for (v = p; v < p + tag_len && tag_str_len < MAXTAGPRINT-1; v++)
182 if (*v >= 32 && *v < 127) {
183 tag_str[tag_str_len++] = *v;
184 isascii++;
185 } else {
186 tag_str[tag_str_len++] = '.';
187 isgarbage++;
188 }

--- 36 unchanged lines hidden ---