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

📄 build_msg.c

📁 wifi 无线网络路由协议OLSR linux下C代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	  if (found)    {      m->v6.olsr_msgsize = htons(curr_size);      m->v6.seqno = htons(get_msg_seqno());      net_outbuffer_push(ifp, msg_buffer, curr_size);    }  else    {      if((!partial_sent) && (!TIMED_OUT(send_empty_tc)))	{	  OLSR_PRINTF(1, "TC: Sending empty package\n");	    	  m->v6.olsr_msgsize = htons(curr_size);	  m->v6.seqno = htons(get_msg_seqno());	  net_outbuffer_push(ifp, msg_buffer, curr_size);	  found = OLSR_TRUE;	}    }  return found;	}/** *IP version 4 * *<b>NO INTERNAL BUFFER</b> *@param ifp use this interfaces address as main address *@return 1 on success */static olsr_boolserialize_mid4(struct interface *ifp){  olsr_u16_t remainsize, curr_size;  /* preserve existing data in output buffer */  union olsr_message *m;  struct midaddr *addrs;  struct interface *ifs;    if((olsr_cnf->ip_version != AF_INET) || (!ifp) || (ifnet == NULL || ifnet->int_next == NULL))    return OLSR_FALSE;  remainsize = net_outbuffer_bytes_left(ifp);  m = (union olsr_message *)msg_buffer;  curr_size = OLSR_MID_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, "MID");  /* Fill header */  m->v4.hopcnt = 0;  m->v4.ttl = MAX_TTL;  /* Set main(first) address */  COPY_IP(&m->v4.originator, &olsr_cnf->main_addr);  m->v4.olsr_msgtype = MID_MESSAGE;  m->v4.olsr_vtime = ifp->valtimes.mid;   addrs = m->v4.message.mid.mid_addr;  /* Don't add the main address... it's already there */  for(ifs = ifnet; ifs != NULL; ifs = ifs->int_next)    {      if(!COMP_IP(&olsr_cnf->main_addr, &ifs->ip_addr))	{	  if((curr_size + olsr_cnf->ipsize) > remainsize)	    {	      /* Only add MID message if it contains data */	      if(curr_size > OLSR_MID_IPV4_HDRSIZE)		{#ifdef DEBUG		  OLSR_PRINTF(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);#endif		  /* set size */		  m->v4.olsr_msgsize = htons(curr_size);		  m->v4.seqno = htons(get_msg_seqno());/* seqnumber */		  		  net_outbuffer_push(ifp, msg_buffer, curr_size);		  curr_size = OLSR_MID_IPV4_HDRSIZE;		  addrs = m->v4.message.mid.mid_addr;		}	      net_output(ifp);	      remainsize = net_outbuffer_bytes_left(ifp);	      check_buffspace(curr_size, remainsize, "MID2");	    }#ifdef DEBUG	  OLSR_PRINTF(BMSG_DBGLVL, "\t%s(%s)\n", 		      olsr_ip_to_string(&ifs->ip_addr), 		      ifs->int_name);#endif	  	  COPY_IP(&addrs->addr, &ifs->ip_addr);	  addrs++;	  curr_size += olsr_cnf->ipsize;	}    }  m->v4.seqno = htons(get_msg_seqno());/* seqnumber */  m->v4.olsr_msgsize = htons(curr_size);  //printf("Sending MID (%d bytes)...\n", outputsize);  if(curr_size > OLSR_MID_IPV4_HDRSIZE)    net_outbuffer_push(ifp, msg_buffer, curr_size);  return OLSR_TRUE;}/** *IP version 6 * *<b>NO INTERNAL BUFFER</b> *@param ifp use this interfaces address as main address *@return 1 on success */static olsr_boolserialize_mid6(struct interface *ifp){  olsr_u16_t remainsize, curr_size;  /* preserve existing data in output buffer */  union olsr_message *m;  struct midaddr6 *addrs6;  struct interface *ifs;  //printf("\t\tGenerating mid on %s\n", ifn->int_name);  if((olsr_cnf->ip_version != AF_INET6) || (!ifp) || (ifnet == NULL || ifnet->int_next == NULL))    return OLSR_FALSE;  remainsize = net_outbuffer_bytes_left(ifp);  curr_size = OLSR_MID_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 + olsr_cnf->ipsize, remainsize, "MID");  m = (union olsr_message *)msg_buffer;      /* Build header */  m->v6.hopcnt = 0;  m->v6.ttl = MAX_TTL;        m->v6.olsr_msgtype = MID_MESSAGE;  m->v6.olsr_vtime = ifp->valtimes.mid;  /* Set main(first) address */  COPY_IP(&m->v6.originator, &olsr_cnf->main_addr);     addrs6 = m->v6.message.mid.mid_addr;  /* Don't add the main address... it's already there */  for(ifs = ifnet; ifs != NULL; ifs = ifs->int_next)    {      if(!COMP_IP(&olsr_cnf->main_addr, &ifs->ip_addr))	{	  if((curr_size + olsr_cnf->ipsize) > remainsize)	    {	      /* Only add MID message if it contains data */	      if(curr_size > OLSR_MID_IPV6_HDRSIZE)		{#ifdef DEBUG		  OLSR_PRINTF(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);#endif		  /* set size */		  m->v6.olsr_msgsize = htons(curr_size);		  m->v6.seqno = htons(get_msg_seqno());/* seqnumber */		  		  net_outbuffer_push(ifp, msg_buffer, curr_size);		  curr_size = OLSR_MID_IPV6_HDRSIZE;		  addrs6 = m->v6.message.mid.mid_addr;		}	      net_output(ifp);	      remainsize = net_outbuffer_bytes_left(ifp);	      check_buffspace(curr_size + olsr_cnf->ipsize, remainsize, "MID2");	    }#ifdef DEBUG		  OLSR_PRINTF(BMSG_DBGLVL, "\t%s(%s)\n", 			      olsr_ip_to_string(&ifs->ip_addr), 			      ifs->int_name);#endif	  COPY_IP(&addrs6->addr, &ifs->ip_addr);	  addrs6++;	  curr_size += olsr_cnf->ipsize;	}    }  m->v6.olsr_msgsize = htons(curr_size);  m->v6.seqno = htons(get_msg_seqno());/* seqnumber */  //printf("Sending MID (%d bytes)...\n", outputsize);  if(curr_size > OLSR_MID_IPV6_HDRSIZE)    net_outbuffer_push(ifp, msg_buffer, curr_size);  return OLSR_TRUE;}/** *IP version 4 * *@param ifp the interface to send on *@return nada */static olsr_boolserialize_hna4(struct interface *ifp){  olsr_u16_t remainsize, curr_size;  /* preserve existing data in output buffer */  union olsr_message *m;  struct hnapair *pair;  struct hna4_entry *h = olsr_cnf->hna4_entries;  /* No hna nets */  if((olsr_cnf->ip_version != AF_INET) || (!ifp) || h == NULL)    return OLSR_FALSE;      remainsize = net_outbuffer_bytes_left(ifp);    curr_size = OLSR_HNA_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, "HNA");  m = (union olsr_message *)msg_buffer;      /* Fill header */  COPY_IP(&m->v4.originator, &olsr_cnf->main_addr);  m->v4.hopcnt = 0;  m->v4.ttl = MAX_TTL;  m->v4.olsr_msgtype = HNA_MESSAGE;  m->v4.olsr_vtime = ifp->valtimes.hna;    pair = m->v4.message.hna.hna_net;    while(h)    {      if((curr_size + (2 * olsr_cnf->ipsize)) > remainsize)	{	  /* Only add HNA message if it contains data */	  if(curr_size > OLSR_HNA_IPV4_HDRSIZE)	    {#ifdef DEBUG	      OLSR_PRINTF(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);#endif	      m->v4.seqno = htons(get_msg_seqno());	      m->v4.olsr_msgsize = htons(curr_size);	      net_outbuffer_push(ifp, msg_buffer, curr_size);	      curr_size = OLSR_HNA_IPV4_HDRSIZE;	      pair = m->v4.message.hna.hna_net;	    }	  net_output(ifp);	  remainsize = net_outbuffer_bytes_left(ifp);	  check_buffspace(curr_size + (2 * olsr_cnf->ipsize), remainsize, "HNA2");	}#ifdef DEBUG      OLSR_PRINTF(BMSG_DBGLVL, "\tNet: %s/%s\n", 		  olsr_ip_to_string(&h->net),		  olsr_ip_to_string(&h->netmask));#endif      COPY_IP(&pair->addr, &h->net);      COPY_IP(&pair->netmask, &h->netmask);      pair++;      curr_size += (2 * olsr_cnf->ipsize);      h = h->next;    }  m->v4.seqno = htons(get_msg_seqno());  m->v4.olsr_msgsize = htons(curr_size);  net_outbuffer_push(ifp, msg_buffer, curr_size);  //printf("Sending HNA (%d bytes)...\n", outputsize);  return OLSR_FALSE;}/** *IP version 6 * *@param ifp the interface to send on *@return nada */static olsr_boolserialize_hna6(struct interface *ifp){  olsr_u16_t remainsize, curr_size;  /* preserve existing data in output buffer */  union olsr_message *m;  struct hnapair6 *pair6;  union olsr_ip_addr tmp_netmask;  struct hna6_entry *h = olsr_cnf->hna6_entries;    /* No hna nets */  if((olsr_cnf->ip_version != AF_INET6) || (!ifp) || h == NULL)    return OLSR_FALSE;      remainsize = net_outbuffer_bytes_left(ifp);  curr_size = OLSR_HNA_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, "HNA");  m = (union olsr_message *)msg_buffer;     /* Fill header */  COPY_IP(&m->v6.originator, &olsr_cnf->main_addr);  m->v6.hopcnt = 0;  m->v6.ttl = MAX_TTL;  m->v6.olsr_msgtype = HNA_MESSAGE;  m->v6.olsr_vtime = ifp->valtimes.hna;  pair6 = m->v6.message.hna.hna_net;  while(h)    {      if((curr_size + (2 * olsr_cnf->ipsize)) > remainsize)	{	  /* Only add HNA message if it contains data */	  if(curr_size > OLSR_HNA_IPV6_HDRSIZE)	    {#ifdef DEBUG	      OLSR_PRINTF(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);#endif	      m->v6.seqno = htons(get_msg_seqno());	      m->v6.olsr_msgsize = htons(curr_size);	      net_outbuffer_push(ifp, msg_buffer, curr_size);	      curr_size = OLSR_HNA_IPV6_HDRSIZE;	      pair6 = m->v6.message.hna.hna_net;	    }	  net_output(ifp);	  remainsize = net_outbuffer_bytes_left(ifp);	  check_buffspace(curr_size + (2 * olsr_cnf->ipsize), remainsize, "HNA2");	}#ifdef DEBUG      OLSR_PRINTF(BMSG_DBGLVL, "\tNet: %s/%d\n", 		  olsr_ip_to_string(&h->net),		  h->prefix_len);#endif      COPY_IP(&pair6->addr, &h->net);      olsr_prefix_to_netmask(&tmp_netmask, h->prefix_len);      COPY_IP(&pair6->netmask, &tmp_netmask);      pair6++;      curr_size += (2 * olsr_cnf->ipsize);      h = h->next;    }    m->v6.olsr_msgsize = htons(curr_size);  m->v6.seqno = htons(get_msg_seqno());    net_outbuffer_push(ifp, msg_buffer, curr_size);    //printf("Sending HNA (%d bytes)...\n", outputsize);  return OLSR_FALSE;}

⌨️ 快捷键说明

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