[VB.NET] Taille du buffet (Size Buffet)

Apr 28, 2013 at 12:44 PM
Edited Apr 28, 2013 at 12:46 PM
Hello everyone,

First of all I apologize for my spelling mistakes, because I'm French.
I code in VB.NET a packet sniffer and I would increase the size of the buffet because I Pcap large packets that are cropped.

Here is my code:
See below

How can I do?
Thank you in advance

Bonjour à tous,

Tous d'abord veuillez m'excuser pour mes fautes d'orthographe, car je suis français.
Je code en VB.NET un sniffeur de packet et je voudrais augmenter la taille du buffet Pcap car j'ai des gros packets qui sont rogné.

Voilà mon code:
Imports PcapDotNet.Core
Imports PcapDotNet.Packets
Imports PcapDotNet.Packets.IpV4
Imports PcapDotNet.Packets.Transport
Imports System.Threading

Public Class Main
    Private SelectedDevice As Integer = 0
    Private isStopCapture As Boolean = False
    Private ThreadStart = New Thread(AddressOf CaptureThread)
    Private allDevices As IList(Of LivePacketDevice) = LivePacketDevice.AllLocalMachine
    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Utils.Index = Me
        If allDevices.Count = 0 Then
            MessageBox.Show("No Adapters")
        End If
        For Each Device As Global.PcapDotNet.Core.LivePacketDevice In allDevices
        cb_Adapters.SelectedIndex = 4
    End Sub
    Private Sub cb_Adapters_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb_Adapters.SelectedIndexChanged
        SelectedDevice = cb_Adapters.SelectedIndex()
        If bt_start.Enabled = False Then
            bt_start.Enabled = True
        End If
    End Sub
    Private Sub bt_start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_start.Click
        If bt_start.Text = "Start" Then
            lb_packetCount.Text = 0
            isStopCapture = False

            ThreadStart = New Thread(AddressOf CaptureThread)
            ThreadStart.IsBackground = True
            bt_start.Text = "Stop"
            isStopCapture = True
            bt_start.Text = "Start"
        End If
    End Sub
    Public Sub CaptureThread()
        Using communicator = allDevices(SelectedDevice).Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1)
            communicator.Mode = PacketCommunicatorMode.Capture
            communicator.ReceivePackets(0, AddressOf PacketHandler)
        End Using
    End Sub
    Private Delegate Sub PacketReceiveDelegate(ByVal packet As Packet)
    Public Sub PacketHandler(ByVal packet As Packet)
        If isStopCapture Then ThreadStart.Abort()
        Me.Invoke(New PacketReceiveDelegate(AddressOf ReceivePackets), packet)
    End Sub
    Public Sub ReceivePackets(ByVal packet As Packet)
            If packet.Count = 0 Then Exit Sub
            Dim Data_ As New List(Of Byte)
            For j As Integer = 0 To packet.Buffer.Length - 55
                Data_.Add(packet.Buffer(j + 54))
            If Data_.Count = 0 Then Exit Sub
        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Critical)
        End Try
    End Sub
Comment puis-je faire ?

Merci par avance
May 3, 2013 at 7:20 AM
Hello Jules42,

Are the packets that get cropped are longer than 64K?
Can you give a .pcap file example for the packets that go in and a .pcap file example for the cropped packets you capture?

May 3, 2013 at 11:44 AM
Brickner Hello and thank you for your reply.

My problem is solved.
I coded a parser allow packets received my algorithm.
At the beginning of my packets I get the size of the packet and I store my bits of packet in a buffet. When my entire packet is I generate a OnPacketReceived event.
All works correctly.

good day