diff options
Diffstat (limited to 'print-pppoe.c')
-rw-r--r-- | print-pppoe.c | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/print-pppoe.c b/print-pppoe.c index 1b908281..f3b2236f 100644 --- a/print-pppoe.c +++ b/print-pppoe.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = -"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.21 2002-12-19 09:39:14 guy Exp $ (LBL)"; +"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.22 2003-06-13 05:55:22 hannes Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -88,6 +88,7 @@ static struct tok pppoetag2str[] = { }; #define PPPOE_HDRLEN 6 +#define MAXTAGPRINT 80 u_int pppoe_if_print(const struct pcap_pkthdr *h, register const u_char *p) @@ -134,14 +135,19 @@ pppoe_print(register const u_char *bp, u_int length) printf(" [ses 0x%x]", pppoe_sessionid); } - if (pppoe_payload + pppoe_length < snapend) { -#if 0 - const u_char *x = pppoe_payload + pppoe_length; + if (pppoe_payload + pppoe_length < snapend && snapend-pppoe_payload+14 > 64) { + /* (small packets are probably just padded up to the ethernet + minimum of 64 bytes) */ printf(" [length %d (%d extra bytes)]", pppoe_length, snapend - pppoe_payload - pppoe_length); - default_print(x, snapend - x); -#endif +#if RESPECT_PAYLOAD_LENGTH snapend = pppoe_payload+pppoe_length; +#else + /* Actual PPPoE implementations appear to ignore the payload + length and use the full ethernet frame anyways */ + pppoe_length = snapend-pppoe_payload; +#endif + } if (pppoe_code) { @@ -162,25 +168,36 @@ pppoe_print(register const u_char *bp, u_int length) /* p points to tag_value */ if (tag_len) { - int isascii = 1; + unsigned isascii = 0, isgarbage = 0; const u_char *v = p; u_short l; - - for (v = p; v < p + tag_len; v++) - if (*v >= 127 || *v < 32) { - isascii = 0; - break; + char tag_str[MAXTAGPRINT]; + unsigned tag_str_len = 0; + + for (v = p; v < p + tag_len && tag_str_len < MAXTAGPRINT-1; v++) + if (*v >= 32 && *v < 127) { + tag_str[tag_str_len++] = *v; + isascii++; + } else { + tag_str[tag_str_len++] = '.'; + isgarbage++; } + tag_str[tag_str_len] = 0; - /* TODO print UTF8 decoded text */ - if (isascii) { - l = (tag_len < 80 ? tag_len : 80); + if (isascii > isgarbage) { printf(" [%s \"%*.*s\"]", - tok2str(pppoetag2str, "TAG-0x%x", tag_type), - l, l, p); - } else - printf(" [%s UTF8]", - tok2str(pppoetag2str, "TAG-0x%x", tag_type)); + tok2str(pppoetag2str, "TAG-0x%x", tag_type), + tag_str_len, tag_str_len, tag_str); + } else { + /* Print hex, not fast to abuse printf but this doesn't get used much */ + printf(" [%s 0x", tok2str(pppoetag2str, "TAG-0x%x", tag_type)); + for (v=p; v<p+tag_len; v++) { + printf("%02.2X", *v); + } + printf("]"); + } + + } else printf(" [%s]", tok2str(pppoetag2str, "TAG-0x%x", tag_type)); |