- 论坛徽章:
- 6
|
回复 #2 wojiaohesen 的帖子
谢谢啊
小弟已经通过libnet实现了,呵呵
顺便把代码贴出来吧
#include <libnet.h>
#include <stdlib.h>
int main()
{
u_char *name="192.168.0.1";
u_long dst_ip=0,src_ip=0;
libnet_t *l;
libnet_ptag_t t;
u_char enet_src[6]={0x00,0x16,0x36,0x5a,0x31,0x91};
u_char enet_dst[6]={0xff,0xff,0xff,0xff,0xff,0xff};
u_char ip_dst[4]={0xc0,0xa8,0x00,0x01};
u_long i;
char *device=NULL;
char errbuf[LIBNET_ERRBUF_SIZE];
l=libnet_init(LIBNET_LINK_ADV,device,errbuf);
if(l==NULL)
{
fprintf(stderr,"libnet_init() failed %s\n",errbuf);
exit(0);
}
i=libnet_get_ipaddr4(l);
t=libnet_build_arp(ARPHRD_ETHER,ETHERTYPE_IP,6,4,ARPOP_REQUEST,enet_src, (u_int32_t*)&i,enet_dst,ip_dst,NULL,0,l,0);
t=libnet_autobuild_ethernet(enet_dst,ETHERTYPE_ARP,l);
libnet_write(l);
libnet_destroy(l);
} |
|