从套接字读取缺少字节?

问题描述

我正在编写在监视器模式下从无线接口读取套接字的程序。 问题是有时无法从read()函数接收到完整的数据包。 收到的数据包没有radiotap标头,它从MAC帧中的地址字段开始。 请检查我的代码是否正确。

打开插座:

printf("create socket\n");
  
if ((s = socket(PF_PACKET,SOCK_RAW,htons(ETH_P_ALL))) < 0)
{
   fprintf(stderr,"socket(PF_PACKET) Failed");
   return 0;
}

绑定(未显示

套接字读取:

FILE* destFile;

  for(int i = 0;i < 16;++i){

        //read
         unsigned char tmpbuf[4096];
         int count = 4096;
         int caplen = read(s,tmpbuf,count);

         //write
         char str[100];
         sprintf(str,"%d.bin",i);

         destFile = fopen(str,"wb");
         fwrite(tmpbuf,1,caplen,destFile);
         //printf("%d\n",caplen);
         fclose(destFile);

  }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)