diff --git a/pcat.c b/pcat.c index aa3c9f5..a35a0be 100644 --- a/pcat.c +++ b/pcat.c @@ -34,11 +34,29 @@ ip4_addr(char *addr_s, uint32_t addr) snprintf(addr_s, 16, "%u.%u.%u.%u", (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, (addr >> 0) & 0xff); } +void +print_nybble(uint8_t nybble) +{ + if (nybble < 10) { + putchar(nybble + '0'); + } else { + putchar(nybble - 10 + 'a'); + } +} + +/* About 3x faster than printf("%02x", octet); */ +void +printx(uint8_t octet) +{ + print_nybble(octet >> 4); + print_nybble(octet & 0xf); +} + void print_payload(struct stream *s) { while (s->len) { - printf("%02x", read_uint8(s)); + printx(read_uint8(s)); } } @@ -177,13 +195,13 @@ void pcat(FILE * f) { struct pcap_file p; + struct pcap_pkthdr hdr; + char frame[MAXFRAME]; if (-1 == pcap_open_in(&p, f)) return; for (;;) { - struct pcap_pkthdr hdr; - char frame[MAXFRAME]; if (-1 == pcap_read_pkthdr(&p, &hdr)) { break; diff --git a/pmerge.c b/pmerge.c index d991774..5699237 100644 --- a/pmerge.c +++ b/pmerge.c @@ -102,7 +102,7 @@ main(int argc, char *argv[]) * Make sure it'll fit */ if (cur->next.caplen > sizeof(frame)) { - fprintf(stderr, "error: huge frame (size %u)\n", (unsigned int) len); + fprintf(stderr, "error: huge frame (size %u)\n", (unsigned int) cur->next.caplen); return EX_SOFTWARE; }