找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1605|回复: 3

[其它] 根据我个人的思路写的防ARP代码

[复制链接]
发表于 2006-11-29 11:38:11 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
根据我个人的思路写的防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);
}
routeros
发表于 2006-11-29 15:55:35 | 显示全部楼层
来这里看 ROS 的没几个人看的懂……我是小白……
routeros
回复

使用道具 举报

发表于 2006-11-30 10:30:58 | 显示全部楼层
加油~~
routeros
回复

使用道具 举报

发表于 2006-12-7 01:33:09 | 显示全部楼层
单方面不能解决问题的
routeros
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2024-5-6 18:34 , Processed in 0.100587 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表