diff options
author | delphij <delphij@FreeBSD.org> | 2015-01-07 19:55:18 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2015-01-07 19:55:18 +0000 |
commit | f49c5d523af9076a4a59e8dd664f9a897108432e (patch) | |
tree | e268839e08c106e178b33bd461d8d0a9c6fb5ad9 /contrib/tcpdump/print-pppoe.c | |
parent | c371846049d370ab78d943e60e789cdffe0aad3d (diff) | |
parent | 08263d19579d35a7a65e0c8bcb768504ce76d04e (diff) | |
download | FreeBSD-src-f49c5d523af9076a4a59e8dd664f9a897108432e.zip FreeBSD-src-f49c5d523af9076a4a59e8dd664f9a897108432e.tar.gz |
MFV r276761: tcpdump 4.6.2.
MFC after: 1 month
Diffstat (limited to 'contrib/tcpdump/print-pppoe.c')
-rw-r--r-- | contrib/tcpdump/print-pppoe.c | 71 |
1 files changed, 30 insertions, 41 deletions
diff --git a/contrib/tcpdump/print-pppoe.c b/contrib/tcpdump/print-pppoe.c index 8040c7a..1624c5e 100644 --- a/contrib/tcpdump/print-pppoe.c +++ b/contrib/tcpdump/print-pppoe.c @@ -17,29 +17,18 @@ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Original code by Greg Stark <gsstark@mit.edu> + * + * Original code by Greg Stark <gsstark@mit.edu> */ -#ifndef lint -static const char rcsid[] _U_ = -"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.31 2005-04-26 19:48:38 guy Exp $ (LBL)"; -#endif - +#define NETDISSECT_REWORKED #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <tcpdump-stdinc.h> -#include <stdio.h> -#include <string.h> - #include "interface.h" -#include "addrtoname.h" -#include "ppp.h" -#include "ethertype.h" -#include "ether.h" #include "extract.h" /* must come after interface.h */ /* Codes */ @@ -51,7 +40,7 @@ enum { PPPOE_PADT = 0xa7 }; -static struct tok pppoecode2str[] = { +static const struct tok pppoecode2str[] = { { PPPOE_PADI, "PADI" }, { PPPOE_PADO, "PADO" }, { PPPOE_PADR, "PADR" }, @@ -76,7 +65,7 @@ enum { PPPOE_GENERIC_ERROR = 0x0203 }; -static struct tok pppoetag2str[] = { +static const struct tok pppoetag2str[] = { { PPPOE_EOL, "EOL" }, { PPPOE_SERVICE_NAME, "Service-Name" }, { PPPOE_AC_NAME, "AC-Name" }, @@ -95,25 +84,25 @@ static struct tok pppoetag2str[] = { #define MAXTAGPRINT 80 u_int -pppoe_if_print(const struct pcap_pkthdr *h, register const u_char *p) +pppoe_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { - return (pppoe_print(p, h->len)); + return (pppoe_print(ndo, p, h->len)); } u_int -pppoe_print(register const u_char *bp, u_int length) +pppoe_print(netdissect_options *ndo, register const u_char *bp, u_int length) { - u_int16_t pppoe_ver, pppoe_type, pppoe_code, pppoe_sessionid; + uint16_t pppoe_ver, pppoe_type, pppoe_code, pppoe_sessionid; u_int pppoe_length; const u_char *pppoe_packet, *pppoe_payload; if (length < PPPOE_HDRLEN) { - (void)printf("truncated-pppoe %u", length); + ND_PRINT((ndo, "truncated-pppoe %u", length)); return (length); } length -= PPPOE_HDRLEN; pppoe_packet = bp; - TCHECK2(*pppoe_packet, PPPOE_HDRLEN); + ND_TCHECK2(*pppoe_packet, PPPOE_HDRLEN); pppoe_ver = (pppoe_packet[0] & 0xF0) >> 4; pppoe_type = (pppoe_packet[0] & 0x0F); pppoe_code = pppoe_packet[1]; @@ -122,22 +111,22 @@ pppoe_print(register const u_char *bp, u_int length) pppoe_payload = pppoe_packet + PPPOE_HDRLEN; if (pppoe_ver != 1) { - printf(" [ver %d]",pppoe_ver); + ND_PRINT((ndo, " [ver %d]",pppoe_ver)); } if (pppoe_type != 1) { - printf(" [type %d]",pppoe_type); + ND_PRINT((ndo, " [type %d]",pppoe_type)); } - printf("PPPoE %s", tok2str(pppoecode2str, "PAD-%x", pppoe_code)); + ND_PRINT((ndo, "PPPoE %s", tok2str(pppoecode2str, "PAD-%x", pppoe_code))); if (pppoe_code == PPPOE_PADI && pppoe_length > 1484 - PPPOE_HDRLEN) { - printf(" [len %u!]",pppoe_length); + ND_PRINT((ndo, " [len %u!]",pppoe_length)); } if (pppoe_length > length) { - printf(" [len %u > %u!]", pppoe_length, length); + ND_PRINT((ndo, " [len %u > %u!]", pppoe_length, length)); pppoe_length = length; } if (pppoe_sessionid) { - printf(" [ses 0x%x]", pppoe_sessionid); + ND_PRINT((ndo, " [ses 0x%x]", pppoe_sessionid)); } if (pppoe_code) { @@ -151,7 +140,7 @@ pppoe_print(register const u_char *bp, u_int length) * tag_type is previous tag or 0xffff for first iteration */ while (tag_type && p < pppoe_payload + pppoe_length) { - TCHECK2(*p, 4); + ND_TCHECK2(*p, 4); tag_type = EXTRACT_16BITS(p); tag_len = EXTRACT_16BITS(p + 2); p += 4; @@ -164,7 +153,7 @@ pppoe_print(register const u_char *bp, u_int length) unsigned tag_str_len = 0; /* TODO print UTF-8 decoded text */ - TCHECK2(*p, tag_len); + ND_TCHECK2(*p, tag_len); for (v = p; v < p + tag_len && tag_str_len < MAXTAGPRINT-1; v++) if (*v >= 32 && *v < 127) { tag_str[tag_str_len++] = *v; @@ -176,24 +165,24 @@ pppoe_print(register const u_char *bp, u_int length) tag_str[tag_str_len] = 0; if (isascii > isgarbage) { - printf(" [%s \"%*.*s\"]", + ND_PRINT((ndo, " [%s \"%*.*s\"]", tok2str(pppoetag2str, "TAG-0x%x", tag_type), (int)tag_str_len, (int)tag_str_len, - tag_str); + 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)); + ND_PRINT((ndo, " [%s 0x", tok2str(pppoetag2str, "TAG-0x%x", tag_type))); for (v=p; v<p+tag_len; v++) { - printf("%02X", *v); + ND_PRINT((ndo, "%02X", *v)); } - printf("]"); + ND_PRINT((ndo, "]")); } - + } else - printf(" [%s]", tok2str(pppoetag2str, - "TAG-0x%x", tag_type)); + ND_PRINT((ndo, " [%s]", tok2str(pppoetag2str, + "TAG-0x%x", tag_type))); p += tag_len; /* p points to next tag */ @@ -201,11 +190,11 @@ pppoe_print(register const u_char *bp, u_int length) return (0); } else { /* PPPoE data */ - printf(" "); - return (PPPOE_HDRLEN + ppp_print(pppoe_payload, pppoe_length)); + ND_PRINT((ndo, " ")); + return (PPPOE_HDRLEN + ppp_print(ndo, pppoe_payload, pppoe_length)); } trunc: - printf("[|pppoe]"); + ND_PRINT((ndo, "[|pppoe]")); return (PPPOE_HDRLEN); } |