pcap_sendpacket()报错 Winpcap 20
这是代码:voidmain(){pcap_t*fp;charerrbuf[PCAP_ERRBUF_SIZE];u_charpacket[100];inti;if((fp=...
这是代码:
void main(){ pcap_t* fp; char errbuf[PCAP_ERRBUF_SIZE]; u_char packet[100]; int i; if ((fp = pcap_open_live(device->name, /* name of the device */ 100, /* portion of the packet to capture (only the first 100 bytes)*/ PCAP_OPENFLAG_PROMISCUOUS, /* promiscuous mode */ 1, /* read timeout */ errbuf /* error buffer */ )) == NULL) { qDebug()<<"Unable to open the adapter. %s is not supported by Winpcap"<<device->name; return; } qDebug()<<"hi"; /* Supposing to be on ethernet, set mac destinat to 1:1:1:1:1:1 */ packet[0] = 1; packet[1] = 1; packet[2] = 1; packet[3] = 1; packet[4] = 1; packet[5] = 1; packet[6] = 2; packet[7] = 2; packet[8] = 2; packet[9] = 2; packet[10] = 2; packet[11] = 2; for (i = 12; i < 100; ++ i) { packet[i] = i % 256; } if (pcap_sendpacket(fp, packet, 100) != 0) { qDebug()<<"fail"; return; } else qDebug()<<"success"; return;}
运行报错了,怎么解决? 展开
void main(){ pcap_t* fp; char errbuf[PCAP_ERRBUF_SIZE]; u_char packet[100]; int i; if ((fp = pcap_open_live(device->name, /* name of the device */ 100, /* portion of the packet to capture (only the first 100 bytes)*/ PCAP_OPENFLAG_PROMISCUOUS, /* promiscuous mode */ 1, /* read timeout */ errbuf /* error buffer */ )) == NULL) { qDebug()<<"Unable to open the adapter. %s is not supported by Winpcap"<<device->name; return; } qDebug()<<"hi"; /* Supposing to be on ethernet, set mac destinat to 1:1:1:1:1:1 */ packet[0] = 1; packet[1] = 1; packet[2] = 1; packet[3] = 1; packet[4] = 1; packet[5] = 1; packet[6] = 2; packet[7] = 2; packet[8] = 2; packet[9] = 2; packet[10] = 2; packet[11] = 2; for (i = 12; i < 100; ++ i) { packet[i] = i % 256; } if (pcap_sendpacket(fp, packet, 100) != 0) { qDebug()<<"fail"; return; } else qDebug()<<"success"; return;}
运行报错了,怎么解决? 展开
1个回答
2015-04-05
展开全部
我测试了下你的代码,没有任何问题,可以发出数据包。
你的网卡名是什么格式的?应该是\Device\NPF_{C1D234D9-4C9C-4747-B716-365137DAFAAC这种格式
你的网卡名是什么格式的?应该是\Device\NPF_{C1D234D9-4C9C-4747-B716-365137DAFAAC这种格式
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
您可能需要的服务
百度律临官方认证律师咨询
平均3分钟响应
|
问题解决率99%
|
24小时在线
立即免费咨询律师
16220人正在获得一对一解答
昆明彩云之南5分钟前提交了问题
重庆晨曦微光6分钟前提交了问题
广州萤火虫6分钟前提交了问题