QUdpSocket sending malformed packets

572 views Asked by At

I am setting up a QUdpSocket broadcaster. when I view the output in wireshark, it says my packets are malformed. Inspecting the packets, it appears they are not emitted with an ethernet trailer. Do I need to emit this myself, or do you see another issue? My code below is slightly condensed. Note that if connected via crossover cable my receiving device (micro-controller) does see and respond to the packet (as seen on wireshark). I want to make sure I don't have malformed frames so I can use this on a switched network which allows UDP traffic.

Thanks

const quint16 s_packetHeader = 0x5A5A;
const quint16 s_sendReadBackRegisters = 0x0203;

m_udpSocketWriter= new QUdpSocket(this);
QByteArray datagram;
QDataStream ds(&datagram, QIODevice::WriteOnly);
ds.setVersion(QDataStream::Qt_4_8);
ds << s_packetHeader << s_sendReadBackRegisters;
m_udpSocketWriter->writeDatagram(datagram.data(), datagram.size(), QHostAddress::Broadcast, 5000);

and the output from wireshark

"1243","886.645245000","172.27.1.117","255.255.255.255","UDP","46","Source port: 58411  Destination port: 5000[Malformed Packet]"

0000   ff ff ff ff ff ff d4 3d 7e 31 e0 27 08 00 45 00  .......=~1.'..E.
0010   00 20 38 6b 00 00 80 11 54 d2 ac 1b 01 75 ff ff  . 8k....T....u..
0020   ff ff e4 2b 13 88 00 0c fe 34 5a 5a 02 03        ...+.....4ZZ..

Note that the last four bytes correspond to the data I sent, 5A 5A 02 03.

According to a google image search, the packet is missing the trailer bits... although I am no network expert that is totally a guess.

Windows 7 x64, VS2010, QT 4.8-latest x64

0

There are 0 answers