#include "globalfunc.h" #include "gutil/qgui.h" #include "pcap.h" #include #include #include #include QString gFileHome; HeadMap headMap; HeadMap_ZRF headMap_zrf; //added by alahover 20230822 St_Zrf_rb_Param st_zrf_rb_param; //added by alahover 20230825 St_Zrf_Base_Param st_zrf_base_param; //added by alahover 20230823 St_Zrf_Cmd_Param st_zrf_cmd_param; //added by alahover 20230823 St_MiaoDian_Param st_miaodian_param; //added by alahover 20230823 byte *getSepas() { auto sepas = new byte[headMap.end+4]{0}; sepas[headMap.ver] = ' '; sepas[headMap.srv] = ' '; sepas[headMap.len] = ' '; sepas[headMap.tgtAddr] = ' '; sepas[headMap.srcAddr] = ' '; sepas[headMap.ptr] = ' '; sepas[headMap.ans] = ' '; sepas[headMap.chk] = ' '; sepas[headMap.body] = '\n'; sepas[headMap.bodylen] = ' '; sepas[headMap.end] = ' '; return sepas; } byte *sepas = getSepas(); pcap_t *pcapSend{0}; PcapReThread *reThd{0}; SyncResp sendMsgSync(QByteArray &msg, int id, qint64 timeout, WaitingDlg *waitingDlg) { QEventLoop loop; QByteArray resmsg; auto res = reThd->sendMsgNet((byte*)msg.data(), msg.size(), id, timeout, [=, &loop, &resmsg](int code, const QByteArray data) { resmsg = data; loop.exit(code); }, true, waitingDlg); if(res==0) res = loop.exec(QEventLoop::ExcludeUserInputEvents); if(res && waitingDlg) waitingDlg->close(); return {res, resmsg}; } QByteArray getNetDev(QWidget *parent, QByteArray def, bool justReturnIfHave) { char errbuf[PCAP_ERRBUF_SIZE]; pcap_if_t *devs; if(pcap_findalldevs(&devs, errbuf) == -1) { QMessageBox::critical(parent, "Error", QString("寻找网卡失败")+errbuf); return QByteArray(); } auto table = new Table{ {"name", "网卡名称"}, {"desc", "网卡描述"}, {"loopback", "Loopback"}, {"ip", "IP"}, {"netmask", "Netmask"}, {"broadaddr", "Broad Addr"}, {"dstaddr", "Dst Addr"} }; pcap_if_t *device = 0; for(pcap_if_t *dev = devs; dev; dev = dev->next) { pcap_addr_t *a; for(a=dev->addresses; a; a=a->next) { auto sa_family = a->addr->sa_family; if(sa_family==AF_INET) { if(justReturnIfHave && ! def.isEmpty() && dev->name == def) { pcap_freealldevs(devs); table->deleteLater(); return def; } auto rr = table->rowCount(); table->setRowCount(rr+1); table->setText(rr, "name", dev->name); table->setText(rr, "desc", dev->description); table->setText(rr, "loopback", (dev->flags & PCAP_IF_LOOPBACK)?"True":"False"); auto ip = (u_char *) &((sockaddr_in *) a->addr)->sin_addr.s_addr; table->setText(rr, "ip", QString::asprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])); if(a->netmask) { ip = (u_char *) &((sockaddr_in *) a->netmask)->sin_addr.s_addr; table->setText(rr, "netmask", QString::asprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])); } if(a->broadaddr) { ip = (u_char *) &((sockaddr_in *) a->broadaddr)->sin_addr.s_addr; table->setText(rr, "broadaddr", QString::asprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])); } if(a->dstaddr) { ip = (u_char *) &((sockaddr_in *) a->dstaddr)->sin_addr.s_addr; table->setText(rr, "dstaddr", QString::asprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])); } if(device==0) device = dev; } } } pcap_freealldevs(devs); auto rowCnt = table->rowCount(); if(rowCnt==0) { table->deleteLater(); QMessageBox::critical(parent, "Error", "没找到 internet 设备"); return QByteArray(); } else if(rowCnt==1) { table->deleteLater(); return table->item(0, "name")->text().toLocal8Bit(); } else { QDialog dlg(parent); dlg.setWindowFlag(Qt::WindowMaximizeButtonHint); dlg.setWindowTitle("选择网卡"); dlg.resize(900, 300); auto vBox = new QVBoxLayout(&dlg); vBox->setContentsMargins(0,0,0,0); vBox->setSpacing(3); vBox->addSpacing(30); table->setDefs(); table->setSelectionMode(QAbstractItemView::SingleSelection); table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); if(! def.isEmpty()) for(int r=0; rrowCount(); r++) if(table->item(r, "name")->text()==def) table->selectRow(r); QByteArray name; QObject::connect(table, &Table::cellDoubleClicked, &dlg, [&, table](int row) { name = table->item(row, "name")->text().toLocal8Bit(); dlg.accept(); }); vBox->addWidget(table); auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close); QObject::connect(btnBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject); QObject::connect(btnBox, &QDialogButtonBox::accepted, &dlg, [&, table] { auto sels = table->selectedRanges(); if(sels.isEmpty()) { QMessageBox::warning(&dlg, "Warning", "请选择网卡"); return; } name = table->item(sels[0].topRow(), "name")->text().toLocal8Bit(); dlg.accept(); }); vBox->addWidget(btnBox); dlg.exec(); return name; } } //added by alahover -s 20230829 #define GAMMA_GRAY_DEPTH_NUM (256) void GammaGen(unsigned short pGammaDataBuffer[],float fGamma,unsigned int uiGray) { unsigned int i=0; float fGray=0; float k=0; fGray=(float)uiGray; k=(fGray/GAMMA_GRAY_DEPTH_NUM); for (i=0;i=uiGray) { pGammaDataBuffer[i]=(unsigned int)uiGray-1; } } if (0) printf("G[%d]=%d\r\n",i,pGammaDataBuffer[i]); } } //added by alahover -o 20230829 int GetIcTypeFromName(QString strName) { int iResult=0; //"ICN系列" if(strName == "ICN2026" ) iResult = enum_normal; if(strName == "ICN2027" ) iResult = enum_normal; if(strName == "ICN2028" ) iResult = enum_normal; if(strName == "ICN2037" ) iResult = enum_normal; if(strName == "ICN2038" ) iResult = enum_normal; if(strName == "ICN2038S" ) iResult = enum_normal; if(strName == "ICN2053" ) iResult = enum_pwm; if(strName == "ICN2058" ) iResult = enum_normal; if(strName == "ICN2088" ) iResult = enum_normal; if(strName == "ICND2045" ) iResult = enum_normal; if(strName == "ICND2046" ) iResult = enum_normal; if(strName == "ICND2047" ) iResult = enum_normal; if(strName == "ICND2049" ) iResult = enum_normal; if(strName == "ICND2055" ) iResult = enum_normal; if(strName == "ICND2059" ) iResult = enum_normal; if(strName == "ICND2065" ) iResult = enum_normal; if(strName == "ICND2069" ) iResult = enum_normal; if(strName == "ICND2076" ) iResult = enum_normal; if(strName == "ICND2110" ) iResult = enum_normal; if(strName == "ICND2112" ) iResult = enum_normal; if(strName == "ICND2153" ) iResult = enum_normal; if(strName == "ICND2153_three") iResult = enum_normal; if(strName == "ICND2163") iResult = enum_normal; if(strName == "ICND2200") iResult = enum_normal; // "SM系列" if(strName == "SM16017_NEW") iResult = enum_normal; if(strName == "SM16017S") iResult = enum_normal; if(strName == "SM16159S") iResult = enum_normal; if(strName == "SM16169S") iResult = enum_normal; if(strName == "SM16207S") iResult = enum_normal; if(strName == "SM16218") iResult = enum_normal; if(strName == "SM16227S") iResult = enum_normal; if(strName == "SM16237DS") iResult = enum_normal; if(strName == "SM16237S") iResult = enum_normal; if(strName == "SM16259S") iResult = enum_normal; if(strName == "SM16259S") iResult = enum_normal; if(strName == "SM16369") iResult = enum_normal; if(strName == "SM16380") iResult = enum_normal; if(strName == "SM16388") iResult = enum_normal; if(strName == "SM16389") iResult = enum_normal; if(strName == "SM16509/16399") iResult = enum_normal; //"LS系列" if(strName == "LS9918S") iResult = enum_normal; if(strName == "LS9919S") iResult = enum_normal; if(strName == "LS9926S") iResult = enum_normal; if(strName == "LS9929C") iResult = enum_normal; if(strName == "LS9929S") iResult = enum_normal; if(strName == "LS9930S") iResult = enum_normal; if(strName == "LS9931S") iResult = enum_normal; if(strName == "LS9935B") iResult = enum_normal; if(strName == "LS9935S") iResult = enum_normal; if(strName == "LS9936S") iResult = enum_normal; if(strName == "LS9961S") iResult = enum_normal; //"MBI系列" if(strName == "MBI5041/5042") iResult = enum_normal; if(strName == "MBI5051") iResult = enum_normal; if(strName == "MBI5124") iResult = enum_normal; if(strName == "MBI5151") iResult = enum_normal; if(strName == "MBI5153") iResult = enum_normal; if(strName == "MBI5155") iResult = enum_normal; if(strName == "MBI5158") iResult = enum_normal; if(strName == "MBI5252") iResult = enum_normal; if(strName == "MBI5253") iResult = enum_normal; if(strName == "MBI5253B") iResult = enum_normal; if(strName == "MBI5254") iResult = enum_normal; if(strName == "MBI5264") iResult = enum_normal; if(strName == "MBI5268") iResult = enum_normal; if(strName == "MBI5353") iResult = enum_normal; if(strName == "MBI5353B") iResult = enum_normal; if(strName == "MBI6322") iResult = enum_normal; if(strName == "MBI6328") iResult = enum_normal; if(strName == "MBI6334") iResult = enum_normal; //"SUM系列" if(strName == "SUM2017") iResult = enum_normal; if(strName == "SUM2017T") iResult = enum_normal; if(strName == "SUM2017TD") iResult = enum_normal; if(strName == "SUM2028") iResult = enum_normal; if(strName == "SUM2030") iResult = enum_normal; if(strName == "SUM2030T") iResult = enum_normal; if(strName == "SUM2032") iResult = enum_normal; if(strName == "SUM2033") iResult = enum_normal; if(strName == "SUM2035") iResult = enum_normal; if(strName == "SUM2036") iResult = enum_normal; if(strName == "SUM2037") iResult = enum_normal; if(strName == "SUM2117") iResult = enum_normal; if(strName == "SUM2130") iResult = enum_normal; if(strName == "SUM2131") iResult = enum_normal; if(strName == "SUM2135") iResult = enum_normal; if(strName == "SUM6086") iResult = enum_normal; //"FM系列") if(strName == "FM6128") iResult = enum_normal; if(strName == "FM6129") iResult = enum_normal; if(strName == "FM6153") iResult = enum_normal; if(strName == "FM6182") iResult = enum_normal; if(strName == "FM6253") iResult = enum_normal; if(strName == "FM6353") iResult = enum_normal; if(strName == "FM6356") iResult = enum_normal; if(strName == "FM6363") iResult = enum_normal; if(strName == "FM6555") iResult = enum_normal; if(strName == "FM6565/6569") iResult = enum_normal; if(strName == "FM6565CE") iResult = enum_normal; //"DP系列" if(strName == "DP5135") iResult = enum_normal; if(strName == "DP5220X") iResult = enum_normal; if(strName == "DP5525") iResult = enum_normal; //"MY系列"); if(strName == "MY9758") iResult = enum_normal; if(strName == "MY9862") iResult = enum_normal; if(strName == "MY9866") iResult = enum_normal; //"LYD系列" if(strName == "LYD6168B") iResult = enum_normal; if(strName == "LYD6168C") iResult = enum_normal; if(strName == "LYD6168D") iResult = enum_normal; if(strName == "LYD6168E") iResult = enum_normal; if(strName == "LYD6188") iResult = enum_normal; if(strName == "LYD6188PC") iResult = enum_normal; //"其他系列" if(strName == "通用") iResult = enum_normal; if(strName == "A5065") iResult = enum_normal; if(strName == "AXS6018") iResult = enum_normal; if(strName == "CFD135A") iResult = enum_normal; if(strName == "CFD455A") iResult = enum_normal; if(strName == "CNS7153") iResult = enum_normal; if(strName == "CNS7253") iResult = enum_normal; if(strName == "CNS7263") iResult = enum_normal; if(strName == "CS2017") iResult = enum_normal; if(strName == "CS2033") iResult = enum_normal; if(strName == "D26188") iResult = enum_normal; if(strName == "HX8055") iResult = enum_normal; if(strName == "HX8864") iResult = enum_normal; if(strName == "HX8896") iResult = enum_normal; if(strName == "RT5965") iResult = enum_normal; if(strName == "RT5967") iResult = enum_normal; if(strName == "SCL8081A") iResult = enum_normal; if(strName == "XM11202G") iResult = enum_normal; return iResult; }