void parse_packet_pf_ring(const struct pfring_pkthdr* h, const u_char* p, const u_char* user_bytes) { memset((void*)&h->extended_hdr.parsed_pkt, 0, sizeof(h->extended_hdr.parsed_pkt)); pfring_parse_pkt((u_char*)p, (struct pfring_pkthdr*)h, 4, 1, 0); char buffer[512]; pfring_print_parsed_pkt(buffer, 512, p, h); std::cout << buffer; }
void dummyProcesssPacket(const struct pfring_pkthdr *h, const u_char *p, const u_char *user_bytes) { const int BUFSIZE = 4096; char bigbuf[BUFSIZE]; // buf into which we spew prints int buflen = 0; long threadId = (long)user_bytes; if(unlikely(do_shutdown)) return; if(verbose) { int s; uint nsec; if(h->ts.tv_sec == 0) { memset((void*)&h->extended_hdr.parsed_pkt, 0, sizeof(struct pkt_parsing_info)); pfring_parse_pkt((u_char*)p, (struct pfring_pkthdr*)h, 5, 1, 1); } s = (h->ts.tv_sec + thiszone) % 86400; nsec = h->extended_hdr.timestamp_ns % 1000; buflen += snprintf(&bigbuf[buflen], BUFSIZE - buflen, "%02d:%02d:%02d.%06u%03u ", s / 3600, (s % 3600) / 60, s % 60, (unsigned)h->ts.tv_usec, nsec); #if 0 for(i=0; i<32; i++) buflen += snprintf(&bigbuf[buflen], BUFSIZE - buflen, "%02X ", p[i]); printf("\n"); #endif buflen += snprintf(&bigbuf[buflen], BUFSIZE - buflen, "[T%lu]", threadId); if(use_extended_pkt_header) { buflen += pfring_print_parsed_pkt(&bigbuf[buflen], BUFSIZE - buflen, p, h); } else { struct ether_header *ehdr = (struct ether_header *) p; u_short eth_type = ntohs(ehdr->ether_type); if(eth_type == 0x0806) buflen += snprintf(&bigbuf[buflen], BUFSIZE - buflen, "[ARP]"); else buflen += snprintf(&bigbuf[buflen], BUFSIZE - buflen, "[eth_type=0x%04X]", eth_type); buflen += snprintf(&bigbuf[buflen], BUFSIZE - buflen, "[caplen=%d][len=%d][parsed_header_len=%d]" "[eth_offset=%d][l3_offset=%d][l4_offset=%d][payload_offset=%d]\n", h->caplen, h->len, h->extended_hdr.parsed_header_len, h->extended_hdr.parsed_pkt.offset.eth_offset, h->extended_hdr.parsed_pkt.offset.l3_offset, h->extended_hdr.parsed_pkt.offset.l4_offset, h->extended_hdr.parsed_pkt.offset.payload_offset); } fputs(bigbuf, stdout); } numPkts[threadId]++, numBytes[threadId] += h->len+24 /* 8 Preamble + 4 CRC + 12 IFG */; }