force close all files while code is running

hello again, i am a beginner and currently working on parsing pcap files.
I have successfully parsed and got data from it. After that i tried to implement it in real time but here i encountered an issue. I use dirent.h to get the newly created file by wireshark ( i am getting my pcap files from wireshark). in the code below:
char errbuff[PCAP_ERRBUF_SIZE];
system("pause");
here: pcap_t * pcap = pcap_open_offline(file.c_str(), errbuff);
struct pcap_pkthdr *header;
const u_char *data;
u_int packetCount = 0;

the point where "here" is written, pcap file is opened. after the task is performed, in my code it doesn't closes the file. My question is how to close this opened file?
is there a way to force close all opened files while code is still running?

for above part of code, i took it from: https://www.rhyous.com/2011/11/13/how-to-read-a-pcap-file-from-wireshark-with-c/
thanks but still getting error that file is opened in console, how can i close it from console.
Please post the exact error that you're seeing. Also, if possible, post the full code.

This sounds to me like a case of "the problem isn't where you think it is." Try adding temporary code to print a string to cerr just before and after the code that you think is generating the error.
well there isn't any way to close pcap file after reading it. I have checked all commands available for pcap in this site:
https://linux.die.net/man/

So no solution in other words.
well there isn't any way to close pcap file after reading it.

Again, what do you suppose pcap_close() does?
https://linux.die.net/man/3/pcap_close

Last edited on
Topic archived. No new replies allowed.