Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 从套接字读取(缺少字节?)_C_Linux_Sockets_Wireless - Fatal编程技术网

C 从套接字读取(缺少字节?)

C 从套接字读取(缺少字节?),c,linux,sockets,wireless,C,Linux,Sockets,Wireless,我正在编写程序,在监视器模式下从无线接口读取套接字。 问题是,有时从read()函数接收到的数据包不完整。 收到的数据包没有radiotap报头,它从MAC帧中的地址字段开始。 请检查我的代码是否正确 开口插座: printf("create socket\n"); if ((s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) { fprintf(stderr, "socket(PF_PA

我正在编写程序,在监视器模式下从无线接口读取套接字。 问题是,有时从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;
}
printf(“创建套接字”);
if((s=套接字(PF_数据包,SOCK_原始,htons(ETH_P_全部)))<0)
{
fprintf(stderr,“套接字(PF_数据包)失败”);
返回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);

  }
文件*destFile;
对于(int i=0;i<16;++i){
//阅读
无符号字符tmpbuf[4096];
整数计数=4096;
int caplen=读取(s,tmpbuf,计数);
//写
char-str[100];
sprintf(str,“%d.bin”,i);
destFile=fopen(str,“wb”);
fwrite(tmpbuf,1,caplen,destFile);
//printf(“%d\n”,caplen);
fclose(destFile);
}