66 lines
1.4 KiB
C
66 lines
1.4 KiB
C
#ifndef GLOBALFUNC_H
|
|
#define GLOBALFUNC_H
|
|
|
|
#include <QWidget>
|
|
#include <QtEndian>
|
|
#include "pcaprethread.h"
|
|
|
|
struct Head {
|
|
byte pre[2]{0x55, 0x55};
|
|
byte ver{1};
|
|
byte srv{0};
|
|
quint16_be len{0};
|
|
byte tgtAddr[4]{0xff, 0xff, 0xff, 0xff};
|
|
byte srcAddr[4]{0, 0, 0, 0};
|
|
byte ptr[4]{0, 0, 0, 0};
|
|
byte ans[2]{0, 0};
|
|
quint32_be chk{0};
|
|
byte bodyh[4]{0, 0, 0, 0};
|
|
quint16_be bodylen{0};
|
|
};
|
|
struct Msg1024 : Head {
|
|
byte body[1024-sizeof(Head)]{0};
|
|
};
|
|
static byte fi = 0;
|
|
inline byte ie(byte size = 1) {
|
|
fi = size;
|
|
return 0;
|
|
}
|
|
inline byte ipp(byte size = 1) {
|
|
auto rtn = fi;
|
|
fi += size;
|
|
return rtn;
|
|
}
|
|
struct HeadMap {
|
|
byte pre{ipp(2)};
|
|
byte ver{fi++};
|
|
byte srv{fi++};
|
|
byte len{ipp(2)};
|
|
byte tgtAddr{ipp(4)};
|
|
byte srcAddr{ipp(4)};
|
|
byte ptr{ipp(4)};
|
|
byte ans{ipp(2)};
|
|
byte chk{ipp(4)};
|
|
byte body{ipp(4)};
|
|
byte bodylen{ipp(2)};
|
|
byte end{fi};
|
|
};
|
|
extern HeadMap headMap;
|
|
extern pcap_t *pcapSend;
|
|
extern PcapReThread *reThd;
|
|
|
|
QByteArray getNetDev(QWidget *parent, QByteArray, bool);
|
|
|
|
inline int sendMsgNet(const byte *msg, int size, const Resp &resp) {
|
|
reThd->addResp(resp);
|
|
return pcap_sendpacket(pcapSend, msg, size);
|
|
}
|
|
inline int sendMsg(const byte *msg, int size, const Resp &resp) {
|
|
return sendMsgNet(msg, size, resp);
|
|
}
|
|
inline int sendMsg(QByteArray &msg, const Resp &resp) {
|
|
return sendMsg((byte*)msg.data(), msg.size(), resp);
|
|
}
|
|
|
|
#endif // GLOBALFUNC_H
|