Add ZNJK-1003 dhcp服务器所有用户的MAC地址查询

This commit is contained in:
dongwenze 2022-09-29 14:33:20 +08:00
parent 697c81b467
commit a5ddf0e358
1 changed files with 68 additions and 2 deletions

View File

@ -219,6 +219,7 @@ const data4 opData[] = {
}; };
static void sendUserList(data19 *req, const char *pRequest); static void sendUserList(data19 *req, const char *pRequest);
static void sendAllLists(data19 *req);
int dhcpd_main(int argc, char **argv) { int dhcpd_main(int argc, char **argv) {
char logBuff[256] = ""; char logBuff[256] = "";
@ -742,6 +743,11 @@ void procHTTP(data19 *req) {
return; return;
} }
// if (strcmp(pMethod, "POST") == 0) {
// sendAllLists(req);
// return;
// }
if (pMethod) { if (pMethod) {
free((void *)pMethod); free((void *)pMethod);
} }
@ -750,10 +756,13 @@ void procHTTP(data19 *req) {
free((void *)pBody); free((void *)pBody);
} }
if (fp && !strcasecmp(fp, "/"))
if (fp && !strcasecmp(fp, "/allusers"))
sendAllLists(req);
else if (fp && !strcasecmp(fp, "/"))
sendStatus(req); sendStatus(req);
// else if (fp && !strcasecmp(fp, "/scopestatus")) // else if (fp && !strcasecmp(fp, "/scopestatus"))
// sendScopeStatus(req); // sendScopeStatus(req)
else { else {
if (fp && (verbatim || cfig.dhcpLogLevel >= 2)) { if (fp && (verbatim || cfig.dhcpLogLevel >= 2)) {
sprintf(logBuff, "HTTP Client %s, %s not found", IP2String(tempbuff, req->remote.sin_addr.s_addr), fp); sprintf(logBuff, "HTTP Client %s, %s not found", IP2String(tempbuff, req->remote.sin_addr.s_addr), fp);
@ -893,6 +902,63 @@ static void sendUserList(data19 *req, const char *pRequest) {
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
} }
static void sendAllLists(data19* req){
char rsp[] =
"{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1599187216753,\"code\":200,\"msgContent\":{\"items\":[],\"status\":"
"0,\"message\":[\"Success\"]}}";
char logBuff[512];
data7 *dhcpEntry = nullptr;
dhcpMap::iterator p;
req->memSize = (int)(2048 + (135 * dhcpCache.size()) + (cfig.dhcpSize * 26));
req->dp = (char *)calloc(1, req->memSize);
if (!req->dp) {
sprintf(logBuff, "Memory Error");
logDHCPMess(logBuff, 1);
closesocket(req->sock);
free(req);
return;
}
char *fp = req->dp;
char *maxData = req->dp + (req->memSize - 512);
cJSON *pRspRoot = cJSON_CreateObject();
cJSON_AddNumberToObject(pRspRoot, "version", 3);
cJSON_AddNumberToObject(pRspRoot, "cryptoType", 0);
cJSON_AddNumberToObject(pRspRoot, "timeStamp", (unsigned int)time(nullptr));
cJSON *pRspMsg = cJSON_CreateObject();
cJSON *pMsgArray = cJSON_CreateArray();
// cJSON_AddItemToObject(pRspMsg, "", pMsgArray);
for (p = dhcpCache.begin(); kRunning && p != dhcpCache.end() && fp < maxData; p++) {
// cJSON *pRspItem = cJSON_CreateObject();
if ((dhcpEntry = p->second)) {
cJSON_AddStringToObject(pMsgArray, " ", dhcpEntry->mapname);
}
// cJSON_AddItemToArray(pMsgArray, pRspItem);
}
cJSON_AddItemToObject(pRspRoot, "msgContent", pMsgArray);
fp += sprintf(fp, "%s", cJSON_Print(pRspRoot));
cJSON_Delete(pRspRoot);
req->bytes = (int)(fp - req->dp);
pthread_t threadId;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
int errcode = pthread_create(&threadId, &attr, sendHTTP, (void *)req);
pthread_attr_destroy(&attr);
}
void sendStatus(data19 *req) { void sendStatus(data19 *req) {
//debug("sendStatus"); //debug("sendStatus");
char ipbuff[16]; char ipbuff[16];