#include #include #include #include "fixed-ctype.h" #include "format.h" typedef struct priv PRIV; struct priv { unsigned char *buf; int len; int buflen; } ; static void force(void **privvp) { PRIV *p; p = malloc(sizeof(PRIV)); p->len = 0; p->buflen = 64; p->buf = malloc(p->buflen); *privvp = p; } static int hdrtest(const char *l, void **privvp) { char *el; int i; if (!strcmp(l,"\t\t\t\t\t icmp type")) goto found; strtol(l,&el,10); if (l == el) return(0); l = el; for (i=0;i<4;i++) { for (;*l&&FIXspace(*l);l++) ; for (;*l&&!FIXspace(*l);l++) ; if (! *l) return(0); } for (;*l&&FIXspace(*l);l++) ; if (! *l) return(0); for (;*l&&!FIXspace(*l);l++) ; if (*l) return(0); found:; force(privvp); return(1); } static void getx(const char *l, PRIV *p, int maxn) { unsigned int v; for (;maxn>0;maxn--) { while (*l && FIXspace(*l)) l ++; if (!FIXxdigit(l[0]) || !FIXxdigit(l[1])) break; sscanf(l,"%2x",&v); if (p->len >= p->buflen) p->buf = realloc(p->buf,p->buflen=p->len+64); p->buf[p->len++] = v; l += 2; } } static int hdrline(const char *l) { if (! l) return(1); if ( (l[0] == ' ') && FIXxdigit(l[1]) && FIXxdigit(l[2]) && ((l[3] == ' ') || (l[3] == '\0')) ) return(0); return(1); } static void line(const char *l, void *pvp) { PRIV *p; p = pvp; if (hdrline(l)) { if (p->len > 0) dumpit(p->buf,p->len); p->len = 0; if (l) printf("%s\n",l); } else { getx(l,p,16); } } FORMAT format_etherfind = { "etherfind", hdrtest, force, line };