This project is read-only.

Show packet on Listview

Mar 6, 2011 at 4:22 AM

Attempt to me has to display on package listview, but not, this is the code of me, help me of you

       private delegate void UpdatePacketList(Packet p);

       public void OnHostsClick(object sender, EventArgs e)
            Class_Capture_packet capture = new Class_Capture_packet();
            gb_selinterface.Visible = false;
            int deviceIndex = ((Button)sender).TabIndex;
            PacketDevice selectedDevice = allDevices[deviceIndex];
            listView_detaill.Visible = true;
            Status.Text = "Listening on " + selectedDevice.Description + "...";
            using (PacketCommunicator communicator =
            selectedDevice.Open(65536,                                  // portion of the packet to capture
                // 65536 guarantees that the whole packet will be captured on all the link layers
                                PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                1000))                                  // read timeout
                Packet packet;
                    PacketCommunicatorReceiveResult result = communicator.ReceivePacket(out packet);
                    switch (result)
                        case PacketCommunicatorReceiveResult.Timeout:
                            // Timeout elapsed
                        case PacketCommunicatorReceiveResult.Ok:
                                this.Invoke(new UpdatePacketList(OnUpdatePacketList), packet);
                            throw new InvalidOperationException("The result " + result + " shoudl never be reached here");
                } while (true);
        private void OnUpdatePacketList(Packet p)
            listView_detaill.Items.Add(new ListViewItem(new string[] {p.Timestamp.ToString("yyyy-MM-dd hh:mm:ss.fff") }));

Mar 11, 2011 at 12:05 PM

Hi haonhien,


What problem exactly do you have?

If you need help with ListView specifically, I'm sure there a lot of sources and examples with that.

If you have trouble getting to the packets' values, I suggest trying to use a simple Unit Test or a Console Application to print what you need and debug it there.



Mar 11, 2011 at 5:22 PM
Edited Mar 11, 2011 at 5:22 PM

Being Coordinator is a tough job to answer every queries. Brickner is right that there are a lot of solutions available. For future please refer, (i remember these 2 now). These are quite good site and their traffic rankings at are very high.


But i will try to write code with reference to your snippet. I assume that you have created the columns of ListView from the VS GUI designer. Dont forget to select the "detailed view" of ListView u have created.



private void OnUpdatePacketList(Packet p)
            //parse your packet here 

            ListViewItem item = new ListViewItem("NewRow & Column1"); // u have to create every row with ListViewItem
            item.SubItems.Add("currentRow Column 2 data");
            item.SubItems.Add("currentRow Column 3 data"); //etc



I hope this helps