Winpcap编程

依然3199 2013-06-15 11:36:11
void main(int argc, char **argv)
{
pcap_t *fp;
char errbuf[PCAP_ERRBUF_SIZE];
u_char packet[128];
//int i;

/* Check the validity of the command line */
if (argc != 2)
{
printf("usage: %s interface (e.g. 'rpcap://eth0')", argv[0]);
return;
}

/* Open the output device */
if ( (fp= pcap_open(argv[1], // name of the device
128, // portion of the packet to capture (only the first 128 bytes)
PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode
1000, // read timeout
NULL, // authentication on the remote machine
errbuf // error buffer
) ) == NULL)
{
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", argv[1]);
return;
}
//printf("bufsize=%d\n",fp->bufsize); error.
/* Supposing to be on ethernet, set mac destination to */
packet[0]=9;
packet[1]=0;
packet[2]=0;
packet[3]=0;
packet[4]=0;
packet[5]=1;

/* set mac source to */
packet[6]=0;
packet[7]=3;
packet[8]=0xb3;
packet[9]=1;
packet[10]=0x89;
packet[11]=0xe3;

/* Fill the rest of the packet */
packet[12]=0x81;
packet[13]=0x00;
packet[14]=0x80;
packet[15]=0x00;


packet[16]=0x88;
packet[17]=0xb8;
packet[18]=0x01;
packet[19]=0x01;
packet[20]=0x00;
packet[21]=0x6e;
packet[22]=0x00;
packet[23]=0x00;


packet[24]=0x00;
packet[25]=0x00;
packet[26]=0x61;
packet[27]=0x64;
packet[28]=0x80;
packet[29]=0x0e;
packet[30]=0x6d;
packet[31]=0x79;

packet[32]=0x64;
packet[33]=0x6f;
packet[34]=0x6d;
packet[35]=0x2f;
packet[36]=0x6d;
packet[37]=0x79;
packet[38]=0x67;
packet[39]=0x63;

packet[40]=0x52;
packet[41]=0x65;
packet[42]=0x66;
packet[43]=0x31;
packet[44]=0x81;
packet[45]=0x01;
packet[46]=0x04;
packet[47]=0x82;

packet[48]=0x10;
packet[49]=0x6d;
packet[50]=0x79;
packet[51]=0x64;
packet[52]=0x6f;
packet[53]=0x6d;
packet[54]=0x2f;
packet[55]=0x6d;

packet[56]=0x79;
packet[57]=0x64;
packet[58]=0x61;
packet[59]=0x74;
packet[60]=0x61;
packet[61]=0x73;
packet[62]=0x65;
packet[63]=0x74;

packet[64]=0x31;
packet[65]=0x83;
packet[66]=0x0a;
packet[67]=0x74;
packet[68]=0x65;
packet[69]=0x73;
packet[70]=0x74;
packet[71]=0x41;

packet[72]=0x70;
packet[73]=0x70;
packet[74]=0x49;
packet[75]=0x44;
packet[76]=0x31;
packet[77]=0x84;
packet[78]=0x08;
packet[79]=0x3f;

packet[80]=0xfb;
packet[81]=0x32;
packet[82]=0x4c;
packet[83]=0x00;
packet[84]=0x00;
packet[85]=0x00;
packet[86]=0x00;
packet[87]=0x85;

packet[88]=0x01;
packet[89]=0x01;
packet[90]=0x86;
packet[91]=0x01;
packet[92]=0x01;
packet[93]=0x87;
packet[94]=0x01;
packet[95]=0x01;

packet[96]=0x88;
packet[97]=0x01;
packet[98]=0x20;
packet[99]=0x89;
packet[100]=0x01;
packet[101]=0x00;
packet[102]=0x8a;
packet[103]=0x01;

packet[104]=0x03;
packet[105]=0xab;
packet[106]=0x15;
packet[107]=0x87;
packet[108]=0x05;
packet[109]=0x08;
packet[110]=0x40;
packet[111]=0x87;

packet[112]=0x7c;
packet[113]=0xee;
packet[114]=0x87;
packet[115]=0x05;
packet[116]=0x08;
packet[117]=0x40;
packet[118]=0xc7;
packet[119]=0x7c;

packet[120]=0xee;
packet[121]=0x87;
packet[122]=0x05;
packet[123]=0x08;
packet[124]=0x41;
packet[125]=0x03;
packet[126]=0xc2;
packet[127]=0x8f;

/* Send down the packet */
if (pcap_sendpacket(fp, packet, 128 /* size */) != 0)
{
fprintf(stderr,"\nError sending the packet: %s\n", pcap_geterr(fp));
return;
}

return;
}


编译通过了,但不知道为什么没有报文发出来,是我的网卡选的不对还是什么?
...全文
23 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

69,387

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧