Add ZNJK-1003 dhcp服务器所有用户的MAC地址查询
This commit is contained in:
parent
697c81b467
commit
a5ddf0e358
|
@ -219,6 +219,7 @@ const data4 opData[] = {
|
|||
};
|
||||
|
||||
static void sendUserList(data19 *req, const char *pRequest);
|
||||
static void sendAllLists(data19 *req);
|
||||
|
||||
int dhcpd_main(int argc, char **argv) {
|
||||
char logBuff[256] = "";
|
||||
|
@ -742,6 +743,11 @@ void procHTTP(data19 *req) {
|
|||
return;
|
||||
}
|
||||
|
||||
// if (strcmp(pMethod, "POST") == 0) {
|
||||
// sendAllLists(req);
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (pMethod) {
|
||||
free((void *)pMethod);
|
||||
}
|
||||
|
@ -750,10 +756,13 @@ void procHTTP(data19 *req) {
|
|||
free((void *)pBody);
|
||||
}
|
||||
|
||||
if (fp && !strcasecmp(fp, "/"))
|
||||
|
||||
if (fp && !strcasecmp(fp, "/allusers"))
|
||||
sendAllLists(req);
|
||||
else if (fp && !strcasecmp(fp, "/"))
|
||||
sendStatus(req);
|
||||
// else if (fp && !strcasecmp(fp, "/scopestatus"))
|
||||
// sendScopeStatus(req);
|
||||
// sendScopeStatus(req)
|
||||
else {
|
||||
if (fp && (verbatim || cfig.dhcpLogLevel >= 2)) {
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
//debug("sendStatus");
|
||||
char ipbuff[16];
|
||||
|
|
Loading…
Reference in New Issue