为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

winpcap发送数据包

2017-11-11 4页 doc 16KB 24阅读

用户头像

is_358746

暂无简介

举报
winpcap发送数据包winpcap发送数据包 #include "pcap.h" #pragma comment(lib,"wpcap.lib") #pragma comment(lib,"ws2_32.lib") void usage(); main() { pcap_if_t *alldevs; pcap_if_t *d; u_char packet[100]; int inum; int i=0; pcap_t *adhandle; char errbuf[PCAP_ERRBUF_SIZE]; /* 获得网卡的列表...
winpcap发送数据包
winpcap发送数据包 #include "pcap.h" #pragma comment(lib,"wpcap.lib") #pragma comment(lib,"ws2_32.lib") void usage(); main() { pcap_if_t *alldevs; pcap_if_t *d; u_char packet[100]; int inum; int i=0; pcap_t *adhandle; char errbuf[PCAP_ERRBUF_SIZE]; /* 获得网卡的列表 */ if (pcap_findalldevs(&alldevs, errbuf) == -1) { fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf); exit(1); } /* 打印网卡信息 */ for(d=alldevs; d; d=d->next) { printf("%d. %s", ++i, d->name); if (d->description) printf(" (%s)\n", d->description); else printf(" (No description available)\n"); } if(i==0) { printf("\nNo interfaces found! Make sure WinPcap is installed.\n"); return -1; } printf("Enter the interface number (1-%d):",i); scanf("%d", &inum); //输入要选择打开的网卡号 if(inum < 1 || inum > i) //判断号的合法性 { printf("\nInterface number out of range.\n"); /* Free the device list */ pcap_freealldevs(alldevs); return -1; } /* 找到要选择的网卡结构 */ for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++); /* 打开选择的网卡 */ if ( (adhandle= pcap_open_live(d->name, // 设备名称 65536, // portion of the packet to capture. // 65536 grants that the whole packet will be captured on all the MACs. 1, // 混杂模式 1000, // 读超时为1秒 errbuf // error buffer ) ) == NULL) { fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n"); /* Free the device list */ pcap_freealldevs(alldevs); return -1; } /* 假设网络环境为ethernet,我门把目的MAC设为1:1:1:1:1:1*/ packet[0]=1; packet[1]=1; packet[2]=1; packet[3]=1; packet[4]=1; packet[5]=1; /* 假设源MAC为 2:2:2:2:2:2 */ packet[6]=2; packet[7]=2; packet[8]=2; packet[9]=2; packet[10]=2; packet[11]=2; packet[12]=0x66; packet[13]=0x66; /* 填充发送包的剩余部分 */ //for(i=15;i<100;i++){ // packet[i]=i%256; //} /* 发送包 */ pcap_sendpacket(adhandle, packet, 100); pcap_sendpacket(adhandle, packet, 100); return 0; }
/
本文档为【winpcap发送数据包】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索