在 Wireshark 中看到的数据报,未被 Qt UDP 套接字接收 [英] Datagrams seen in Wireshark, not received by Qt UDP Socket

查看:93
本文介绍了在 Wireshark 中看到的数据报,未被 Qt UDP 套接字接收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个通过 UDP 套接字与 FPGA 通信的 Qt (5.6) 应用程序.数据包以 2 KHz 的速率传输到 PC(所有数据包大小相同,1272 字节).Wireshark 显示正在发送数据包,UDP 标头符合预期.问题是,我使用的 Qt UDP 套接字从不接收这些数据包.readyRead 信号永远不会被调用.

I am writing a Qt (5.6) application that communicates with an FPGA over UDP socket. Packets are being streamed to the PC at 2 KHz (all packets identical size, 1272 bytes). Wireshark shows that packets are being sent, and the UDP header is as expected. The problem is, the Qt UDP Socket that I am using is never receiving these packets. The readyRead signal is never called.

这是一个代码片段:

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 没有在与主线程不同的线程上运行.应该是吗?
  • 我绑定成功,我假设connectToHost"正在工作,因为我能够向远程主机发送消息.
  • 该应用程序已添加到防火墙例外列表中(再次,ARP 握手证明它们能够通信).
  • 该接口是 FPGA 和 PC 之间的直接以太网连接.
  • 为什么 Wireshark 可以看到这些消息,而我的程序却看不到?

    Why is Wireshark able to see these messages, but my program is not?

    更新 #1Wireshark 将 2KHz 数据包作为 LLC 数据包.以太网标头显示正确的目标(我的 MAC 地址)、源地址(在 FPGA 中硬编码)和长度.IP头的Source IP为192.168.10.200,Destination IP为192.168.10.10,UDP Header的Source Port为1920,Destination Port为1919.

    UPDATE #1 Wireshark has the 2KHz packets as LLC packets. The Ethernet Header shows a correct Destination (my MAC address), Source Address (hard coded in the FPGA), and Length. The IP header has the Source IP as 192.168.10.200 and the Destination IP as 192.168.10.10, UDP Header has Source Port as 1920 and Destination Port as 1919.

    更新 #2Wireshark 日志:paste.ee/p/98c1H如您所见,数据包以 2KHz 的频率从 FPGA 重复并发送.ARP传输和回复可以在第5个、第10个和第11个数据包中找到.

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

    更新 #3传入数据包的 IP 数据包具有未设置为 0x0000 的正确校验和.

    UPDATE #3 The IP packets of the incoming packets have a correct checksum that is NOT being set to 0x0000.

    推荐答案

    数据包似乎不是有效的 UDP 数据报.

    The packet seems not to be a valid UDP Datagram.

    编辑:

    摆弄数据包后,似乎足以将以太网标头中的类型更改为 IPv4 (0x0800).

    After fiddling with the packet it seem to be enough to change the type in the ethernet header to to IPv4 (0x0800).

    它确实显示了一个奇怪的 TTL,值为 0,但这可能与发件人有关.

    It does show a strange TTL with a value of 0, but that may be sender related.

    原帖:

    你应该像这样发送一个有效的数据报,而不是你当前的数据:

    Instead of your current data you should send like this for having a valid datagram:

    带有 IPv4 的以太网标头(14 字节):(与您的实现相同,但键入 IPv4 0x0800)、源、目标、类型

    Ethernet Headers w/ IPv4 (14Byte): (as in your implementation, but type IPv4 0x0800), Source, Dest, Type

    64006a493488 020826283900 0800
    

    IPv4-Headers (20Byte): Version, Other, Size=1298(0512) UDP + 20, Ident, Flags(0x00), FlagOffset(0), TTL(128), Protocol(17 UDP),校验和,源 = .10.200,目标 = .10.10

    IPv4-Headers (20Byte): Version, Other, Size=1298(0512) UDP + 20, Ident, 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 CALCULATED in example!!!

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

    077f 0780 003e 9672
    

    DataPayload:1270 字节的原始数据

    DataPayload: 1270 Byte of raw data

    0a9f....
    

    使用它作为数据报,你实际上不应该使用 connectToHost() 而是使用 writeDatagram() 并且现在可能通过调用信号readyRead() 工作带有 hasPendingDatagrams()readDatagram() 的 code> 槽.

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

    这篇关于在 Wireshark 中看到的数据报,未被 Qt UDP 套接字接收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆