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

📄 address_arep.c

📁 支持IPv6的adov路由协议(本人修改后)
💻 C
字号:
#include "address_arep.h"#include "address_conf.h"#include "debug.h"#include "aodv_socket.h"#include "ipv6_utils.h"AREP *arep_create(struct in6_addr  req_addr,u_int32_t seqno,u_int32_t id){        AREP *arep;                                                                                                                                     arep = (AREP *) aodv_socket_new_msg();        arep->type = AODV_AREP;        arep->code=0;        arep->checksum=0;/*to be coded!*/        copy_in6_addr(&arep->request_addr,&req_addr);                                                                                arep->seqno = htonl(seqno);        arep->id=htonl(id);        DEBUG(LOG_DEBUG, 0, "arep_create: Assembled AREP %s", ip6_to_str(req_addr));        #ifdef DEBUG_OUTPUT        log_pkt_fields((AODV_msg *) arep);        #endif        return arep;}void arep_send(struct in6_addr req_addr,u_int32_t seqno,u_int32_t id,struct in6_addr ip_dest,int ttl){        AREP *arep;        int i;                                                                                                                                     /* Broadcast on all interfaces */        for (i = 0; i < MAX_NR_INTERFACES; i++) {                if (!DEV_NR(i).enabled)                        continue;                arep = arep_create(req_addr,seqno,id);        printf("ZJH:arep_send!!!\n");        aodv_socket_send((AODV_msg *) arep, ip_dest, AREP_SIZE, ttl,&DEV_NR(i));        }}                                                                                                                             void arep_forward(AREP *arep,struct in6_addr ip_dest,int ttl){        int i;        printf("ZJH:arep forward!!!\n");        /* FORWARD the RREQ if the TTL allows it. */        DEBUG(LOG_INFO, 0, "forwarding AREP requst_ip=%s, areq_id=%lu",          ip6_to_str(arep->req_addr), ntohl(arep->id));                                                                                                                                     /* Queue the received message in the send buffer */        arep = (AREP *) aodv_socket_queue_msg((AODV_msg *) arep, AREP_SIZE);                                                                                                                                     /* Send out on all interfaces */        for (i = 0; i < MAX_NR_INTERFACES; i++) {                if (!DEV_NR(i).enabled)                        continue;                aodv_socket_send((AODV_msg *) arep,ip_dest, AREP_SIZE, ttl,&DEV_NR(i));        }}void arep_process(AREP *arep, int areplen, struct in6_addr ip_src,struct in6_addr ip_dst, int ip_ttl, unsigned int ifindex){                                                                                                                             	rt_table_t *rev_rt;        struct in6_addr req_addr;        u_int32_t areq_id;        areq_id = ntohl(arep->id);        copy_in6_addr(&req_addr, &arep->request_addr);                                                                                                                                     /* Ignore AREP's that originated from this node. Either we do this        or we buffer our own sent AREP's as we do with others we receive. */                                                                                                                                     //if (memcmp(&ip_src, &(DEV_IFINDEX(ifindex).ipaddr), sizeof(struct in6_addr)) ==0)	if(to_my_address(ip_src))                return;                                                                                                                                     if (areplen < (int) AREP_SIZE) {                log(LOG_WARNING, 0,                        "arep_process: IP data field too short (%u bytes) from %s to %s,request %s",                        areplen, ip6_to_str(ip_src), ip6_to_str(ip_dst),ip6_to_str(req_addr));                return;        }        DEBUG(LOG_DEBUG, 0,"AREP_process: ip_src=%s ip_dest=%s request_addr=%s",                ip6_to_str(ip_src),ip6_to_str(ip_dst),ip6_to_str(req_addr));	/* Check if this AREP was for us (i.e. we previously made a AREQ for this request address). */	if((memcmp(&req_addr,&areq_info.request_addr,sizeof(struct in6_addr))==0)&&		(areq_id==areq_info.id)){		//do address config again;		tentative_addr_conf();	}else{		rev_rt=rt_table_find_active(req_addr);		if(rev_rt&&(rev_rt->flags==TEMP))			arep_forward(arep,rev_rt->next_hop,--ip_ttl);		else			DEBUG(LOG_DEBUG, 0, "Could not forward AREP - NO ROUTE!!!");	}}	

⌨️ 快捷键说明

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