Example #1
0
        //
        //when you choose a item in listview2, a messagebox will appear,to show the reassembled packets' content.
        //
        private void listView2_Click(object sender, EventArgs e)
        {
            int          index = Convert.ToInt32(this.listView2.SelectedItems[0].Text);
            simplePacket pac   = (simplePacket)reassemblyPac[index - 1];

            MessageBox.Show("id: " + pac.id + " \n" + "source address: " + pac.src + "\n" + "destination address: " + pac.des + "\n" + "length: " + pac.length + "\n" + "reassembly packet payloaddata: \n" + pac.data);
        }
Example #2
0
 //
 //reassemble
 //show the reassembly packets in the listview2.
 //
 private void button3_Click_1(object sender, EventArgs e)
 {
     this.listView2.Items.Clear();
     if (this.deviceIsOpen)
     {
         MessageBox.Show("Please close the capture first!");
     }
     else
     {
         foreach (packet p in this.packets)
         {
             if (p.epac.Type.ToString() == "IpV4")//get all the ip4 packets
             {
                 simplePacket simpac = new simplePacket(p);
                 if (simpac.df == 0)
                 {
                     simpackets.Add(simpac);
                 }
             }
         }
         foreach (simplePacket sp in this.simpackets)
         {
             if (sp.offset == 0 && sp.mf == 1)
             {   // find the first packet of  the same id packets
                 ArrayList    arr    = new ArrayList();
                 simplePacket lastpa = sp;
                 foreach (simplePacket simp in this.simpackets)
                 {
                     if (simp.id == sp.id && simp.src == sp.src && simp.des == sp.des)
                     {
                         arr.Add(simp); // get all the packets having the same id.
                     }
                     if (simp.id == sp.id && simp.src == sp.src && simp.des == sp.des && simp.mf == 0)
                     {
                         lastpa = simp; //gte the last packet.
                     }
                 }
                 int totallength = 0;
                 foreach (simplePacket s in arr)
                 {
                     totallength += s.length;
                 }
                 int a = lastpa.length + (lastpa.offset * 8);
                 if (totallength == a) // test if there is any packet lost.
                 {
                     while (sp.length != totallength)
                     {
                         foreach (simplePacket pac in arr)
                         {
                             if ((pac.offset * 8) == sp.length)
                             {
                                 sp.length += pac.length;
                                 sp.data   += pac.data;
                             }
                         }
                     }
                     reassemblyPac.Add(sp);
                 }
             }
         }
         //
         //show the information in the treeview.
         //
         int i = 1;
         foreach (simplePacket sp in reassemblyPac)
         {
             ListViewItem item = new ListViewItem(new string[] { i.ToString(), "IpV4", sp.id, sp.src, sp.des });
             listView2.Items.Add(item);
         }
     }
 }