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

📄 seek_list.c

📁 支持IPv6的adov路由协议(本人修改后)
💻 C
字号:
/***************************************************************************** * * Copyright (C) 2001 Uppsala University and Ericsson AB. * Copyright (C) 2003 Simon Fraser University and NewMIC * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * * Authors: Erik Nordstr鰉, <erik.nordstrom@it.uu.se> *        : Peter Lee       <peter.lee@shaw.ca> *           * *****************************************************************************/#include <stdlib.h>#ifdef NS_PORT#include "aodv-uu.h"#else#include "seek_list.h"#include "timer_queue.h"#include "ipv6_utils.h"#include "aodv_timeout.h"#include "defs.h"#include "params.h"#include "debug.h"#endif#ifndef NS_PORT/* The seek list is a linked list of destinations we are seeking   (with RREQ's). */static seek_list_t *seek_list_head = NULL;#ifdef SEEK_LIST_DEBUGvoid seek_list_print();#endif#endif				/* NS_PORT *///PL#ifdef _IPV6seek_list_t *NS_CLASS seek_list_insert(struct in6_addr dest_addr,				       u_int32_t dest_seqno,                                       //PL: ttl need to be changed later				       int ttl, u_int8_t flags,				       struct ip_data *ipd)#elseseek_list_t *NS_CLASS seek_list_insert(u_int32_t dest_addr,				       u_int32_t dest_seqno,				       int ttl, u_int8_t flags,				       struct ip_data *ipd)#endif /* _IPV6 */{    seek_list_t *entry;    if ((entry = (seek_list_t *) malloc(sizeof(seek_list_t))) < 0) {	fprintf(stderr, "seek_list_insert: Failed malloc\n");	exit(-1);    }    //PL#ifdef _IPV6    memcpy(&entry->dest_addr, &dest_addr, sizeof(dest_addr));#else    entry->dest_addr = dest_addr;#endif /* _IPV6 */    entry->dest_seqno = dest_seqno;    entry->flags = flags;    entry->to_internet=0;    entry->reqs = 0;    entry->ttl = ttl;    entry->ipd = ipd;    entry->seek_timer.handler = &NS_CLASS route_discovery_timeout;    entry->seek_timer.data = entry;    entry->next = seek_list_head;    seek_list_head = entry;    return entry;}//PL#ifdef _IPV6int NS_CLASS seek_list_remove(struct in6_addr dest_addr)#elseint NS_CLASS seek_list_remove(u_int32_t dest_addr)#endif /* _IPV6 */{    seek_list_t *curr, *prev;    curr = seek_list_head;    prev = NULL;    while (curr != NULL) {      //PL#ifdef _IPV6      if (memcmp(&curr->dest_addr, &dest_addr, sizeof(dest_addr)) == 0) {#else	if (curr->dest_addr == dest_addr) {#endif /* _IPV6 */	    if (prev == NULL)		seek_list_head = curr->next;	    else		prev->next = curr->next;	    /* Make sure any timers are removed */	    timer_remove(&curr->seek_timer);	    if (curr->ipd)		free(curr->ipd);	    free(curr);	    return 1;	}	prev = curr;	curr = curr->next;    }    return 0;}//PL#ifdef _IPV6seek_list_t *NS_CLASS seek_list_find(struct in6_addr dest_addr)#elseseek_list_t *NS_CLASS seek_list_find(u_int32_t dest_addr)#endif /* _IPV6 */{    seek_list_t *entry;    entry = seek_list_head;    while (entry != NULL) {      //PL#ifdef _IPV6      if (memcmp(&entry->dest_addr, &dest_addr, sizeof(dest_addr)) == 0)#else	if (entry->dest_addr == dest_addr)#endif /* _IPV6 */	    return entry;	entry = entry->next;    }    return NULL;}//#ifdef SEEK_LIST_DEBUGvoid NS_CLASS seek_list_print(){    seek_list_t *entry;    //PL:#ifdef _IPV6    for (entry = seek_list_head; entry != NULL; entry = entry->next) {	printf("%s %u %d %d\n", ip6_to_str(entry->dest_addr),	       entry->dest_seqno, entry->reqs, entry->ttl);    }#else    for (entry = seek_list_head; entry != NULL; entry = entry->next) {	printf("%s %u %d %d\n", ip_to_str(entry->dest_addr),	       entry->dest_seqno, entry->reqs, entry->ttl);    }#endif /* _IPV6 */}//#endifdest_list_t *seek_list_find_i(){	seek_list_t *entry;	dest_list_t *head=NULL,*tmp=NULL;	entry=seek_list_head;	while(entry!=NULL){		if(entry->to_internet){			if((tmp=(dest_list_t *)malloc(sizeof(dest_list_t)))==NULL){				fprintf(stderr,"malloc failed!\n");				exit(1);			}			if(head==NULL){				head=tmp;				head->next=NULL;			}else{				tmp->next=head;				head=tmp;			}			head->dest_addr=entry->dest_addr;		}		entry=entry->next;	}	return head;}

⌨️ 快捷键说明

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