This project is read-only.

ReceivePacket doesn't seem to work

Feb 4, 2015 at 9:48 AM
I try to make some "special" protocol using PCAP.NET.
I have a hardware board , there is an FPGA and it is programmed for only raw ethernet packets. no other protocol will be used because of space limit on FPGA. Anyway I want to send and receive raw ethernet packets. I can send packets and FPGA sends answer immidiately, I can see it on WireShark. However I can not see it on my program. FPGA sends a special packet every 20 second, I can see it in my program. If I send a packet I dont see the answer from FPGA even though I see it in Wireshark.
How can I solve this?
Second question:
Can I open a device for sending and receiving? Or Do I need two instances?
Do I need a "close" function after I send the packet?
I am calling the receivePacket method in a different Thread in a loop.
My code:
        public void Config(int timeOut)
            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, //.None, //.Promiscuous, 
                                       timeOut); // read timeout

        public int SendPacket(string sourceMAC, string destMAC, string textToSend)

            Packet packetToSend;

                if (!destMAC.Contains(":"))
                    return -1; 

                packetToSend = BuildEthernetPacket(sourceMAC, destMAC, textToSend);
                return 0; 

 public string[] receivePacket(out int errStatus, string filterStr)
            Packet packetReceived = null;
            string[] returnVal = new string[5];
            errStatus = 0;
            PacketCommunicatorReceiveResult result;

                if (communicator.DataLink.Kind != DataLinkKind.Ethernet)
                   errStatus = -1;
                   returnVal = new string[5] { "it is not ethernet", "", "", "", "" };

                result = communicator.ReceivePacket(out packetReceived);

                switch (result)
                    case PacketCommunicatorReceiveResult.BreakLoop:
                        returnVal = new string[5] { "BreakLoop", "", "", "", "" };
                        errStatus = -4;
                    case PacketCommunicatorReceiveResult.Eof:
                        returnVal = new string[5] { "Eof", "", "", "", "" };
                        errStatus = -5;
                    case PacketCommunicatorReceiveResult.None:
                        returnVal = new string[5] { "None", "", "", "", "" };
                        errStatus = -6;
                    case PacketCommunicatorReceiveResult.Ok:
                            returnVal[0] = packetReceived.Timestamp.ToString("hh:mm:ss.fff");
                            returnVal[1] = packetReceived.Ethernet.Source.ToString();
                            returnVal[2] = packetReceived.Ethernet.Destination.ToString();
                            returnVal[3] = packetReceived.Ethernet.Payload.ToHexadecimalString();
                            returnVal[4] = packetReceived.Ethernet.Payload.Length.ToString();
                            errStatus = 0;
                    case PacketCommunicatorReceiveResult.Timeout:
                        errStatus = -2;
                        errStatus = -3;
                        returnVal = new string[5] { "The result " + result + " should never be reached here", "", "", "", "" };
            return returnVal;                    

Feb 4, 2015 at 10:19 AM
I think I found something. I was also using berkeley filtering, I didn't mention it, sorry. With filtering it does not receive the answer from FPGA. Without filtering it receives the packet. I dont know why. Filtering string is "ether host 00:11:22:33:44:55", also MAC address of FPGA board. As I said before, FPGA sends a packet every 20 second and I receive it even with filtering. Only what i don't receive is the immidiate answer after I send a packet.
What is the problem?
Feb 4, 2015 at 10:20 AM
Hi kahlenberg
If you want to capture packet from your FPGA, follow the sample "opning an adapter and capture the packet". it's a good way to get packet even ethernet packet.
Feb 4, 2015 at 11:57 AM
Thanks for answer, I already followed that example, my problem is now filtering the traffic. If I use the filtering I don't get response from FPGA, if I don't use filtering I get the response. I am filtering the traffic in application level, also I am getting every packet and than compare the soruce and destination MAC addresses, if one of them is MAC address of FPGA then I am using the packet.
Feb 4, 2015 at 2:01 PM
you said that the FPGA device is only programmed for ethernet raw. That means this device cannot capture other kind of packet but ethernet. any other protocol above will be ignored.
But you can to try to compare the payload of packet as ethernet payload.
I think this can help you
Feb 6, 2015 at 10:25 AM
Hi Barack1234,

Did you try capturing these packets using Wireshark with "Capture Filter" "ether host 00:11:22:33:44:55"?

Feb 27, 2015 at 1:20 PM
My apologies, my question was for kahlenberg.
Feb 27, 2015 at 1:22 PM
You can use the same PacketCommunicator for both sending and receiving.
If the problem is with the filter, I suggest to try and change it so it works in Wireshark and then use the same in Pcap.Net.