+/*
+ * format_packet - make a readable representation of a packet,
+ * calling `printer(arg, format, ...)' to output it.
+ */
+void
+format_packet(p, len, printer, arg)
+ u_char *p;
+ int len;
+ void (*printer) __ARGS((void *, char *, ...));
+ void *arg;
+{
+ int i, n;
+ u_short proto;
+ u_char x;
+
+ if (len >= DLLHEADERLEN && p[0] == ALLSTATIONS && p[1] == UI) {
+ p += 2;
+ GETSHORT(proto, p);
+ len -= DLLHEADERLEN;
+ for (i = 0; i < N_PROTO; ++i)
+ if (proto == prottbl[i].protocol)
+ break;
+ if (i < N_PROTO) {
+ printer(arg, "[%s", prottbl[i].name);
+ n = (*prottbl[i].printpkt)(p, len, printer, arg);
+ printer(arg, "]");
+ p += n;
+ len -= n;
+ } else {
+ printer(arg, "[proto=0x%x]", proto);
+ }
+ }
+
+ for (; len > 0; --len) {
+ GETCHAR(x, p);
+ printer(arg, " %.2x", x);
+ }