handle_cfg.c
来自「OLSR Implementation for XORP」· C语言 代码 · 共 245 行
C
245 行
/* * Copyright (c) 2004 Ying Ge, Communication Research Center Canada. * * Copyright (c) 2002, 2003 Maoyu Wang, Communication Research Center Canada. * * By Ying Ge: * 1. Change the OLSR packet format and message processing procedure based * on the OLSR RFC. * 2. Add support of multiple interfaces to OLSR, including MID message * creating and processing procedure as specified in the OLSR RFC. * 3. Add QoS Support to OLSR * * By Maoyu Wang: * 1. Ported OLSR from IPv4 to IPv6. * 2. Added the Host and Network Association (HNA) functionality into OLSR. * 3. Added the default gateway functionality into OLSR by extending the HNA * message usage. The default gateway functionality supported the mobility * by cooperating with Mobile IPv6 for a mobile node as well as supported * Internet access for MANET nodes. * * DISTRIBUTED WITH NO WARRANTY, EXPRESS OR IMPLIED. * See the GNU Library General Public License (file COPYING in the distribution) * for conditions of use and redistribution *//* * Routing table management daemon. */ char handle_cfg_rcsid[] = "$Id: handle_cfg.c,v 1.1 2003/2/20 16:56:12 prima Exp $";#include "defs.h"struct hna_message hnainfo;char* olsr_skip_whitespace(char* p){ while ( p && *p && ( isspace( *p ) || *p == '\n' || *p == '\r' ) ) p++; return p;}void olsr_parse(char* p, char ip[][64], int length[], int* pCount){ char* cut; p = olsr_skip_whitespace(p); cut = strstr(p, " "); length[*pCount] = atoi(cut); strncpy(ip[*pCount], p, cut - p); ip[*pCount][cut - p] = 0; *pCount += 1;}struct hna_net_addr*olsr_lookup_hna_info_node(struct hna_message* message,struct hna_net_addr* netaddr){ struct olsr_ip_addr inaddrany = in6addr_any; struct hna_net_addr *net_addr_ptr; net_addr_ptr=message->hna_net_addrs; while(net_addr_ptr!=NULL) { if((0 == memcmp(&(netaddr->net_addr),&(net_addr_ptr->net_addr),sizeof(struct olsr_ip_addr))) &&(netaddr->prefix==net_addr_ptr->prefix)) return (net_addr_ptr); net_addr_ptr = net_addr_ptr->next; } return NULL;}voidolsr_set_prefix_in_hna_configuration(struct hna_message* message){ struct hna_net_addr *netnode; for(netnode=message->hna_net_addrs;netnode!=NULL;netnode=netnode->next) olsr_prefix_setting(&(netnode->net_addr),netnode->prefix); return;}/*Read the HNA information from configure.txt file and store them into struct hna_message */int olsr_get_hna_configuration(struct hna_message* message){ char ip[16][64]; /*to store the ip*/ int length[16]; /*to store the ip length*/ int i, j, count = 0; int left_bytes=0; char* buf; char* p; char* filename; FILE* fp; unsigned size; struct in6_addr ip6addr_tmp; struct hna_net_addr* netaddr; struct hna_net_addr* netnode; struct hna_net_addr infonode; filename = "configure.txt"; fp = fopen(filename, "r"); if (fp ) { fseek( fp, 0, SEEK_END ); size = ftell( fp ); fseek( fp, 0, SEEK_SET ); buf = (char*)malloc(sizeof(char[size+1])); p = buf; left_bytes = size; while(fgets(p, size, fp ) && left_bytes > 0) { if(strlen(p) > 2) olsr_parse(p, ip, length, &count); left_bytes -= strlen(p); } fclose( fp ); free(buf); if(debug_level>2) { printf ("count = %d\n", count); for(i=0; i<count; i++) printf("IP = %s, length = %d\n", ip[i], length[i]); } if(message->hna_net_addrs==NULL) { message->hna_net_addrs=malloc(sizeof(struct hna_net_addr)); netnode=message->hna_net_addrs; } else { for(netaddr=message->hna_net_addrs;netaddr->next!=NULL;netaddr=netaddr->next); netaddr->next=malloc(sizeof(struct hna_net_addr)); netnode=netaddr->next; } inet_pton(AF_INET6,ip[0],&ip6addr_tmp); memcpy(&(netnode->net_addr),&ip6addr_tmp,sizeof(struct olsr_ip_addr)); netnode->prefix=length[0]; netnode->next=NULL; for(i=1; i<count; i++) { inet_pton(AF_INET6,ip[i],&ip6addr_tmp); memcpy(&(infonode.net_addr),&ip6addr_tmp,sizeof(struct olsr_ip_addr)); infonode.prefix=length[i]; infonode.next=NULL; if(!olsr_lookup_hna_info_node(message,&infonode)) { netnode->next=malloc(sizeof(struct hna_net_addr)); memcpy(&(netnode->next->net_addr),&ip6addr_tmp,sizeof(struct olsr_ip_addr)); netnode->next->prefix=length[i]; netnode=netnode->next; netnode->next=NULL; } } olsr_set_prefix_in_hna_configuration(message); return 0; } else { return 1; }}voidolsr_release_hna_configuration_list(struct hna_message* message){ struct hna_net_addr* netnode; netnode=message->hna_net_addrs; while(netnode!=NULL) { message->hna_net_addrs=message->hna_net_addrs->next; free(netnode); netnode=message->hna_net_addrs; } return;}voidolsr_set_gateway_configuration(struct hna_message* message,olsr_u16_t length){ struct hna_net_addr* netaddr; struct hna_net_addr* netnode; struct hna_net_addr gwnode; struct olsr_ip_addr gwinfo=in6addr_any; memcpy(&(gwnode.net_addr),&gwinfo,sizeof(struct olsr_ip_addr)); gwnode.prefix=length; gwnode.next=NULL; if(message->hna_net_addrs==NULL) { message->hna_net_addrs=malloc(sizeof(struct hna_net_addr)); netnode=message->hna_net_addrs; } else { if(!olsr_lookup_hna_info_node(message,&gwnode)) { for(netaddr=message->hna_net_addrs;netaddr->next!=NULL;netaddr=netaddr->next); netaddr->next=malloc(sizeof(struct hna_net_addr)); netnode=netaddr->next; } else return; } memcpy(&(netnode->net_addr),&gwinfo,sizeof(struct olsr_ip_addr)); netnode->prefix=length; netnode->next=NULL; return;}voidolsr_init_hna_info(){ printf (" ----- in init hna info-----\n"); /*memcpy(&(hnainfo.source_addr),&addr_manet,sizeof(struct olsr_ip_addr)); memcpy(&(hnainfo.originator),&addr_manet,sizeof(struct olsr_ip_addr)); hnainfo.packet_seq_number=0; hnainfo.msg_seq_number=0; hnainfo.hop_count=HOPCNT_MAX;*/ /****************** added by Y.Ge *******************/ memcpy(&(hnainfo.originator),&my_main_addr,sizeof(struct olsr_ip_addr)); hnainfo.v_time = olsr_compute_vtime(HNA_HOLD_TIME); //validity time hnainfo.hop_count =0; hnainfo.time_to_live = HOPCNT_MAX; hnainfo.packet_seq_number = msg_seqnum.hna_seqnum; /****************** end of revision *****************/ hnainfo.hna_net_addrs=NULL; if(role==GATEWAY) olsr_set_gateway_configuration(&hnainfo,GW_PREFIXLEN); olsr_get_hna_configuration(&hnainfo);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?