optimize pcat

This commit is contained in:
Neale Pickett 2014-06-12 12:52:37 -06:00
parent 7e6e7f5b40
commit d690f8d591
3 changed files with 24 additions and 6 deletions

View File

@ -1,5 +1,5 @@
CFLAGS = -Wall -Werror -Wno-unused-variable
TARGETS = pmerge puniq p4split pcat
CFLAGS += -Wall -Werror -Wno-unused-variable -O2
TARGETS += pmerge puniq p4split pcat
TARGETS += hd pyesc printfesc xor unhex
all: $(TARGETS)

24
pcat.c
View File

@ -20,11 +20,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));
}
}
@ -163,13 +181,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;

View File

@ -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;
}