/*Reads the next packet from pcap_next() and validates the FCS. */ unsigned char *next_packet(struct pcap_pkthdr *header) { const unsigned char *packet = NULL; struct pcap_pkthdr *pkt_header; static int warning_shown = 0; int status; /* Loop until we get a valid packet, or until we run out of packets */ while((status = pcap_next_ex(get_handle(), &pkt_header, &packet)) == 1 || !status) { if(!status) continue; /* timeout */ memcpy(header, pkt_header, sizeof(*header)); if(get_validate_fcs() && !check_fcs(packet, header->len)) { if(!warning_shown) cprintf(INFO, "[!] Found packet with bad FCS, skipping...\n"); warning_shown = 1; continue; } break; } return (void*)packet; }
/*Reads the next packet from pcap_next() and validates the FCS. */ const u_char *next_packet(struct pcap_pkthdr *header) { const u_char *packet = NULL; /* Loop until we get a valid packet, or until we run out of packets */ #ifdef __APPLE__ struct pcap_pkthdr *pkt_header = NULL; int status = 1; while ((status = pcap_next_ex(get_handle(), &pkt_header, &packet)) == 1 || status == 0) // status == 0 indicates timeout #else while((packet = pcap_next(get_handle(), header)) != NULL) #endif { #ifdef __APPLE__ if (status == 0) continue; memcpy(header, pkt_header, sizeof(*header)); #endif if(get_validate_fcs()) { if(check_fcs(packet, header->len)) { break; } else { #ifndef __APPLE__ cprintf(INFO, "[!] Found packet with bad FCS, skipping...\n"); #endif } } else { break; } } return packet; }