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

📄 output.c

📁 OLSR Implementation for XORP
💻 C
📖 第 1 页 / 共 5 页
字号:
		m_tmp->olsr_msgtype = TC_PACKET;		m_tmp->olsr_vtime = message->v_time;		m_tmp->olsr_msgsize = (char *)mprsaddr - (char *)m_tmp;		m_tmp->olsr_msgsize = htons(m_tmp->olsr_msgsize);		m_tmp->olsr_ttl = message->time_to_live;		m_tmp->olsr_hopcount = message->hop_count;		if (relay)			m_tmp->olsr_msgseq = htons(message->packet_seq_number);		else			m_tmp->olsr_msgseq = htons(current_seq_number);		memcpy(&(m_tmp->olsr_source),&(message->originator),sizeof(struct olsr_ip_addr));		tc->tc_mprseqnum = htons(message->mssn);		memset(tc->tc_res, 0, sizeof(tc->tc_res));					/* copy the TC packet from packet_tmp to packet */		for (i=0; i<outputsize_tmp; i++)		{			packet[current_qostc_position+i]=packet_tmp[i+4];		}				/*j=0;		for (i=0; i<current_qostc_position; i++)		{			if (j==4)			{				printf("\n");				j=0;			}			printf ("i=%d, packet: %d  ", i, packet[i]);			j++;		}		printf("\n");				j=0;		for (i=0; i<outputsize_tmp; i++)		{						if (j==4)			{				printf("\n");				j=0;			}			printf ("i=%d, packet_tmp: %d  ", i, packet_tmp[i]);			j++;			//packet[current_qostc_position + i] = packet_tmp[i];		}		printf("\n");*/	}		if (debug_level > 3)	{		printf ("++++++++++ QoS TC packet built finished!\n");		//printf (" Message sequence: %d\n", ntohs(msg->olsr_seqnum));		printf (" TC sequence: %d\n", ntohs(m->olsr_msgseq));		printf (" TC mssn: %d\n", message->mssn);		printf (" Originator's busy time: %d\n", qostc->qostc_originator_busy);		printf (" QoS TC packet size: %d\n", (char *)mprsbusytime - (char *)m);		printf (" TC packet size: %d\n", (char *)mprsaddr - (char *)m_tmp);						fprintf (y_file,"++++++++++ QoS TC packet built finished!\n");		//fprintf (y_file," Message sequence: %d\n", ntohs(msg->olsr_seqnum));		fprintf (y_file," TC sequence: %d\n", ntohs(m->olsr_msgseq));		fprintf (y_file," TC mssn: %d\n", message->mssn);		fprintf (y_file," Originator's busy time: %d\n", qostc->qostc_originator_busy);		fprintf (y_file," QoS TC packet size: %d\n", (char *)mprsbusytime - (char *)m);		fprintf (y_file," TC packet size: %d\n", (char *)mprsaddr - (char *)m_tmp);	}		if (outputsize > MAXPACKETSIZE - (int)sizeof (struct olsrmsg)) 	{		tointerface (sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL, ifp->my_index); //added by Y.Ge	}}/********************************* end of revision *********************//* * Generate TC packet with the contents of the parameter "message". * If this won't fit in one packet, chop it up into several. * Send the packet if the size of the data contained in the output buffer * reach MAXPACKETSIZE. Don't generate an empty TC packet. * The parameter messag is not used. */ void tc_build(struct sockaddr *dst, struct hello_message *messag, struct tc_message *message, struct mid_message *mmessage, struct hna_message *messg, int flags, struct interface *ifp, int relay)           {	/*void (*output)(int,int,struct sockaddr *,int) = afswitch[dst->sa_family].af_output;*/	/*int remainsize = outputsize - (sizeof(msg->olsr_packlen)  + sizeof(msg->olsr_res));*/ //commented by Y.Ge	int remainsize = outputsize - comm_head_size;  //addedd by Y.Ge	struct tc_mpr_addr *mprs, *prev_mprs;	struct olsrmsg *m = outputsize ? (struct olsrmsg *)((char *)msg->olsr_msg + remainsize) : msg->olsr_msg;	struct tcmsg *tc = m->olsr_tc;	//CRC v4->v6 add	struct olsr_ip_addr *mprsaddr = tc->tc_mprsaddr; 	struct interface *interf;	struct sockaddr address;	int found = 0;	if (debug_level > 3)	{		printf ("\n\n-------------- in tc build -----------------\n");		fprintf (y_file,"\n\n-------------- in tc build -----------------\n");		printf ("originator address: %s\n", convert_address_to_string(&message->originator));		fprintf (y_file, "originator address: %s\n", convert_address_to_string(&message->originator));		printf ("sending address: %s\n", convert_address_to_string(&addr_manet[ifp->my_index]));		fprintf (y_file,"sending address: %s\n", convert_address_to_string(&addr_manet[ifp->my_index]));	}		if (outputsize > MAXPACKETSIZE - (int)sizeof (struct olsrmsg)) 	{		msg->olsr_packlen = htons(outputsize);		//memset(msg->olsr_res, 0, sizeof(msg->olsr_res));  //commented by Y.Ge		//msg->olsr_seqnum = htons(pkt_seqnum[ifp->my_index]++); 	//added by Y.Ge 		//TRACE_OUTPUT(ifp, dst, outputsize);		//(*output)(s6, flags, dst, outputsize);		//inet6_output(s6, flags, dst, outputsize); //commented by Y.Ge		tointerface (sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL, ifp->my_index); //added by Y.Ge	}            	if (!message)		return;		/*CRC v4->v6 del	memset(address.sa_data, 0, sizeof(address.sa_data));	((struct sockaddr_in *)&address)->sin_addr.s_addr = message->originator;	address.sa_family = AF_INET;	interf = if_ifwithaddr(&address);*/	//CRC v4->v6 add	memset(&address, 0, sizeof(address));	//memcpy(&(((struct sockaddr_in6 *)&address)->sin6_addr.s6_addr), &(message->originator),sizeof(struct in6_addr)); //commented by Y.Ge	memcpy(&(((struct sockaddr_in6 *)&address)->sin6_addr.s6_addr), &addr_manet[ifp->my_index],sizeof(struct in6_addr)); //added by Y.Ge	address.sa_family = AF_INET6;	interf = if_ifwithaddr6(&address);	if (debug_level > 3)	{		printf ("include the mpr selector addresses!\n");		fprintf (y_file,"include the mpr selector addresses!\n");	}		for (mprs = message->multipoint_relay_selector_address; mprs != NULL; mprs = mprs->next) 	{		if (debug_level > 3)		{			printf ("+++ mpr selector: %s\n", convert_address_to_string(&mprs->address));			fprintf (y_file,"+++ mpr selector: %s\n", convert_address_to_string(&mprs->address));		}				outputsize = (char *)mprsaddr - packet;				/* printf ("+++++++ outputsize: %d\n", outputsize);		fprintf (y_file,"+++++++ outputsize: %d, sizeof addr: %d, maxpacketsize: %d\n", outputsize,(int)sizeof (mprsaddr),MAXPACKETSIZE); */				//the following IF is revised by Y.Ge. Original one: "if (outputsize > MAXPACKETSIZE - (int)sizeof (mprsaddr)))"		if (outputsize > MAXPACKETSIZE - (int)sizeof (struct olsr_ip_addr))		{			msg->olsr_packlen = htons(outputsize);			//memset(msg->olsr_res, 0, sizeof(msg->olsr_res));  //commented by Y.Ge			//msg->olsr_seqnum = htons(pkt_seqnum[ifp->my_index]++); 	//added by Y.Ge			m->olsr_msgtype = TC_PACKET;			m->olsr_vtime = message->v_time; //added by Y.Ge			//m->olsr_broad = MSG_BROADCAST;  //commented by Y.Ge			//m->olsr_nextmsg = (char *)mprsaddr - (char *)m;   //commented by Y.Ge			//m->olsr_nextmsg = htons(m->olsr_nextmsg);         //commented by Y.Ge			m->olsr_msgsize = (char *)mprsaddr - (char *)m;    //added by Y.Ge			m->olsr_msgsize = htons(m->olsr_msgsize);    //added by Y.Ge			m->olsr_ttl = message->time_to_live;  //added by Y.Ge			m->olsr_hopcount = message->hop_count;  //added by Y.Ge						/************ added by Y.Ge *********/			/* deal with the packet sequence number for the chunked packet */			if (relay)			{				printf (" XXXXXXXX something wrong! relayed TC should not be chunked XXXXXX\n");				exit (1);			}			m->olsr_msgseq = htons(message->packet_seq_number + tc_chunk[ifp->my_index]); 			tc_chunk[ifp->my_index] ++;			/************ end of revision ******/						//CRC HNA add			//------------------------------------------------------------------			//memcpy(&(m->olsr_source),&addr_ip,sizeof(struct olsr_ip_addr));			//memcpy(&(m->olsr_source),&(message->source_addr),sizeof(struct olsr_ip_addr)); //commented by Y.Ge			memcpy(&(m->olsr_source),&(message->originator),sizeof(struct olsr_ip_addr)); //added by Y.Ge			//-------------------------------------------------------------------			/*if (interf)            				//tc->tc_seqnum = htons(tc_seqnum++); 			else				tc->tc_seqnum = htons(message->packet_seq_number);*/ //commented by Y.Ge						tc->tc_mprseqnum = htons(message->mssn);			/*tc->tc_hopcnt = message->hop_count;*/ //commented by Y.Ge			memset(tc->tc_res, 0, sizeof(tc->tc_res));			//CRC v4->v6 del tc->tc_origaddr = message->originator;			//CRC v4->v6 add			/*memcpy(&(tc->tc_origaddr),&(message->originator),sizeof(struct olsr_ip_addr));*/ //commented by Y.Ge						if (debug_level > 3)			{				printf ("++++++++++ TC packet chunked!\n");				//printf (" Message sequence: %d\n", ntohs(msg->olsr_seqnum));				printf (" TC sequence: %d\n", ntohs(m->olsr_msgseq));				printf (" TC packet size: %d\n", (char *)mprsaddr - (char *)m);								fprintf (y_file,"++++++++++ TC packet chunked!\n");				//fprintf (y_file," Message sequence: %d\n", ntohs(msg->olsr_seqnum));				fprintf (y_file," TC sequence: %d\n",ntohs(m->olsr_msgseq));				fprintf (y_file," TC packet size: %d\n", (char *)mprsaddr - (char *)m);			}		  			//TRACE_OUTPUT(ifp, dst, outputsize);			//(*output)(s6, flags, dst, outputsize);			//inet6_output(s6, flags, dst, outputsize); //commented by Y.Ge			tointerface (sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL, ifp->my_index); //added by Y.Ge 						m = msg->olsr_msg;			tc = m->olsr_tc;			mprsaddr = tc->tc_mprsaddr;			found = 0;		}		found = 1; 		//CRC v4->v6 del *mprsaddr = mprs->address;		//CRC v4->v6 add		memcpy(mprsaddr,&(mprs->address),sizeof(struct olsr_ip_addr));		mprsaddr++;	}	//if (found) //commented by Y.Ge		/*	 * Y.Ge: TC should be sent out in the following conditions	 * a) mpr selector table is not NULL	 * b) mpr selector table times out and become empty for the first time	 * c) the TC is to be relayed	 */	if (found || (found ==0 && changes) || (found ==0 && relay))  //added by Y.Ge	{		/************** added by Y.Ge *************/		if (debug_level > 3)		{			if (found ==0 && changes)			{				printf ("XXXXXXXXXXX MPR selector table becomes empty! Send out an empty TC !\n");				fprintf (y_file,"XXXXXXXXXXX MPR selector table becomes empty! Send out an empty TC !\n");			}						if (found ==0 && relay)			{				printf ("XXXXXXXXXXX RELAY out an empty TC !\n");				fprintf (y_file,"XXXXXXXXXXX RELAY out an empty TC !\n");			}		}		outputsize = (char *)mprsaddr - packet;		msg->olsr_packlen = htons(outputsize);		//memset(msg->olsr_res, 0, sizeof(msg->olsr_res));  //commented by Y.Ge		//msg->olsr_seqnum = htons(pkt_seqnum[ifp->my_index]++); 	//added by Y.Ge		m->olsr_msgtype = TC_PACKET;		m->olsr_vtime = message->v_time; //added by Y.Ge		//m->olsr_broad = MSG_BROADCAST;  //commented by Y.Ge		//m->olsr_nextmsg = (char *)mprsaddr - (char *)m;   //commented by Y.Ge		//m->olsr_nextmsg = htons(m->olsr_nextmsg);         //commented by Y.Ge		m->olsr_msgsize = (char *)mprsaddr - (char *)m;   //addeded by Y.Ge		m->olsr_msgsize = htons(m->olsr_msgsize);         //addeded by Y.Ge		m->olsr_ttl = message->time_to_live;  //added by Y.Ge		m->olsr_hopcount = message->hop_count;  //added by Y.Ge				/************ added by Y.Ge *********/		if (relay)			m->olsr_msgseq = htons(message->packet_seq_number);		else		{			m->olsr_msgseq = htons(message->packet_seq_number + tc_chunk[ifp->my_index]);			tc_chunk[ifp->my_index] ++;		}		/************ end of revision ******/					//CRC HNA add		//-----------------------------------------------------------		//memcpy(&(m->olsr_source),&addr_ip,sizeof(struct olsr_ip_addr));		//memcpy(&(m->olsr_source),&(message->source_addr),sizeof(struct olsr_ip_addr)); //commented by Y.Ge		memcpy(&(m->olsr_source),&(message->originator),sizeof(struct olsr_ip_addr)); //added by Y.Ge		//------------------------------------------------------------				/*if (interf)            			tc->tc_seqnum = htons(tc_seqnum++);		else			tc->tc_seqnum = htons(message->packet_seq_number);*/ //commented by Y.Ge		tc->tc_mprseqnum = htons(message->mssn);		/*tc->tc_hopcnt = message->hop_count;*/ //commented by Y.Ge		memset(tc->tc_res, 0, sizeof(tc->tc_res));		//CRC v4->v6 del tc->tc_origaddr = message->originator;		//CRC v4->v6 add		/*memcpy(&(tc->tc_origaddr),&(message->originator),sizeof(struct olsr_ip_addr));*/ //commented by Y.Ge	}		if (debug_level > 3)	{		printf ("++++++++++ TC packet built finished!\n");		//printf (" Message sequence: %d\n", ntohs(msg->olsr_seqnum));		printf (" TC sequence: %d\n", ntohs(m->olsr_msgseq));		printf (" TC mssn: %d\n", message->mssn);		printf (" TC packet size: %d\n", (char *)mprsaddr - (char *)m);						fprintf (y_file,"++++++++++ TC packet built finished!\n");		//fprintf (y_file," Message sequence: %d\n", ntohs(msg->olsr_seqnum));		//fprintf (y_file," TC sequence: %d\n", message->packet_seq_number + tc_chunk[ifp->my_index] -1 );		fprintf (y_file," TC sequence: %d\n", ntohs(m->olsr_msgseq));		fprintf (y_file," TC mssn: %d\n", message->mssn);

⌨️ 快捷键说明

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