根据我个人的思路写的防ARP代码
根据我个人的思路写的防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={0x00,0x40,0xca,0x66,0x41,0x9f};
libnet_t *l;
libnet_ptag_t t;
char *device = NULL;
u_int8_tpacket;
u_int32_t packet_s;
char errbuf;
if (argc > 1)
{
device = argv;
}
packet_s = sizeof(packet);
for(m=0;m<packet_s;m++) packet = 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);
} 来这里看 ROS 的没几个人看的懂……我是小白…… 加油~~ ;P 单方面不能解决问题的
页:
[1]