Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linkLayers is not yet implemented #525

Open
qq1176914912 opened this issue Aug 21, 2024 · 3 comments
Open

linkLayers is not yet implemented #525

qq1176914912 opened this issue Aug 21, 2024 · 3 comments

Comments

@qq1176914912
Copy link

ssh12346.zip
Excuse me.When I tried to get the pcap file in the following way, an error was reported at ‘device.Capture()’: linkLayers is not yet implemented.How do we solve this?

    ICaptureDevice device = new CaptureFileReaderDevice(filepath); 
      device.OnPacketArrival += new PacketArrivalEventHandler(ProcessPcapPacket);  
    device.Open();  
    device.Capture();

     private void ProcessPcapPacket(object sender, PacketCapture e)
        {
            var packet = PacketDotNet.Packet.ParsePacket(e.GetPacket().LinkLayerType, e.GetPacket().Data);
            ProcessPacket(packet);
        }

        void ProcessPacket(PacketDotNet.Packet packet)
        {
            try
            {
       var tcpPacket = packet.Extract<PacketDotNet.TcpPacket>();
       var udpPacket = packet.Extract<PacketDotNet.UdpPacket>();

       if (udpPacket != null)
       {
           var ipPacket = (PacketDotNet.IPPacket)udpPacket.ParentPacket;

           UdpPacketArived?.Invoke(this, new UdpPacketArivedEventArgs
           {
               Packet = new UdpPacket
               {
                   SourcePort = udpPacket.SourcePort,
                   DestinationPort = udpPacket.DestinationPort,
                   SourceIp = ipPacket.SourceAddress.ToString(),
                   DestinationIp = ipPacket.DestinationAddress.ToString(),
                   Data = udpPacket.PayloadData ?? new byte[] { }
               }
           });

           if (this.BuildUdpSessions)
           {
               this._udpStreamBuilder.HandlePacket(udpPacket);
           }

           _processingPrecentsPredicator.NotifyAboutProcessedData(packet.Bytes.Length);
       }
       else if (tcpPacket != null)
       {
           var ipPacket = (PacketDotNet.IPPacket)tcpPacket.ParentPacket;

           // Raise event Tcp packet arived event.
           TcpPacketArived?.Invoke(this, new TcpPacketArivedEventArgs
           {
               Packet = new TcpPacket
               {
                   SourcePort = tcpPacket.SourcePort,
                   DestinationPort = tcpPacket.DestinationPort,
                   SourceIp = ipPacket.SourceAddress.ToString(),
                   DestinationIp = ipPacket.DestinationAddress.ToString(),
                   Data = tcpPacket.PayloadData ?? new byte[] { }
               }
           });

           if (this.BuildTcpSessions)
           {
               this._tcpSessionsBuilder.HandlePacket(tcpPacket);
           }

           _processingPrecentsPredicator.NotifyAboutProcessedData(packet.Bytes.Length);
       }
   }
   catch (Exception ex)
   {
       // TODO: handle or throw this
       //Console.WriteLine(ex);
   }
 }
@qq1176914912
Copy link
Author

ssh12346.zip Excuse me.When I tried to get the pcap file in the following way, an error was reported at ‘device.Capture()’: linkLayers is not yet implemented.How do we solve this?

    ICaptureDevice device = new CaptureFileReaderDevice(filepath); 
      device.OnPacketArrival += new PacketArrivalEventHandler(ProcessPcapPacket);  
    device.Open();  
    device.Capture();

     private void ProcessPcapPacket(object sender, PacketCapture e)
        {
            var packet = PacketDotNet.Packet.ParsePacket(e.GetPacket().LinkLayerType, e.GetPacket().Data);
            ProcessPacket(packet);
        }

        void ProcessPacket(PacketDotNet.Packet packet)
        {
            try
            {
       var tcpPacket = packet.Extract<PacketDotNet.TcpPacket>();
       var udpPacket = packet.Extract<PacketDotNet.UdpPacket>();

       if (udpPacket != null)
       {
           var ipPacket = (PacketDotNet.IPPacket)udpPacket.ParentPacket;

           UdpPacketArived?.Invoke(this, new UdpPacketArivedEventArgs
           {
               Packet = new UdpPacket
               {
                   SourcePort = udpPacket.SourcePort,
                   DestinationPort = udpPacket.DestinationPort,
                   SourceIp = ipPacket.SourceAddress.ToString(),
                   DestinationIp = ipPacket.DestinationAddress.ToString(),
                   Data = udpPacket.PayloadData ?? new byte[] { }
               }
           });

           if (this.BuildUdpSessions)
           {
               this._udpStreamBuilder.HandlePacket(udpPacket);
           }

           _processingPrecentsPredicator.NotifyAboutProcessedData(packet.Bytes.Length);
       }
       else if (tcpPacket != null)
       {
           var ipPacket = (PacketDotNet.IPPacket)tcpPacket.ParentPacket;

           // Raise event Tcp packet arived event.
           TcpPacketArived?.Invoke(this, new TcpPacketArivedEventArgs
           {
               Packet = new TcpPacket
               {
                   SourcePort = tcpPacket.SourcePort,
                   DestinationPort = tcpPacket.DestinationPort,
                   SourceIp = ipPacket.SourceAddress.ToString(),
                   DestinationIp = ipPacket.DestinationAddress.ToString(),
                   Data = tcpPacket.PayloadData ?? new byte[] { }
               }
           });

           if (this.BuildTcpSessions)
           {
               this._tcpSessionsBuilder.HandlePacket(tcpPacket);
           }

           _processingPrecentsPredicator.NotifyAboutProcessedData(packet.Bytes.Length);
       }
   }
   catch (Exception ex)
   {
       // TODO: handle or throw this
       //Console.WriteLine(ex);
   }
 }

The specific problem is with 'e.G Packet().LinkLayerType', which gets type 276

@kayoub5
Copy link
Collaborator

kayoub5 commented Aug 25, 2024

@PhyxionNL Is LINKTYPE_LINUX_SLL2 supported in the packet decoding?

@PhyxionNL
Copy link

Not yet, there's a PR that's missing tests. I'll get some feedback going there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants