Unsolved Pacp - Send Data
-
@neda said in Pacp - Send Data:
fprintf( stderr,"\nError sending the packet: \n", pcap_geterr( adhandle ));
What does this line print out?
And I'm not sure what this has to do with Qt. -
@jsulm said in Pacp - Send Data:
What does this line print out?
PacketSendPacket failed
And I'm not sure what this has to do with Qt.
I did not find a document or a good sample to use "pcap" in Qt.
-
@neda
Hi
And you did install winpcap/Win10Pcap so the driver is running?
Also, you are using visual studio compiler ?
Im not sure it works with mingw. -
@mrjj said in Pacp - Send Data:
Also, you are using visual studio compiler ?
Qt 5.12.5 MSVC2017 32bit
And you did install winpcap/Win10Pcap so the driver is running?
I installed "http://www.win10pcap.org/download/Win10Pcap-v10.2-5002.msi".
Now "pcap_sendpacket" return 0, It's OK.
But I do not have a correct answer from the device.I have a "QByteArray" Data for send such as:
"\x02\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
I don't know this code is true or not.
void PCAPNetwork::sendData(const QByteArray &data) { const u_char* p= reinterpret_cast<const uchar *>(data.constData()); //std::memcpy(&p,data.constData(),data.size()); pcap_sendpacket(adhandle, p, sizeof(p) );
-
@neda
Hi
from a quick glance - it looks ok.
Should not truncate values. -
I think I was wrong in reading data.
The device sends a lot of data in real-time.
I read them by this code.void PCAPNetwork::packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data) {
How can I convert "pkt_data" to decimal?
-
@neda said in Pacp - Send Data:
u_char
But is this not a byte already ?
If you place cursor on u_char and press F2, what is it then defined as?
-
u_char = unsigned char
qDebug()<<"data: "<<pkt_data;
output:
data: 0x46c16bc
I don't know how can I convert it to decimal.
-
@neda
Is it zero terminated ?That is the address it writes out. Not the actual data i think.
You can convert it to bytearray
QByteArray databuf = QByteArray(reinterpret_cast<char*>(pkt_data), header->len);
(i think but not 100% sure header->len is data len. check docs) -
@mrjj said in Pacp - Send Data:
Not the actual data i think.
You right.
The device sends a lot of data in real-time.
How can I read the actual data? -
@neda
The data is in pkt_data as far as i can see from docs
so try
QByteArray databuf = QByteArray(reinterpret_cast<char*>(pkt_data), header->len);
qDebug()<<"data: "<<databuf ;