Wireshark datagrams not received by Qt UDP Socket

I am writing a Qt application (5.6) that communicates with FPGA via a UDP socket. Packets are transmitted to a PC with a frequency of 2 kHz (all packets are the same size, 1272 bytes). Wireshark shows that packets are being sent, and the UDP header is as expected. The problem is that the Qt UDP Socket that I use never receives these packets. ReadyRead is never called.

Here is the code snippet:

UdpConnection::UdpConnection(QObject* parent) { fpgaConnection = QSharedPointer<QUdpSocket>(new QUdpSocket); qDebug() << connect(fpgaConnection.data(), &QUdpSocket::readyRead, this, &UdpConnection::readyRead); if (fpgaConnection->bind(QHostAddress("192.168.10.10"), 1920)) { qDebug() << "Successfully Bound!"; } else { qDebug() << "BINDING FAILURE"; } fpgaConnection->connectToHost(QHostAddress("192.168.10.200"), 1919); sendArpRequest(); } void UdpConnection::readyRead() { while (fpgaConnection->hasPendingDatagrams()) { QByteArray buffer; buffer.resize(fpgaConnection->pendingDatagramSize()); QHostAddress sender; quint16 senderPort; fpgaConnection->readDatagram(buffer.data(), buffer.size(), &sender, &senderPort); qDebug() << "Message from:" << sender; qDebug() << "Message port:" << senderPort; qDebug() << buffer; } } 
  • UdpConnection does not work in a separate thread from the main. Should it be?
  • I successfully bind and I would suggest that "connectToHost" works because I can send a message to the remote host.
  • The application has been added to the Firewall exception list (again, the ARP handshake proves that they are able to communicate).
  • The interface is a direct Ethernet connection between the FPGA and the PC.

Why can Wireshark see these messages, but my program is not working?

UPDATE # 1 Wireshark has 2 kHz packets as LLC packets. The Ethernet header displays the correct destination (my MAC address), source address (hardcoded in FPGA), and length. The IP header has a source IP address of 192.168.10.200, and the destination IP address is 192.168.10.10, the UDP header has a source port of 1920, and a destination port of 1919.

UPDATE # 2 Wireshark Logs: paste.ee/p/98c1H As you can see, the packet is repeated and sent from the FPGA at 2 kHz. The ARP transmission and response can be found as the 5th, 10th and 11th packets.

UPDATE # 3 Incoming IP packets have a valid checksum that is NOT set to 0x0000.

+6
source share
3 answers

The packet does not seem to be a valid UDP datagram.

Edit :

After flashing with the package, it seems that this is enough to change the type in the ethernet header to IPv4 (0x0800).

It shows a weird TTL with a value of 0, but this could be due to the sender.

Original post :

Instead of your current data, you should send it so that you have a valid datagram:

Ethernet headers with IPv4 (14Byte): (as in your implementation, but enter IPv4 0x0800), Source, Dest, Type

 64006a493488 020826283900 0800 

IPv4 headers (20Byte): Version, Other, Size = 1298 (0512) UDP + 20, Identifier, Flags (0x00), FlagOffset (0), TTL (128), Protocol (17 UDP), checksum, source =. 10.200, Dest = .10.10

 45 00 0512 31f0 00 00 80 11 0000 c0a80ac8 c0a80a0a 

UDP-Header (8Byte): Source = 1919, Dest = 1920, Length = 1278 (04fe) = Data + 8, Checksum 2Byte NOT CALCULATION in the example !!!

 077f 0780 003e 9672 

DataPayload : 1270 bytes of raw data

 0a9f.... 

Using this as a datagram, you should not actually use connectToHost() , but use writeDatagram() and now you are probably working with the signal called by the readyRead() slot with hasPendingDatagrams() and readDatagram() .

+1
source

I am not very familiar with Qt, but for the BSD socket APIs I usually use bind to set my receive port, but I don’t use the connection for UDP connections, especially when using different ports, such as 1919 versus 1920 For send socket API use sendto () to send packets with the target IP / port.

So try commenting on connectToHost and directly use writeDatagram when submitting.

+2
source

Try running nc and see what packets get from FPGA

  nc -lu 192.168.10.10 1920 

If you received packages with nc, the problem is in your Qt code. You can try Qt :: DirectConnection in the last (optional) connection argument. perhaps you are blocking the current thread, and the program counter no longer reaches the event loop, and thus, no slots will actually be called.

0
source

Source: https://habr.com/ru/post/1012961/


All Articles