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

📄 build_msg.c

📁 wifi 无线网络路由协议OLSR linux下C代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	    {	      hinfo->size = htons((char *)haddr - (char *)hinfo);	      hinfo = (struct hellinfo *)((char *)haddr);	      haddr = (union olsr_ip_addr *)&hinfo->neigh_addr;	    }	} /* for j */    } /* for i*/       m->v4.seqno = htons(get_msg_seqno());  m->v4.olsr_msgsize = htons(curr_size);    net_outbuffer_push(ifp, msg_buffer, curr_size);  /* HELLO will always be generated */  return OLSR_TRUE;}/** * IP version 6 * *@param message the hello_message struct containing the info *to build the hello message from. *@param ifp the interface to send the message on * *@return nada */static olsr_boolserialize_hello6(struct hello_message *message, struct interface *ifp){  olsr_u16_t remainsize, curr_size;  struct hello_neighbor *nb;  union olsr_message *m;  struct hellomsg6 *h6;  struct hellinfo6 *hinfo6;  union olsr_ip_addr *haddr;  int i, j;  olsr_bool first_entry;  if((!message) || (!ifp) || (olsr_cnf->ip_version != AF_INET6))    return OLSR_FALSE;  remainsize = net_outbuffer_bytes_left(ifp);  m = (union olsr_message *)msg_buffer;  curr_size = OLSR_HELLO_IPV6_HDRSIZE; /* OLSR message header */  /* Send pending packet if not room in buffer */  if(curr_size > remainsize)    {      net_output(ifp);      remainsize = net_outbuffer_bytes_left(ifp);    }  check_buffspace(curr_size + olsr_cnf->ipsize + 4, remainsize, "HELLO");  h6 = &m->v6.message.hello;  hinfo6 = h6->hell_info;  haddr = (union olsr_ip_addr *)hinfo6->neigh_addr;  /* Fill message header */  m->v6.ttl = message->ttl;  m->v6.hopcnt = 0;  /* Set source(main) addr */  COPY_IP(&m->v6.originator, &olsr_cnf->main_addr);  m->v6.olsr_msgtype = HELLO_MESSAGE;  m->v6.olsr_vtime = ifp->valtimes.hello;    /* Fill packet header */  h6->willingness = message->willingness;   h6->htime = double_to_me(ifp->hello_etime);  memset(&h6->reserved, 0, sizeof(olsr_u16_t));  /*   *Loops trough all possible neighbor statuses   *The negbor list is grouped by status   */  for (i = 0; i <= MAX_NEIGH; i++)     {      for(j = 0; j <= MAX_LINK; j++)	{	  first_entry = OLSR_TRUE;	  	  	  /*	   *Looping trough neighbors	   */	  for (nb = message->neighbors; nb != NULL; nb = nb->next) 	    {	      	      if ((nb->status != i) || (nb->link != j))		continue;#ifdef DEBUG	      OLSR_PRINTF(BMSG_DBGLVL, "\t%s - ", olsr_ip_to_string(&nb->address));	      OLSR_PRINTF(BMSG_DBGLVL, "L:%d N:%d\n", j, i);#endif		  	      /*	       * If there is not enough room left 	       * for the data in the outputbuffer	       * we must send a partial HELLO and	       * continue building the rest of the	       * data in a new HELLO message	       *	       * If this is the first neighbor in 	       * a group, we must check for an extra	       * 4 bytes	       */	      if((curr_size + olsr_cnf->ipsize + (first_entry ? 4 : 0)) > remainsize)		{		  /* Only send partial HELLO if it contains data */		  if(curr_size > OLSR_HELLO_IPV6_HDRSIZE)		    {#ifdef DEBUG		      OLSR_PRINTF(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);#endif		      /* Complete the headers */		      m->v6.seqno = htons(get_msg_seqno());		      m->v6.olsr_msgsize = htons(curr_size);			  		      hinfo6->size = (char *)haddr - (char *)hinfo6;		      hinfo6->size = htons(hinfo6->size);			  		      /* Send partial packet */		      net_outbuffer_push(ifp, msg_buffer, curr_size);		      curr_size = OLSR_HELLO_IPV6_HDRSIZE;			  		      h6 = &m->v6.message.hello;		      hinfo6 = h6->hell_info;		      haddr = (union olsr_ip_addr *)hinfo6->neigh_addr;		      /* Make sure typeheader is added */		      first_entry = OLSR_TRUE;		    }		  net_output(ifp);		  /* Reset size and pointers */		  remainsize = net_outbuffer_bytes_left(ifp);		  check_buffspace(curr_size + olsr_cnf->ipsize + 4, remainsize, "HELLO2");		      		}	      if(first_entry)		{		  memset(&hinfo6->reserved, 0, sizeof(olsr_u8_t));		  /* Set link and status for this group of neighbors (this is the first) */		  hinfo6->link_code = CREATE_LINK_CODE(i, j);		  curr_size += 4; /* HELLO type section header */		}		  	      COPY_IP(haddr, &nb->address);		  	      /* Point to next address */	      haddr++;	      curr_size += olsr_cnf->ipsize; /* IP address added */ 		  	      first_entry = OLSR_FALSE;	    }/* looping trough neighbors */	  	  	  if (!first_entry)	    {	      hinfo6->size = htons((char *)haddr - (char *)hinfo6);	      hinfo6 = (struct hellinfo6 *)((char *)haddr);	      haddr = (union olsr_ip_addr *)&hinfo6->neigh_addr;	    }	  	} /* for j */    } /* for i */  m->v6.seqno = htons(get_msg_seqno());  m->v6.olsr_msgsize = htons(curr_size);  net_outbuffer_push(ifp, msg_buffer, curr_size);  /* HELLO is always buildt */  return OLSR_TRUE;}/** *IP version 4 * *@param message the tc_message struct containing the info *to send *@param ifp the interface to send the message on * *@return nada */static olsr_boolserialize_tc4(struct tc_message *message, struct interface *ifp)           {  olsr_u16_t remainsize, curr_size;  struct tc_mpr_addr *mprs;  union olsr_message *m;  struct olsr_tcmsg *tc;  struct neigh_info *mprsaddr;   olsr_bool found = OLSR_FALSE, partial_sent = OLSR_FALSE;  if((!message) || (!ifp) || (olsr_cnf->ip_version != AF_INET))    return OLSR_FALSE;  remainsize = net_outbuffer_bytes_left(ifp);  m = (union olsr_message *)msg_buffer;  tc = &m->v4.message.tc;  mprsaddr = tc->neigh;  curr_size = OLSR_TC_IPV4_HDRSIZE;  /* Send pending packet if not room in buffer */  if(curr_size > remainsize)    {      net_output(ifp);      remainsize = net_outbuffer_bytes_left(ifp);    }  check_buffspace(curr_size, remainsize, "TC");  /* Fill header */  m->v4.olsr_vtime = ifp->valtimes.tc;  m->v4.olsr_msgtype = TC_MESSAGE;  m->v4.hopcnt = message->hop_count;  m->v4.ttl = message->ttl;  COPY_IP(&m->v4.originator, &message->originator);  /* Fill TC header */  tc->ansn = htons(message->ansn);  tc->reserved = 0;    /*Looping trough MPR selectors */  for (mprs = message->multipoint_relay_selector_address; mprs != NULL;mprs = mprs->next)     {      /*If packet is to be chomped */      if((curr_size + olsr_cnf->ipsize) > remainsize)	{	  /* Only add TC message if it contains data */	  if(curr_size > OLSR_TC_IPV4_HDRSIZE)	    {#ifdef DEBUG	      OLSR_PRINTF(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);#endif	      m->v4.olsr_msgsize = htons(curr_size);	      m->v4.seqno = htons(get_msg_seqno());	      net_outbuffer_push(ifp, msg_buffer, curr_size);	      	      /* Reset stuff */	      mprsaddr = tc->neigh;	      curr_size = OLSR_TC_IPV4_HDRSIZE;	      found = OLSR_FALSE;	      partial_sent = OLSR_TRUE;	    }	  net_output(ifp);	  remainsize = net_outbuffer_bytes_left(ifp);	  check_buffspace(curr_size + olsr_cnf->ipsize, remainsize, "TC2");	}      found = OLSR_TRUE;#ifdef DEBUG	  OLSR_PRINTF(BMSG_DBGLVL, "\t%s\n", 		      olsr_ip_to_string(&mprs->address));#endif       COPY_IP(&mprsaddr->addr, &mprs->address);      curr_size += olsr_cnf->ipsize;      mprsaddr++;    }  if (found)    {	          m->v4.olsr_msgsize = htons(curr_size);      m->v4.seqno = htons(get_msg_seqno());            net_outbuffer_push(ifp, msg_buffer, curr_size);    }  else    {      if((!partial_sent) && (!TIMED_OUT(send_empty_tc)))	{	  if(!TIMED_OUT(send_empty_tc))	    OLSR_PRINTF(1, "TC: Sending empty package - (%d/%d/%d/%d)\n", partial_sent, (int)send_empty_tc, (int)now_times, (int)((send_empty_tc) - now_times));	  m->v4.olsr_msgsize = htons(curr_size);	  m->v4.seqno = htons(get_msg_seqno());	  net_outbuffer_push(ifp, msg_buffer, curr_size);	  found = OLSR_TRUE;	}    }  return found;	}/** *IP version 6 * *@param message the tc_message struct containing the info *to send *@param ifp the interface to send the message on * *@return nada */static olsr_boolserialize_tc6(struct tc_message *message, struct interface *ifp)           {  olsr_u16_t remainsize, curr_size;  struct tc_mpr_addr *mprs;  union olsr_message *m;  struct olsr_tcmsg6 *tc6;  struct neigh_info6 *mprsaddr6;   olsr_bool found = OLSR_FALSE, partial_sent = OLSR_FALSE;  if ((!message) || (!ifp) || (olsr_cnf->ip_version != AF_INET6))    return OLSR_FALSE;  remainsize = net_outbuffer_bytes_left(ifp);  m = (union olsr_message *)msg_buffer;  tc6 = &m->v6.message.tc;  mprsaddr6 = tc6->neigh;  curr_size = OLSR_TC_IPV6_HDRSIZE;  /* Send pending packet if not room in buffer */  if(curr_size > remainsize)    {      net_output(ifp);      remainsize = net_outbuffer_bytes_left(ifp);    }  check_buffspace(curr_size, remainsize, "TC");  /* Fill header */  m->v6.olsr_vtime = ifp->valtimes.tc;  m->v6.olsr_msgtype = TC_MESSAGE;  m->v6.hopcnt = message->hop_count;  m->v6.ttl = message->ttl;  COPY_IP(&m->v6.originator, &message->originator);  /* Fill TC header */  tc6->ansn = htons(message->ansn);  tc6->reserved = 0;    /*Looping trough MPR selectors */  for (mprs = message->multipoint_relay_selector_address; mprs != NULL;mprs = mprs->next)     {	          /*If packet is to be chomped */      if((curr_size + olsr_cnf->ipsize) > remainsize)	{	  /* Only add TC message if it contains data */	  if(curr_size > OLSR_TC_IPV6_HDRSIZE)	    {#ifdef DEBUG	      OLSR_PRINTF(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);#endif	      m->v6.olsr_msgsize = htons(curr_size);	      m->v6.seqno = htons(get_msg_seqno());	      net_outbuffer_push(ifp, msg_buffer, curr_size);	      mprsaddr6 = tc6->neigh;	      curr_size = OLSR_TC_IPV6_HDRSIZE;	      found = OLSR_FALSE;	      partial_sent = OLSR_TRUE;	    }	  net_output(ifp);	  remainsize = net_outbuffer_bytes_left(ifp);	  check_buffspace(curr_size + olsr_cnf->ipsize, remainsize, "TC2");	}      found = OLSR_TRUE;#ifdef DEBUG	  OLSR_PRINTF(BMSG_DBGLVL, "\t%s\n", 		      olsr_ip_to_string(&mprs->address));#endif      COPY_IP(&mprsaddr6->addr, &mprs->address);      curr_size += olsr_cnf->ipsize;      mprsaddr6++;    }

⌨️ 快捷键说明

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