69,371
社区成员
发帖
与我相关
我的任务
分享
if(i=0)
RETURN VALUE
Upon successful completion fopen(), fdopen() and freopen() return a FILE pointer. Otherwise, NULL is returned and errno is set to
indicate the error.
ERRORS
EINVAL The mode provided to fopen(), fdopen(), or freopen() was invalid.
The fopen(), fdopen() and freopen() functions may also fail and set errno for any of the errors specified for the routine mal‐
loc(3).
The fopen() function may also fail and set errno for any of the errors specified for the routine open(2).
The fdopen() function may also fail and set errno for any of the errors specified for the routine fcntl(2).
The freopen() function may also fail and set errno for any of the errors specified for the routines open(2), fclose(3) and
fflush(3).
看看 errnovoid packet_handler(u_char *dumpfp, const struct pcap_pkthdr *header, const u_char *pkt_data)
{
static int i=0;
static u_char filename[256];
printf("in packet handler\n");
if(i=0) {
strncpy((char*)filename,(const char *)pkt_data+18,255);filename[255]=0;
i=1;
} else {/*处理一帧*/
savetofile(filename,pkt_data);
}
return;
}
void savetofile(u_char *filename,const u_char *pkt_data) {
FILE *onfile;
if((onfile=fopen((char*)filename,"ab"))==NULL) {
printf("[%s]文件打开失败",filename);
exit(0);
}
fwrite(pkt_data+18,1,542,onfile);
fclose(onfile);
return ;
}