⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 neighbor_list.c

📁 一种AODV实现方法
💻 C
字号:
/*               Kernel AODV  v2.0National Institute of Standards and Technology               Luke Klein-Berndt-----------------------------------------------------  Version 2.0 new features:     * Updated to AODV draft version 11     * Managed internet gatewaying     * Monitor wireles signal strength     * Many bug fixes!-----------------------------------------------------Originally based upon MadHoc code. I am notsure how much of it is left anymore, but MadHocproved to be a great starting point.MadHoc was written by - Fredrik Lilieblad,Oskar Mattsson, Petra Nylund, Dan Ouchterlonyand Anders Roxenhag Mail: mad-hoc@flyinglinux.netThis software is Open Source under the GNU General Public Licence.*/#include "neighbor_list.h"/****************************************************   neighbor_list----------------------------------------------------This is a list of the neighboring nodes****************************************************/struct neighbor_list_entry *neighbor_list;extern u_int32_t g_broadcast_ip;/****************************************************   init_interface_list----------------------------------------------------Discover the available interfaces and add themto the list****************************************************/int init_neighbor_list(){    neighbor_list=NULL;    return 0;}/****************************************************   find_interface_by_dev----------------------------------------------------Finds an interface by matching up the dev tothe dev in the interface list****************************************************/struct neighbor_list_entry *find_neighbor_list_entry(u_int32_t ip){    struct neighbor_list_entry *tmp_entry=neighbor_list;    //search the interface list for a device with the same ip    while (tmp_entry!=NULL)    {        if (tmp_entry->ip==ip)            return tmp_entry;        tmp_entry=tmp_entry->next;    }    return NULL;}void update_link_by_hw(char *hw_addr,u_int8_t link){    struct neighbor_list_entry *tmp_entry=neighbor_list;    struct route_table_entry *tmp_route;    u_int8_t link_temp;    //search the interface list for a device with the same ip    while (tmp_entry!=NULL)    {        if (!memcmp(&(tmp_entry->hw_addr), hw_addr, ETH_ALEN))        {            tmp_entry->link=link;            tmp_route=find_route_table_entry(tmp_entry->ip);            if (tmp_route!=NULL)                tmp_route->link=link;        }        tmp_entry=tmp_entry->next;    }}struct neighbor_list_entry *find_first_neighbor_list_entry(){    return neighbor_list;}int delete_neighbor_list_entry(u_int32_t ip){    struct neighbor_list_entry *tmp_entry=neighbor_list;    struct neighbor_list_entry *prev_entry=NULL;    //search the interface list for a device with the same ip    while (tmp_entry!=NULL)    {        if (tmp_entry->ip==ip)        {            if (prev_entry!=NULL)                prev_entry->next=tmp_entry->next;            else                neighbor_list=tmp_entry->next;            kfree(tmp_entry);            delete_timer_queue_entry_of_id(ip, EVENT_NEIGHBOR);            update_timer_queue();            return 1;        }        prev_entry=tmp_entry;        tmp_entry=tmp_entry->next;    }    return 0;}struct neighbor_list_entry *create_neighbor_list_entry(u_int32_t ip){    struct neighbor_list_entry *tmp_entry;    int i;    if ((tmp_entry = kmalloc(sizeof(struct neighbor_list_entry),GFP_ATOMIC)) == NULL)    {#ifndef NO_ERROR        printk("NEIGHBOR_LIST: Can't allocate new entry\n");#endif        return NULL;    }    tmp_entry->next=neighbor_list;    tmp_entry->ip=ip;    tmp_entry->lifetime=0;    tmp_entry->link=255;    tmp_entry->route_entry=NULL;    neighbor_list=tmp_entry;    return tmp_entry;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -