static char const RCSID[] =
"$Id: common.c,v 1.3 2008/06/09 08:34:23 paulus Exp $";
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#define _GNU_SOURCE 1
#include "pppoe.h"
-#include "pppd/pppd.h"
+#include <pppd/pppd.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <syslog.h> /* for LOG_DEBUG */
+#include <ctype.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
size_t elen = strlen(msg);
err.type = htons(TAG_GENERIC_ERROR);
err.length = htons(elen);
- strcpy(err.payload, msg);
+ strcpy((char*) err.payload, msg);
memcpy(cursor, &err, elen + TAG_HDR_SIZE);
cursor += elen + TAG_HDR_SIZE;
plen += elen + TAG_HDR_SIZE;
void (*printer)(void *, char *, ...), void *arg)
{
int len = ntohs(packet->length);
- int i, tag, tlen, text;
+ int i, j, tag, tlen, text;
switch (ntohs(packet->ethHdr.h_proto)) {
case ETH_PPPOE_DISCOVERY:
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, "]");
}