C 从套接字读取(缺少字节?)
我正在编写程序,在监视器模式下从无线接口读取套接字。 问题是,有时从read()函数接收到的数据包不完整。 收到的数据包没有radiotap报头,它从MAC帧中的地址字段开始。 请检查我的代码是否正确 开口插座: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
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);
}