I was creating a simple sniffer, just for fun, and I want to output the dump to a file. Here's the code of the sniffer:
#include <stdio.h>
#include <pcap.h>
#define MAX_PACKET_NUM 5
int main(void) {
struct pcap_pkthdr header;
const u_char *packet;
char errbuf[PCAP_ERRBUF_SIZE];
char *device;
pcap_t *pcap_handle;
int i;
printf("## Now sniffing on: %s ##\n", device);
printf("## Max packets number for this session: %d\n", MAX_PACKET_NUM);
printf("[?] Sniffing...\n");
pcap_handle = pcap_open_live(device, 1000, 1, 0, errbuf);
for(i=0; i < MAX_PACKET_NUM; i++) {
packet = pcap_next(pcap_handle, &header);
printf("[!] Captured a %d bytes packet!\n", header.len);
dump(packet, header.len);
}
}
It works fine, but how can I output the dump to a file? I tried using file streams, but I don't really know how to output a function. As you can see, the dump() function prints the output on the screen, maybe there is a function to output to a file? Please help me out guys!