From ec5dc9e9000f13203d35570c9375052b5847f637 Mon Sep 17 00:00:00 2001 From: dongwenze Date: Mon, 12 Dec 2022 15:45:25 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=9A=84=E9=83=A8=E5=88=86=E5=AE=9E=E7=8E=B0=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- srcs/open_dhcp/query.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/srcs/open_dhcp/query.cpp b/srcs/open_dhcp/query.cpp index c79b145..40685b6 100644 --- a/srcs/open_dhcp/query.cpp +++ b/srcs/open_dhcp/query.cpp @@ -104,17 +104,16 @@ static int dhcp_get_user_info(data19 *req, const char *pRequest) { } else { cJSON_AddStringToObject(pRspItem, "leaseExpiry", "Expiry"); } + cJSON_AddNumberToObject(pRspItem, "status", ERR_SUCCESS); + cJSON_AddStringToObject(pRspItem, "message", getErrorEnumDesc(ERR_SUCCESS)); } else { - cJSON_AddStringToObject(pRspItem, "ip", ""); - cJSON_AddStringToObject(pRspItem, "hostname", ""); + cJSON_AddNumberToObject(pRspItem, "status", ERR_ITEM_UNEXISTS); + cJSON_AddStringToObject(pRspItem, "message", getErrorEnumDesc(ERR_ITEM_UNEXISTS)); } cJSON_AddItemToArray(pMsgArray, pRspItem); } - cJSON_AddNumberToObject(pRspMsg, "status", ERR_SUCCESS); - cJSON_AddStringToObject(pRspMsg, "message", getErrorEnumDesc(ERR_SUCCESS)); - const char *pStrPro = proto_create_new(pRspMsg, 200); //cJSON_AddItemToObject(pRspRoot, "msgContent", pRspMsg); @@ -564,12 +563,6 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) { return ERR_SUCCESS; } -static void revert(unsigned int *num) { - unsigned int v = *num; - v = ((v & 0x000000FF) << 24) | ((v & 0x0000FF00) << 8) | ((v & 0x00FF0000) >> 8) | ((v & 0xFF000000) >> 24); - *num = v; -} - static int query_dhcpd_rangeset(data19 *req) { char logBuff[512]; req->memSize = (int)(2048 + (135 * dhcpCache.size()) + (cfig.dhcpSize * 26)); @@ -627,8 +620,7 @@ static int query_dhcpd_rangeset(data19 *req) { dnsSize = op.size; do { tmpVal = fIP(op.value + offset); - revert(&tmpVal); - IP2String(dns_op, ntohl(tmpVal)); + IP2String(dns_op, htonl(ntohl(tmpVal))); sprintf(domainServer, "%s%s", domainServer, dns_op); if (dnsSize != 4) { sprintf(domainServer, "%s,", domainServer); @@ -640,14 +632,13 @@ static int query_dhcpd_rangeset(data19 *req) { cJSON_AddStringToObject(pRangeItem, "domainServer", domainServer); } else if (op.opt_code == DHCP_OPTION_ROUTER) { tmpVal = fIP(op.value); - revert(&tmpVal); - IP2String(gateway, ntohl(tmpVal)); + IP2String(gateway, htonl(ntohl(tmpVal))); cJSON_AddStringToObject(pRangeItem, "gateway", gateway); } else if (op.opt_code == DHCP_OPTION_IPADDRLEASE) { lease = fUInt(op.value); - cJSON_AddNumberToObject(pRangeItem, "lease", lease); + cJSON_AddNumberToObject(pRangeItem, "leaseTime", lease); } opPointer += op.size; }