void read_file(const char *filename) { if (!read_pcap_file(filename)) { read_json_file(filename); } }
int main (int argc, char* argv[]) { int i; void* buffer; long length; int loops; __u64 packets_sent = 0; __u64 packet_bytes = 0; struct timeval tv_start; struct pcap_pkthdr* pcap_hdr; struct quick_tx qtx; if (argc != 3 && argc != 4) { printf("Usage: ./pcapsend <path-to-pcap> <interface> [loops]\n"); exit(-1); } if (!read_pcap_file(argv[1], &buffer, &length)) { perror("Failed to read file! "); exit(-1); } if (argc == 4) { loops = atoi(argv[3]); } else { loops = 1; } memset(&qtx, 0, sizeof(qtx)); int ret = quick_tx_open(argv[2], &qtx); if (ret == 0) { int blocks = quick_tx_alloc_mem_space(&qtx, length * loops); if (blocks >= 0) { printf("quick_tx mapped %d blocks of memory\n", blocks); } else { printf("quick_tx_alloc_mem_space failure\n"); exit(-1); } } else { exit(-1); } gettimeofday(&tv_start,NULL); for (i = 0; i < loops; i++) { void* offset = buffer + sizeof(struct pcap_file_header); while(offset < buffer + length) { pcap_hdr = (struct pcap_pkthdr*) offset; offset += sizeof(struct pcap_pkthdr); if ((quick_tx_send_packet(&qtx, (const void*)offset, pcap_hdr->caplen)) < 0) { printf("An error occurred while trying to send a packet\n"); goto quick_tx_error; } offset += pcap_hdr->caplen; packets_sent++; packet_bytes+= pcap_hdr->caplen; } } printf("Done, closing everything!\n"); printf("\n"); quick_tx_error: quick_tx_close(&qtx); free(buffer); return 0; }