*/
#ifndef lint
-static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-l2tp.c,v 1.12 2002-06-11 17:08:51 itojun Exp $";
+static const char rcsid[] _U_ =
+ "@(#) $Header: /tcpdump/master/tcpdump/print-l2tp.c,v 1.19 2005-04-20 21:49:56 guy Exp $";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+#include <tcpdump-stdinc.h>
+
#include <stdio.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
#include "l2tp.h"
#include "interface.h"
static void
print_string(const u_char *dat, u_int length)
{
- int i;
+ u_int i;
for (i=0; i<length; i++) {
printf("%c", *dat++);
}
static void
print_octets(const u_char *dat, u_int length)
{
- int i;
+ u_int i;
for (i=0; i<length; i++) {
printf("%02x", *dat++);
}
TCHECK(*ptr); /* Flags & Length */
len = EXTRACT_16BITS(ptr) & L2TP_AVP_HDR_LEN_MASK;
- /* If it is not long enough to decode the entire AVP, we'll
- abandon. */
+ /* If it is not long enough to contain the header, we'll give up. */
+ if (len < 6)
+ goto trunc;
+
+ /* If it goes past the end of the remaining length of the packet,
+ we'll give up. */
+ if (len > (u_int)length)
+ goto trunc;
+
+ /* If it goes past the end of the remaining length of the captured
+ data, we'll give up. */
TCHECK2(*ptr, len);
/* After this point, no need to worry about truncation */
const u_int16_t *ptr = (u_int16_t *)dat;
u_int cnt = 0; /* total octets consumed */
u_int16_t pad;
- int flag_t, flag_l, flag_s, flag_o, flag_p;
+ int flag_t, flag_l, flag_s, flag_o;
u_int16_t l2tp_len;
- flag_t = flag_l = flag_s = flag_o = flag_p = FALSE;
+ flag_t = flag_l = flag_s = flag_o = FALSE;
TCHECK(*ptr); /* Flags & Version */
if ((EXTRACT_16BITS(ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2TP) {
flag_o = TRUE;
printf("O");
}
- if (EXTRACT_16BITS(ptr) & L2TP_FLAG_PRIORITY) {
- flag_p = TRUE;
+ if (EXTRACT_16BITS(ptr) & L2TP_FLAG_PRIORITY)
printf("P");
- }
printf("]");
ptr++;
cnt += (2 + pad);
}
+ if (flag_l) {
+ if (length < l2tp_len) {
+ printf(" Length %u larger than packet", l2tp_len);
+ return;
+ }
+ length = l2tp_len;
+ }
+ if (length < cnt) {
+ printf(" Length %u smaller than header length", length);
+ return;
+ }
if (flag_t) {
+ if (!flag_l) {
+ printf(" No length");
+ return;
+ }
if (length - cnt == 0) {
printf(" ZLB");
} else {