X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fplugins%2Fpppoe%2Fcommon.c;h=9ddbcbd47f3202045c01141f9157f422840d77e8;hb=HEAD;hp=64bed1af6ca63df5de7344bbdc85c8ea262f22e8;hpb=eff574c871822c7e2788aa8a928f2480fa7a6cb3;p=ppp.git diff --git a/pppd/plugins/pppoe/common.c b/pppd/plugins/pppoe/common.c index 64bed1a..31811f5 100644 --- a/pppd/plugins/pppoe/common.c +++ b/pppd/plugins/pppoe/common.c @@ -17,17 +17,18 @@ static char const RCSID[] = "$Id: common.c,v 1.3 2008/06/09 08:34:23 paulus Exp $"; #ifdef HAVE_CONFIG_H -#include +#include "config.h" #endif #define _GNU_SOURCE 1 #include "pppoe.h" -#include "pppd/pppd.h" +#include #include #include #include #include /* for LOG_DEBUG */ +#include #ifdef HAVE_UNISTD_H #include @@ -164,6 +165,42 @@ sendPADT(PPPoEConnection *conn, char const *msg) info("Sent PADT"); } +static void +pppoe_printpkt_hex(void (*printer)(void *, char *, ...), void *arg, unsigned char const *buf, int len) +{ + int i; + int base; + + /* do NOT dump PAP packets */ + if (len >= 2 && buf[0] == 0xC0 && buf[1] == 0x23) { + printer(arg, "(PAP Authentication Frame -- Contents not dumped)\n"); + return; + } + + for (base=0; baselength); - int i, tag, tlen, text; + int i, j, tag, tlen, text; switch (ntohs(packet->ethHdr.h_proto)) { case ETH_PPPOE_DISCOVERY: @@ -211,6 +248,8 @@ void pppoe_printpkt(PPPoEPacket *packet, printer(arg, " dst %02x:%02x:%02x:%02x:%02x:%02x ", EH(packet->ethHdr.h_dest)); printer(arg, " src %02x:%02x:%02x:%02x:%02x:%02x\n", EH(packet->ethHdr.h_source)); + if (pppoe_verbose >= 2) + pppoe_printpkt_hex(printer, arg, packet->payload, ntohs(packet->length)); if (ntohs(packet->ethHdr.h_proto) != ETH_PPPOE_DISCOVERY) return; @@ -265,13 +304,23 @@ void pppoe_printpkt(PPPoEPacket *packet, printer(arg, "unknown tag 0x%x", tag); } if (tlen) { + /* If it is supposed to be text, make sure it's all printing chars */ + if (text) { + for (j = 0; j < tlen; ++j) { + if (!isprint(packet->payload[i+j])) { + text = 0; + break; + } + } + } if (text) - printer(arg, " %.*v", tlen, &packet->payload[i]); - else if (tlen <= 32) - printer(arg, " %.*B", tlen, &packet->payload[i]); - else - printer(arg, " %.32B... (length %d)", - &packet->payload[i], tlen); + printer(arg, " %.*s", tlen, &packet->payload[i]); + else { + for (j = 0; j < tlen && j < 32; j++) + printer(arg, " %02x", (unsigned) *(&packet->payload[i]+j)); + if (j < tlen) + printer(arg, "... (length %d)", tlen); + } } printer(arg, "]"); }