Hello all, I'm trying to do random access read on a growing pcap file, (program keeps track of previous EOF and then try to restart reading from this mark on growing file), for this i'm using fseek and ftell functions. But problem i'm facing is that, when i go to read the file second time ,from previous EOF, pcap_open_offline shows error " bad dump file format" how to resolve this problem? is anything wrong about my logic ? FILE* fp=fopen(a.pcap,"r"); if(...) fseek(fp,size,SEEK_SET); pcap_fopen_offline(fp,errbuf); if(..) size=ftell(fp); asked 10 Jun '13, 12:42 Sanny_D edited 10 Jun '13, 12:43 |
One Answer:
Yes. You're assuming that a If you're just trying to do the moral equivalent of If you're really trying to do random I/O, i.e. going back and rereading packets, and also do a sequential read of the file, you should probably open the file twice, each time with answered 11 Jun '13, 00:10 Guy Harris ♦♦ |
this is what i am trying to do, indeed i am opening the file everytym.
while(1) {
so that you do the seek AFTER libpcap opens the file, not BEFORE it opens the file.
(Also, make sure you don’t keep an unlimited number of file handles open; eventually you will hit the maximum number of open files per process (most if not all UN*Xes have one; I don’t know whether Windows does) and subsequent opens will fail.)