|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
×
根据我个人的思路写的防ARP代码,思路见"WINDOWS防ARP新法"
半成品,只能防一台机器的,要防全网需要改写.
#include <stdio.h>
#include <netinet/in.h>
#include <libnet.h>
#include <sys/socket.h>
#include <unistd.h>
int main(int argc,char *argv[])
{
int m=0;
u_int32_t l_ipaddr,l_ipaddr2 = 0x3200a8c0;
struct libnet_ether_addr *l_hwaddr;
u_int8_t brodcast_hwaddr[6]={0x00,0x40,0xca,0x66,0x41,0x9f};
libnet_t *l;
libnet_ptag_t t;
char *device = NULL;
u_int8_t packet[18];
u_int32_t packet_s;
char errbuf[LIBNET_ERRBUF_SIZE];
if (argc > 1)
{
device = argv[1];
}
packet_s = sizeof(packet);
for(m=0;m<packet_s;m++) packet[m] = 0x20;
l = libnet_init(
LIBNET_LINK_ADV,
device,
errbuf);
if (l == NULL)
{
fprintf(stderr, "%s", errbuf);
exit(EXIT_FAILURE);
}
l_ipaddr = libnet_get_ipaddr4(l);
l_hwaddr = libnet_get_hwaddr(l);
t = libnet_build_arp(
ARPHRD_ETHER,
ETHERTYPE_IP,
6,
4,
ARPOP_REPLY,
l_hwaddr->ether_addr_octet,
(u_int8_t *)&l_ipaddr,
brodcast_hwaddr,
(u_int8_t *)&l_ipaddr2,
packet,
packet_s,
l,
0);
if (t == -1)
{
fprintf(stderr, "Can't build ARP header: %s\n", libnet_geterror(l));
goto bad;
}
t = libnet_autobuild_ethernet(
brodcast_hwaddr,
ETHERTYPE_ARP,
l);
if (t == -1)
{
fprintf(stderr, "Can't build ethernet header: %s\n",
libnet_geterror(l));
goto bad;
}
while(1){
if (libnet_write(l) == -1)
{
fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
goto bad;
}
else
{
fprintf(stderr, "ARP packet from context \"%s\"; "
"check the wire.\n", libnet_cq_getlabel(l));
}
sleep(5);
}
libnet_destroy(l);
return (EXIT_SUCCESS);
bad:
libnet_destroy(l);
return (EXIT_FAILURE);
} |
|