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

📄 crc_main.cc

📁 OLSR Implementation for XORP
💻 CC
📖 第 1 页 / 共 3 页
字号:
		olsr_if_index[iface_index] = ifp->int_ifindex; //the int_ifindex of a certain interface;		memcpy(&(addr[iface_index].sin6_addr.s6_addr), &addr_manet[iface_index],sizeof(struct olsr_ip_addr));		iface_index++;		num_of_interface++;	}	printf ("........ the main address used in this node is: %s.............\n", convert_address_to_string(&my_main_addr));	printf ("......... number of interface is: %d........................\n", num_of_interface);		/* Initialisation of differents tables to be used.*/	olsr_init_tables();	memset(&saved_gateway,0,sizeof(struct gateway)); 	if(role==MANETNODE)	{		//delete_subnet_default_entry(&addr_ip,addr_ip_prefix); //commented by Y.Ge				/********************* added by Y.Ge ****************/		for (ifp = ifnet; ifp; ifp = ifp->int_next)		{			delete_subnet_default_entry(&addr_manet[ifp->my_index],ifp->int6_site_prefix,ifp->my_index); 		}		/******************** end of revision *************/	}    	if (filter)    		load_topology_filter();     	/* 	 * Build and send empty HELLO.	 */        	for (ifp = ifnet; ifp; ifp = ifp->int_next) 	{		//added by L.Qin, whether the hello message is built for eth1		printf("in the main, the interface index is: %d\n",ifp->my_index);				hellopack.neighbors = (struct hello_neighbor *)NULL;		olsr_build_hello_packet(&hellopack, ifp->my_index);		hello_build((struct sockaddr *)NULL, &hellopack, (struct tc_message *)NULL, (struct mid_message *)NULL, (struct hna_message *)NULL, 0, ifp);		tointerface (sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL, ifp->my_index);	}        	//toall(hello_build, &hellopack, (struct tc_message *)NULL,(struct	hna_message *)NULL,(struct interface *)NULL);	//toall(hna_build, (struct hello_message *)NULL,(struct tc_message *)NULL,&hnainfo,(struct interface *)NULL);	//toall(sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL);				signal(SIGALRM, timer);	signal(SIGINT, olsr_delete_all_kernel_routes);  	signal(SIGUSR1, sigtrace);	signal(SIGUSR2, sigtrace);	srandom(getpid());	if (setitimer(ITIMER_REAL, &itval, (struct itimerval *)NULL) < 0)		syslog(LOG_ERR, "setitimer: %m\n");	nfd=0;	for (i=0; i<num_of_interface; i++)	{		if((s6[i] + 1) > nfd)			nfd = s6[i] + 1;	}	// added by L.Qin, start the OLSR target module  *****//    xlog_init(argv[0], 0);//    xlog_set_verbose(XLOG_VERBOSE_HIGH);//    xlog_add_default_output();//    xlog_start();    //    XrlOlsrTarget tgt_target(&tgt_router);//    printf("*-*-*- start running olsr target\n");    //    bool timeout = false;//    XorpTimer t = e.set_flag_after_ms(2000, &timeout);//    while (timeout == false && tgt_router.ready() == false)//	e.run();//create a routing table in the RIB    XrlRibNotifier xn;    xn.startup();    printf("-*-*-* create a RIB table\n");        if (timeout) {	fprintf(stderr, "Timed out connecting to finder\n");	exit(-1);    }//*****	for (;;)	{		//added by L.Qin *****		  		e.run();		//*****		FD_ZERO(&ibits);				for(i = 0;i < num_of_interface; i++)		{	  		FD_SET(s6[i], &ibits);			}				tvp = (struct timeval *)NULL;		n = select(nfd, &ibits, 0, 0, tvp);				if (n <= 0) 		{			if (n < 0) 			{				if (errno == EINTR)				{					continue;				}				syslog(LOG_ERR, "select: %m");			}		}		(void) gettimeofday(&now, (struct timezone *)NULL);				sigemptyset(&sigSet);		sigaddset(&sigSet, SIGALRM);		sigprocmask(SIG_BLOCK, &sigSet, &osigset);		/*********** added by Y.Ge **********/		for (i=0; i<num_of_interface; i++)		{			if (FD_ISSET (s6[i], &ibits))			{				if (debug_level > 5)				{					printf ("&&&&&&&&&&&&&&&&&& packet received from iface:%d &&&&&&&&&&&&&&&&&&\n", i);					fprintf (y_file,"&&&&&&&&&&&&&&&&&& packet received from iface:%d &&&&&&&&&&&&&&&&&&\n", i);					//exit (1);				}			//	printf ("&&&&&&&&&&&&&&&&&& packet received from iface:%d &&&&&&&&&&&&&&&&&&\n", i);				process(s6[i], sd[i], i);			}		}		/********* end of revision *********/		// handle ICMP redirects 		sigprocmask(SIG_SETMASK, &osigset, NULL);	} /* for(;;) */			//added by L.Qin	xlog_stop();        xlog_exit();} /* main *//*************************** end of revision *******************/void process(int fd, int qd, int index) //"index" is added by Y.Ge, which interface the packet is recieved?{	struct sockaddr_in6 from;	size_t fromlen = sizeof(struct sockaddr_in6);	int cc, rtflags=0;	union 	{		char	buf[MAXPACKETSIZE+1];		struct	olsr olsr;	} inbuf;	char str[46];	struct sockaddr_in6* sinfrom; 	struct olsr *olsrptr = (struct olsr*)&(inbuf.olsr);	struct olsr_ip_addr	inaddrany = in6addr_any;	for (;;) 	{		fromlen = sizeof (from);		cc = recvfrom(fd, &inbuf, sizeof (inbuf), 0, (struct sockaddr*)&from, &fromlen);		if (cc <= 0) {			if (cc < 0 && errno != EWOULDBLOCK)				perror("recvfrom");				break;		}		/*v4->v6 del if (fromlen != sizeof (struct sockaddr_in))*/		if (fromlen != sizeof (struct sockaddr_in6))			break;        sinfrom = (struct sockaddr_in6*)&from;	//added by L.Qin//	printf("**************main: the index %d\n",index);        olsr_input((struct sockaddr*)&from, &inbuf.olsr, cc, index); //"index" is added by Y.Ge                //CRC added        if(role==MOBILENODE){                	if(debug_level>6)        	{        		printf("before ioctl(sd,SIOCSRTDEL) in main.c\n");        		printf("saved_gateway: %s\n",inet_ntop(AF_INET6,&(saved_gateway.gw_addr),str,sizeof(str)));        	}        	        	//if((rtflags=ioctl(sd,SIOCSRTDEL,0))<0){		if((rtflags=ioctl(qd,SIOCSRTDEL,0))<0){				perror("ioctl");				syslog(LOG_ERR, "ioctl: %m");			}						if(rtflags==1){				//if(ioctl(sd,SIOCSFLAGSET,0)<0){				if(ioctl(qd,SIOCSFLAGSET,0)<0){				perror("ioctl");				syslog(LOG_ERR, "ioctl: %m");				}				olsr_release_tables(1);				olsr_init_tables();								if(0==memcmp(&inaddrany,&saved_gateway.gw_addr,sizeof(struct olsr_ip_addr)))				{					rt_reset=1;					refresh=1;				}				else				{					rt_reset=0;					refresh=0;     			}								if(debug_level>6)				{					printf("********routingtable*********\n"); 					olsr_print_routing_table(routingtable); 					printf("********mirror_table*********\n");  					olsr_print_routing_table(mirror_table); 				}			}		}	 	}}int getsocket(int domain, int type, struct sockaddr *sa){	/*v4->v6 del struct sockaddr_in *sin=(struct sockaddr_in *)sa;*/	//CRC v4->v6 add	struct sockaddr_in6 *sin = (struct sockaddr_in6 *)sa;	int sock, on = 1, longueur;		/* memset(sin, 0 sizeof (struct sockaddr_in6));	sin->sin6_family = AF_INET6;	sin->sin6_port = sp->s_port;*/	printf ("++++++++++++++++ in getsocket +++++++++++++\n");	printf ("address is:  %s\n", convert_address_to_string (&sin->sin6_addr));	if ((sock = socket(domain, type, 0)) < 0) {		perror("socket");		syslog(LOG_ERR, "socket: %m");		return (-1);	}/* CRC v4->v6 del#ifdef SO_BROADCAST	if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0)	  {		syslog(LOG_ERR, "setsockopt SO_BROADCAST: %m");		close(sock);		return (-1);	  }#endif#ifdef SO_RCVBUF	for (on = bufspace; ; on -= 1024) {		if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,		    &on, sizeof (on)) == 0)			break;		if (on <= 8*1024) {			syslog(LOG_ERR, "setsockopt SO_RCVBUF: %m");			break;		}	}	if (traceactions)		fprintf(ftrace, "recv buf %d\n", on);#endif*/	printf ("address is: %s\n", convert_address_to_string (&sin->sin6_addr));		//MAOYU 	/********** reuse the in6addr_any ***********/	if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0)	  {		syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");		close(sock);		return (-1);	  }				if (bind(sock, (struct sockaddr *)sin, sizeof (*sin)) < 0) 	{		perror("bind");		syslog(LOG_ERR, "bind: %m");		close(sock);		return (-1);	}		if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1)		syslog(LOG_ERR, "fcntl O_NONBLOCK: %m\n");		return (sock);}//CRC v4->v6 addint setmulticast(int sock,struct interface* ifp){    struct ipv6_mreq mreq6;    int if_index;    memcpy(&mreq6.ipv6mr_multiaddr,&ifp->int6_multi_addr, sizeof(struct in6_addr));    mreq6.ipv6mr_interface = ifp->int_ifindex;    if_index=ifp->int_ifindex;     if(setsockopt(sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6))<0)    return (-1);        if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof(mreq6))<0)    return -1;        if(setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_IF, &if_index, sizeof(if_index))<0)    return (-1);    return (0);  }//CRC v4->v6 addvoid init(){	int i;		//memset(&addr,0,sizeof(struct sockaddr_in6)); //commented by Y.Ge	memset(&addr_ip,0,sizeof(struct olsr_ip_addr));	memset(&addr_coa,0,sizeof(struct olsr_ip_addr));	//memset(&addr_manet,0,sizeof(struct olsr_ip_addr)); //commented by Y.Ge	for (i=0; i<MAXIFACENUM; i++)	{		memset(&addr_manet[i], 0, sizeof(struct olsr_ip_addr));		//memset(&addrsock6[i], 0, sizeof(struct sockaddr_in6));		memset(&addr[i],0,sizeof(struct sockaddr_in6));	} //added by Y.Ge	memset (&my_main_addr, 0, sizeof (struct olsr_ip_addr)); //added by Y.Ge	memset(&multiaddr,0,sizeof(struct olsr_ip_addr));	memset(&addrsock6,0,sizeof(struct sockaddr_in6)); //comment by Y.Ge	memset(packet,0,MAXPACKETSIZE+1);	memset(&saved_gateway,0,sizeof(struct gateway));}

⌨️ 快捷键说明

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