📄 output.c
字号:
fprintf (y_file," TC packet size: %d\n", (char *)mprsaddr - (char *)m); } if (outputsize > MAXPACKETSIZE - (int)sizeof (struct olsrmsg)) { //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 } /* * commented by Y.Ge. * This is now done in timer(), as node with multiple interface should build same TC andd MID. * it is not necessary to call this function in all interfaces */ /* * Delete the list of mprs messages */ /*mprs = message->multipoint_relay_selector_address; while (mprs) { prev_mprs = mprs; mprs = mprs->next; free(prev_mprs); }*/ }//CRC HNA add/*---------------------------------------------------------------------------*//* * Generate HNA packet with the contents of the parameter "message". * Send the packet if the size of the data contained in the output buffer * reach MAXPACKETSIZE. Don't generate an empty HNA packet. * The parameter messag, messg is not used. */ void hna_build(struct sockaddr *dst, struct hello_message *messag,struct tc_message *messg, struct mid_message *mmessage, struct hna_message *message, int flags, struct interface *ifp, int relay) { /*int remainsize = outputsize - (sizeof(msg->olsr_packlen) + sizeof(msg->olsr_res));*/ //commented by Y.Ge int remainsize = outputsize - comm_head_size; struct hna_net_addr *nodeptr; struct olsrmsg *m = outputsize ? (struct olsrmsg *)((char *)msg->olsr_msg + remainsize): msg->olsr_msg; struct hnamsg *hna = m->olsr_hna; struct hnaaddr *hnaaddrs = hna->hna_netaddr; struct interface *interf; struct sockaddr address; int found = 0; int more = 0; 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 //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; if (!message->hna_net_addrs) return; if (debug_level > 3) { printf ("\n\n-------------- in hna build -----------------\n"); fprintf (y_file,"\n\n-------------- in hna build -----------------\n"); printf ("--- HNA sequence number: %d\n",message->packet_seq_number); fprintf (y_file,"--- HNA sequence number: %d\n",message->packet_seq_number); 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])); } 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); for (nodeptr = message->hna_net_addrs; nodeptr!= NULL; nodeptr = nodeptr->next) { /* if (more ==1 && wrap_around_compare(message->packet_seq_number,3)) continue; more =1; */ outputsize = (char *)hnaaddrs - packet; //printf (" outputsize: %d\n", outputsize); //the following IF is revised by Y.Ge,original one: "if (outputsize > MAXPACKETSIZE - (int)sizeof (hnaaddrs))" if (outputsize > MAXPACKETSIZE - (int)sizeof (struct hnaaddr)) { 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 = HNA_PACKET; m->olsr_vtime = message->v_time; //added by Y.Ge //m->olsr_broad = MSG_BROADCAST; //commented by Y.Ge //m->olsr_nextmsg = (char *)hnaaddrs - (char *)m; //commented by Y.Ge //m->olsr_nextmsg = htons(m->olsr_nextmsg); //commented by Y.Ge m->olsr_msgsize = (char *)hnaaddrs - (char *)m; //commented by Y.Ge m->olsr_msgsize = htons(m->olsr_msgsize); //commented 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 sequence number of the chunked packet */ if (relay) { printf (" XXXXXXXX something wrong! relayed HNA should not be chunked XXXXXX\n"); exit (1); } m->olsr_msgseq = htons(message->packet_seq_number + hna_chunk[ifp->my_index]); hna_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) hna->hna_seqnum = htons(hna_seqnum++); else hna->hna_seqnum = htons(message->packet_seq_number);*/ //commented by Y.Ge /*hna->hna_msgseqnum = htons(message->msg_seq_number); hna->hna_hopcnt = message->hop_count; memset(hna->hna_res, 0, sizeof(hna->hna_res)); memcpy(&(hna->hna_origaddr),&(message->originator),sizeof(struct olsr_ip_addr));*/ //commented by Y.Ge if (debug_level > 3) { printf ("++++++++++ HNA packet chunked!\n"); //printf (" Message sequence: %d\n", ntohs(msg->olsr_seqnum)); printf (" HNA sequence: %d\n", ntohs(m->olsr_msgseq)); printf (" HNA packet size: %d\n", (char *)hnaaddrs - (char *)m); fprintf (y_file,"++++++++++ HNA packet chunked!\n"); //fprintf (y_file," Message sequence: %d\n",ntohs(msg->olsr_seqnum)); fprintf (y_file," HNA sequence: %d\n", ntohs(m->olsr_msgseq)); fprintf (y_file," HNA packet size: %d\n", (char *)hnaaddrs - (char *)m); } //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; hna = m->olsr_hna; hnaaddrs = hna->hna_netaddr; found = 0; } found = 1; memcpy(&(hnaaddrs->addr),&(nodeptr->net_addr),sizeof(struct olsr_ip_addr)); hnaaddrs->prefix=htons(nodeptr->prefix); memset(hnaaddrs->res,0,sizeof(hnaaddrs->res)); if (debug_level >3) { printf ("--- hna address: %s, prefix:%d\n", convert_address_to_string(&hnaaddrs->addr), hnaaddrs->prefix); fprintf (y_file,"--- hna address: %s, prefix:%d\n", convert_address_to_string(&hnaaddrs->addr), hnaaddrs->prefix); } hnaaddrs++; } if (found) { outputsize = (char *)hnaaddrs - 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 = HNA_PACKET; m->olsr_vtime = message->v_time; //added by Y.Ge //m->olsr_broad = MSG_BROADCAST; //commented by Y.Ge //m->olsr_nextmsg = (char *)hnaaddrs - (char *)m; //commented by Y.Ge //m->olsr_nextmsg = htons(m->olsr_nextmsg); //commented by Y.Ge m->olsr_msgsize = (char *)hnaaddrs - (char *)m; //added 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 + hna_chunk[ifp->my_index]); hna_chunk[ifp->my_index] ++; } /************* end of revision *******/ /*printf ("now, the hna sequence is:%d\n", hna_chunk[ifp->my_index]);*/ //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) hna->hna_seqnum = htons(hna_seqnum++); else hna->hna_seqnum = htons(message->packet_seq_number);*/ //commented by Y.Ge /*hna->hna_msgseqnum = htons(message->msg_seq_number); hna->hna_hopcnt = message->hop_count; memset(hna->hna_res, 0, sizeof(hna->hna_res)); //CRC v4->v6 del tc->tc_origaddr = message->originator; //CRC v4->v6 add memcpy(&(hna->hna_origaddr),&(message->originator),sizeof(struct olsr_ip_addr));*/ //commented by Y.Ge } if (debug_level > 3) { printf ("++++++++++ HNA packet built finished!\n"); //printf (" Message sequence: %d\n", ntohs(msg->olsr_seqnum)); printf (" HNA sequence: %d\n", ntohs(m->olsr_msgseq)); printf (" HNA packet size: %d\n", (char *)hnaaddrs - (char *)m); fprintf (y_file,"++++++++++ HNA packet built finished!\n"); //fprintf (y_file," Message sequence: %d\n", ntohs(msg->olsr_seqnum)); fprintf (y_file," HNA sequence: %d\n", ntohs(m->olsr_msgseq)); fprintf (y_file," HNA packet size: %d\n", (char *)hnaaddrs - (char *)m); } if (outputsize > MAXPACKETSIZE - (int)sizeof (struct olsrmsg)) { //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 }}/*---------------------------------------------------------------------------*//****************************** added by Y.Ge ***********************//* * Generate MID packet with the contents of the parameter "message". * Send the packet if the size of the data contained in the output buffer * reach MAXPACKETSIZE. Don't generate an empty MID packet. * The parameter messag, messg, mess is not used. */ void mid_build(struct sockaddr *dst, struct hello_message *messg,struct tc_message *messag, struct mid_message *message, struct hna_message *mess,int flags, struct interface *ifp, int relay) { int remainsize = outputsize - comm_head_size; struct mid_iface_addr *addressptr; struct olsrmsg *m = outputsize ? (struct olsrmsg *)((char *)msg->olsr_msg + remainsize): msg->olsr_msg; struct midmsg *mid = m->olsr_mid; struct olsr_ip_addr *ifaceaddrs = mid->mid_ifaceaddr; struct interface *interf; struct sockaddr address; int found = 0; if (debug_level > 3) { printf ("\n\n-------------- in mid build -----------------\n"); fprintf (y_file,"\n\n-------------- in mid build -----------------\n"); printf ("originator address: %s\n", convert_address_to_string(&message->originator_addr)); fprintf (y_file, "originator address: %s\n", convert_address_to_string(&message->originator_addr)); 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); //msg->olsr_seqnum = htons(pkt_seqnum[ifp->my_index]++); tointerface (sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL, ifp->my_index); } if (!message) { printf ("message = NULL!\n"); return; } if (!message->mid_interface_address) { printf (" message->mid_interface_address = NULL!\n"); return; } memset(&address, 0, sizeof(address)); memcpy(&(((struct sockaddr_in6 *)&address)->sin6_addr.s6_addr),&addr_manet[ifp->my_index],sizeof(struct in6_addr)); address.sa_family = AF_INET6; interf = if_ifwithaddr6(&address); if (debug_level > 3) { printf ("include the interface addresses!\n"); fprintf (y_file,"include the interface addresses!\n"); } for (addressptr = message->mid_interface_address; addressptr!= NULL; addressptr = addressptr->next) { if (debug_level > 3) { printf (" ++ interface address: %s\n", convert_address_to_string (&addressptr->interface_address)); fprintf (y_file," ++ interface address: %s\n", convert_address_to_string (&addressptr->interface_address)); } outputsize = (char *)ifaceaddrs - packet; if (outputsize >
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -