From eb9c03c9084e2eb930a6b1d9c88d56cec17dd215 Mon Sep 17 00:00:00 2001 From: huangxin Date: Thu, 16 Mar 2023 09:57:04 +0800 Subject: [PATCH] =?UTF-8?q?OCT=201.=20=E6=9B=B4=E6=96=B0=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- srcs/opendhcp183/opendhcpd.h | 164 +++++++++++++++++------------------ srcs/opendhcp183/query.cpp | 23 ++--- 2 files changed, 95 insertions(+), 92 deletions(-) diff --git a/srcs/opendhcp183/opendhcpd.h b/srcs/opendhcp183/opendhcpd.h index 4b43817..01334b2 100644 --- a/srcs/opendhcp183/opendhcpd.h +++ b/srcs/opendhcp183/opendhcpd.h @@ -39,7 +39,7 @@ #endif #ifndef SIOCGIFCONF -#include +#include #endif #ifndef _UIO_H_ @@ -70,19 +70,19 @@ typedef struct in_pktinfo IN_PKTINFO; #define IFF_DYNAMIC 0x8000 #endif -#define MYWORD unsigned short -#define MYBYTE unsigned char -#define MYDWORD unsigned int -#define SOCKET_ERROR -1 -#define INVALID_SOCKET -1 -#define SOCKADDR_IN sockaddr_in -#define SOCKADDR sockaddr -#define SOCKET int -#define BOOL bool -#define LPSOCKADDR sockaddr * -#define closesocket close +#define MYWORD unsigned short +#define MYBYTE unsigned char +#define MYDWORD unsigned int +#define SOCKET_ERROR -1 +#define INVALID_SOCKET -1 +#define SOCKADDR_IN sockaddr_in +#define SOCKADDR sockaddr +#define SOCKET int +#define BOOL bool +#define LPSOCKADDR sockaddr * +#define closesocket close -#define STR2INT(val) ((int)strtol((val), nullptr, 10)) +#define STR2INT(val) ((int)strtol((val), nullptr, 10)) #define DISCOVER_RSP_NOT_BOARDCAST (0) @@ -707,77 +707,77 @@ struct data15 { }; //Function Prototypes -bool checkIP(data9 *req, data17 *rangeData, MYDWORD ip); -bool checkMask(MYDWORD); -bool checkRange(data17 *, char); -bool detectChange(); -bool getSection(const char *, char *, MYBYTE, char *); -bool isInt(char *); -bool isIP(char *); -FILE *openSection(const char *, MYBYTE); -MYBYTE pIP(void *, MYDWORD); -MYBYTE pUInt(void *raw, MYDWORD data); -MYBYTE pUShort(void *, MYWORD); -MYBYTE addServer(MYDWORD *, MYBYTE, MYDWORD); -int getRangeInd(MYDWORD); -char *myTrim(char *, char *); -char *myGetToken(char *, MYBYTE); -char *cloneString(char *); -char *getHexValue(MYBYTE *, char *, MYBYTE *); -char *genHostName(char *, const MYBYTE *, MYBYTE); -char *hex2String(char *, const MYBYTE *, MYBYTE); -char *IP2String(char *, MYDWORD); -char *myUpper(char *string); -char *myLower(char *string); -char *readSection(char *, FILE *); -data7 *findDHCPEntry(char *); -data7 *createCache(data71 *pLump); -MYDWORD alad(data9 *); -MYDWORD resad(data9 *); -MYDWORD sdmess(data9 *); -MYDWORD sendRepl(data9 *req); -MYDWORD *findServer(MYDWORD *, MYBYTE, MYDWORD); -int getIndex(char, MYDWORD); -int addDHCPRange(char *dp); -void addVendClass(MYBYTE rangeSetInd, char *vendClass, MYBYTE vendClassSize); -void addUserClass(MYBYTE rangeSetInd, char *userClass, MYBYTE userClassSize); -void addMacRange(MYBYTE rangeSetInd, char *macRange); -void addOptions(data9 *req); -void calcRangeLimits(MYDWORD, MYDWORD, MYDWORD *, MYDWORD *); -void closeConn(); -bool getInterfaces(data1 *pNetwork); -void *init(void *); -void lockOptions(FILE *); -void loadOptions(FILE *, const char *, data20 *); -void mySplit(char *, char *, const char *, char); -void *sendHTTP(void *); -void procHTTP(data19 *); -void pvdata(data9 *, data3 *); -void recvRepl(data9 *); -void lockIP(MYDWORD); -void sendStatus(data19 *req); -void setTempLease(data7 *); -void setLeaseExpiry(data7 *); -void setLeaseExpiry(data7 *, MYDWORD); -void *updateStateFile(void *); -MYWORD fUShort(void *); -MYWORD gdmess(data9 *, MYBYTE); -MYWORD myTokenize(char *, char *, const char *, bool); -MYDWORD fIP(void *raw); -MYDWORD fUInt(void *raw); -int prepareUserHtmlRespStatus(const char **pRsp); +bool checkIP(data9 *req, data17 *rangeData, MYDWORD ip); +bool checkMask(MYDWORD); +bool checkRange(data17 *, char); +bool detectChange(); +bool getSection(const char *, char *, MYBYTE, char *); +bool isInt(char *); +bool isIP(char *); +FILE *openSection(const char *, MYBYTE); +MYBYTE pIP(void *, MYDWORD); +MYBYTE pUInt(void *raw, MYDWORD data); +MYBYTE pUShort(void *, MYWORD); +MYBYTE addServer(MYDWORD *, MYBYTE, MYDWORD); +int getRangeInd(MYDWORD); +char *myTrim(char *, char *); +char *myGetToken(char *, MYBYTE); +char *cloneString(char *); +char *getHexValue(MYBYTE *, char *, MYBYTE *); +char *genHostName(char *, const MYBYTE *, MYBYTE); +char *hex2String(char *, const MYBYTE *, MYBYTE); +char *IP2String(char *, MYDWORD); +char *myUpper(char *string); +char *myLower(char *string); +char *readSection(char *, FILE *); +data7 *findDHCPEntry(char *); +data7 *createCache(data71 *pLump); +MYDWORD alad(data9 *); +MYDWORD resad(data9 *); +MYDWORD sdmess(data9 *); +MYDWORD sendRepl(data9 *req); +MYDWORD *findServer(MYDWORD *, MYBYTE, MYDWORD); +int getIndex(char, MYDWORD); +int addDHCPRange(char *dp); +void addVendClass(MYBYTE rangeSetInd, char *vendClass, MYBYTE vendClassSize); +void addUserClass(MYBYTE rangeSetInd, char *userClass, MYBYTE userClassSize); +void addMacRange(MYBYTE rangeSetInd, char *macRange); +void addOptions(data9 *req); +void calcRangeLimits(MYDWORD, MYDWORD, MYDWORD *, MYDWORD *); +void closeConn(); +bool getInterfaces(data1 *pNetwork); +void *init(void *); +void lockOptions(FILE *); +void loadOptions(FILE *, const char *, data20 *); +void mySplit(char *, char *, const char *, char); +void *sendHTTP(void *); +void procHTTP(data19 *); +void pvdata(data9 *, data3 *); +void recvRepl(data9 *); +void lockIP(MYDWORD); +void sendStatus(data19 *req); +void setTempLease(data7 *); +void setLeaseExpiry(data7 *); +void setLeaseExpiry(data7 *, MYDWORD); +void *updateStateFile(void *); +MYWORD fUShort(void *); +MYWORD gdmess(data9 *, MYBYTE); +MYWORD myTokenize(char *, char *, const char *, bool); +MYDWORD fIP(void *raw); +MYDWORD fUInt(void *raw); +int prepareUserHtmlRespStatus(const char **pRsp); #ifdef HTTPSERVER_ON -void opendhcp_init_http_server(); +void opendhcp_init_http_server(); #endif -void opendhcp_set_replication_svr(); -void opendhcp_add_ip_pool_set(); -void opendhcp_add_mac_filter(); -int process_iptv_multicast(const unsigned char *p, int size, const char *mac); -int opendhcp_add_listener(); -unsigned int opendhcp_set_lease_time(); -int getHwAddr(char *buff, char *mac); -int arpSet(const char *ifname, char *ipStr, char *mac); +void opendhcp_set_replication_svr(); +void opendhcp_add_ip_pool_set(); +void opendhcp_add_mac_filter(); +int process_iptv_multicast(const unsigned char *p, int size, const char *mac); +int opendhcp_add_listener(); +unsigned int opendhcp_set_lease_time(); +int getHwAddr(char *buff, char *mac); +int arpSet(const char *ifname, char *ipStr, char *mac); #if DISCOVER_RSP_NOT_BOARDCAST -sockaddr_in get_cliAddr(char *nicif, char *tempbuff, data9 *req); +sockaddr_in get_cliAddr(char *nicif, char *tempbuff, data9 *req); #endif #pragma clang diagnostic pop \ No newline at end of file diff --git a/srcs/opendhcp183/query.cpp b/srcs/opendhcp183/query.cpp index b7d7f75..7b442e1 100644 --- a/srcs/opendhcp183/query.cpp +++ b/srcs/opendhcp183/query.cpp @@ -5,18 +5,14 @@ #include using namespace std; -#include -#include #include #include #include -#include #include #include #include "opendhcpd.h" #include "s2j/cJSON.h" #include "misc.h" -#include #include #include "config.h" #include "proto.h" @@ -27,6 +23,12 @@ using namespace std; #include "http_svr.h" #include "task_manager.h" +#if DISCOVER_RSP_NOT_BOARDCAST +#include +#include +#include +#endif + extern data2 cfig; extern bool kRunning; extern dhcpMap dhcpCache; @@ -45,11 +47,12 @@ static PIPTV_DEV_SET g_iptvCacheDevs = nullptr; static uv_rwlock_t g_uvCacheLock; #ifdef JSON_SCHEMA_ON +// clang-format off const char *g_json_msg[] = { - "{\"type\":\"object\",\"required\":[\"rangeSet\"],\"properties\":{\"rangeSet\":{\"type\":\"array\",\"minItems\":1,\"items\":{\"type\":\"object\",\"required\":[\"dhcpRange\"]}}}}", - "{\"type\":\"object\",\"required\":[\"dhcpRange\"],\"properties\":{\"dhcpRange\":{\"type\":\"array\",\"minItems\":1}}}", - "{\"type\":\"object\",\"required\":[\"userMac\"],\"properties\":{\"userMac\":{\"type\":\"array\",\"minItems\":1}}}" -}; + R"({"type":"object","required":["rangeSet"],"properties":{"rangeSet":{"type":"array","minItems":1,"items":{"type":"object","required":["dhcpRange"]}}}})", + R"({"type":"object","required":["dhcpRange"],"properties":{"dhcpRange":{"type":"array","minItems":1}}})", + R"({"type":"object","required":["userMac"],"properties":{"userMac":{"type":"array","minItems":1}}})"}; +// clang-format on #endif static int dhcp_get_user_info(const char **pRsp, const char *pRequest) { @@ -977,8 +980,8 @@ static HTTP_ROUTE_INFO g_routeTable[] = { }; void opendhcp_init_http_server() { - static int added = FALSE; - static uv_timer_t uvTm; + static int added = FALSE; + static uv_timer_t uvTm; if (!added) { uv_rwlock_init(&g_uvCacheLock); uv_timer_init(get_task_manager(), &uvTm);