diff --git a/srcs/libs/docs/OpenDHCPServerManual.pdf b/srcs/libs/docs/OpenDHCPServerManual.pdf index d93f135..f90ea25 100644 Binary files a/srcs/libs/docs/OpenDHCPServerManual.pdf and b/srcs/libs/docs/OpenDHCPServerManual.pdf differ diff --git a/srcs/opendhcp183/opendhcpd.cpp b/srcs/opendhcp183/opendhcpd.cpp index 62fcd35..c656db8 100644 --- a/srcs/opendhcp183/opendhcpd.cpp +++ b/srcs/opendhcp183/opendhcpd.cpp @@ -27,8 +27,6 @@ #include #include #include -#include -#include #include #include #include @@ -37,6 +35,7 @@ #include #include using namespace std; +#include #include "dhcpd.h" #include "opendhcpd.h" #include "user_errno.h" @@ -64,18 +63,18 @@ char serviceName[] = "OpenDHCP"; char exeFile[PATH_MAX] = ""; char iniFile[PATH_MAX] = ""; char leaFile[PATH_MAX] = ""; -char logFile[PATH_MAX] = ""; +//char logFile[PATH_MAX] = ""; char tempFile[PATH_MAX] = "/tmp/opendhcp.tmp"; char filePATH[PATH_MAX] = ""; char htmlTitle[PATH_MAX] = ""; char icoFile[PATH_MAX] = ""; char nicif[256] = ""; char *icoString = nullptr; -int icoSize = 0; +unsigned long icoSize = 0; data71 lump; -char arpa[] = ".in-addr.arpa"; -char ip6arpa[] = ".ip6.arpa"; -time_t t = time(nullptr); +//char arpa[] = ".in-addr.arpa"; +//char ip6arpa[] = ".ip6.arpa"; +time_t t = time(nullptr); timeval tv; fd_set readfds; //fd_set writefds; @@ -104,8 +103,7 @@ const char htmlStart const char bodyStart [] = "
\n
%s
Server: %s %s %shttp://dhcpserver.sourceforge.net/
"; + "align=\"left\">Server: %s %s %s
"; //const char htmlStart[] = "\n\n%s\n\n\n"; //const char bodyStart[] = "
%s
http://dhcp-dns-server.sourceforge.net/
"; @@ -253,7 +251,7 @@ int dhcpd_main(int daemon, const char *pInifile, const char *pStatusFile, const { while (fgets(tempbuff, sizeof(tempbuff), p)) { - if (atoi(tempbuff) != getpid()) + if (STR2INT(tempbuff) != getpid()) { sprintf(logBuff, "Error: %s is already running, Pid = %s", ds, tempbuff); break; @@ -623,6 +621,8 @@ int dhcpd_main(int daemon, const char *pInifile, const char *pStatusFile, const if (cfig.dhcpReplConn.ready) { close(cfig.dhcpReplConn.sock); } + + return 0; } void closeConn() { @@ -675,7 +675,7 @@ void on_system_exit(void *p) { bool chkQu(char *query) { if (strlen(query) >= UCHAR_MAX) { - return 0; + return false; } while (true) { @@ -730,14 +730,181 @@ MYBYTE pUInt(void *raw, MYDWORD data) { return sizeof(MYDWORD); } +void prepareUserHtmlRespStatus(data19 *req) { + //debug("sendStatus"); + char ipbuff[16]; + char extbuff[16]; + char logBuff[512]; + char tempbuff[512]; + + dhcpMap::iterator p; + MYDWORD iip = 0; + data7 *dhcpEntry = nullptr; + //data7 *cache = nullptr; + //printf("%d=%d\n", dhcpCache.size(), cfig.dhcpSize); + 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); + //tm *ttm = gmtime(&t); + //strftime(tempbuff, sizeof(tempbuff), "%a, %d %b %Y %H:%M:%S GMT", ttm); + //fp += sprintf(fp, send200, tempbuff, tempbuff); + //fp += sprintf(fp, send200); + //char *contentStart = fp; + fp += sprintf(fp, htmlStart, htmlTitle); + + if (cfig.replication == 1) { + fp += sprintf(fp, bodyStart, sVersion, cfig.servername, "(Primary)", MY_EXE_SIZE); + } else if (cfig.replication == 2) { + fp += sprintf(fp, bodyStart, sVersion, cfig.servername, "(Secondary)", MY_EXE_SIZE); + } else { + fp += sprintf(fp, bodyStart, sVersion, cfig.servername, "", MY_EXE_SIZE); + } + + fp += sprintf(fp, "\n\n"); + + if (cfig.dhcpRepl > t) { + fp += sprintf(fp, "\n"); + fp += sprintf(fp, + "\n"); + } else { + fp += sprintf(fp, "\n"); + fp += sprintf( + fp, + "\n"); + } + + for (p = dhcpCache.begin(); kRunning && p != dhcpCache.end() && fp < maxData; p++) { + //if ((dhcpEntry = p->second) && dhcpEntry->display) + if ((dhcpEntry = p->second) && dhcpEntry->display && dhcpEntry->expiry >= t) { + fp += sprintf(fp, ""); + fp += sprintf(fp, td200, dhcpEntry->mapname); // mapname is MAC address + fp += sprintf(fp, td200, IP2String(tempbuff, dhcpEntry->ip)); + + if (dhcpEntry->expiry >= MY_MAX_TIME) { + fp += sprintf(fp, td200, "Infinity"); + } else { + tm *ttm = localtime(&dhcpEntry->expiry); + strftime(tempbuff, sizeof(tempbuff), "%d-%b-%y %X", ttm); + fp += sprintf(fp, tdnowrap200, tempbuff); + } + + if (dhcpEntry->hostname[0]) { + strcpy(tempbuff, dhcpEntry->hostname); + tempbuff[20] = 0; + fp += sprintf(fp, td200, tempbuff); + } else { + fp += sprintf(fp, td200, " "); + } + + if (cfig.dhcpRepl > t) { + if (dhcpEntry->local && cfig.replication == 1) { + fp += sprintf(fp, td200, "Primary"); + } else if (dhcpEntry->local && cfig.replication == 2) { + fp += sprintf(fp, td200, "Secondary"); + } else if (cfig.replication == 1) { + fp += sprintf(fp, td200, "Secondary"); + } else { + fp += sprintf(fp, td200, "Primary"); + } + } + + fp += sprintf(fp, "\n"); + } + } + + fp += sprintf(fp, "
Active Leases
Mac AddressIPLease ExpiryHostname (first 20 " + "chars)Server
Active Leases
Mac AddressIPLease ExpiryHostname (first 20 chars)
\n
\n\n"); + fp += sprintf(fp, "\n"); + fp += sprintf(fp, + "\n"); + + for (char rangeInd = 0; kRunning && rangeInd < cfig.rangeCount && fp < maxData; rangeInd++) { + MYWORD ipused = 0; + MYWORD ipfree = 0; + MYWORD ind = 0; + + for (MYDWORD ip = cfig.dhcpRanges[rangeInd].rangeStart; ip <= cfig.dhcpRanges[rangeInd].rangeEnd; ip++, ind++) { + if (cfig.dhcpRanges[rangeInd].expiry[ind] != MY_MAX_TIME) { + if (cfig.dhcpRanges[rangeInd].expiry[ind] < t) { + ipfree++; + } else { + ipused++; + } + } + } + + IP2String(tempbuff, ntohl(cfig.dhcpRanges[rangeInd].rangeStart)); + IP2String(ipbuff, ntohl(cfig.dhcpRanges[rangeInd].rangeEnd)); + IP2String(extbuff, cfig.dhcpRanges[rangeInd].mask); + fp += sprintf(fp, + "\n", + tempbuff, + ipbuff, + extbuff, + (ipused + ipfree), + ipfree); + } + + fp += sprintf(fp, "
Free Dynamic Leases
DHCP RangeMaskAvailable " + "LeasesFree Leases
%s - %s%s%i%i
\n
\n\n"); + fp += sprintf(fp, "\n"); + fp += sprintf(fp, "\n"); + + MYBYTE colNum = 0; + + for (p = dhcpCache.begin(); kRunning && p != dhcpCache.end() && fp < maxData; p++) { + if ((dhcpEntry = p->second) && dhcpEntry->fixed && dhcpEntry->expiry < t) { + if (!colNum) { + fp += sprintf(fp, ""); + colNum = 1; + } else if (colNum == 1) { + colNum = 2; + } else if (colNum == 2) { + fp += sprintf(fp, "\n"); + colNum = 1; + } + + fp += sprintf(fp, td200, dhcpEntry->mapname); + fp += sprintf(fp, td200, IP2String(tempbuff, dhcpEntry->ip)); + } + } + + if (colNum) { + fp += sprintf(fp, "\n"); + } + + fp += sprintf(fp, "
Free Static Leases
Mac AddressIPMac AddressIP
\n\n"); + //MYBYTE x = sprintf(tempbuff, "%u", (fp - contentStart)); + //memcpy((contentStart - 12), tempbuff, x); + 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 procHTTP(data19 *req) { +#if 0 char logBuff[256]; char tempbuff[512]; req->ling.l_onoff = 1; //0 = off (l_linger ignored), nonzero = on req->ling.l_linger = 30; //0 = discard data, nonzero = wait for data sent setsockopt(req->sock, SOL_SOCKET, SO_LINGER, (const char *)&req->ling, sizeof(req->ling)); - timeval tv1; + timeval tv1 {}; fd_set readfds1; FD_ZERO(&readfds1); tv1.tv_sec = 1; @@ -753,7 +920,7 @@ void procHTTP(data19 *req) { } char buffer[2048]; - req->bytes = recv(req->sock, buffer, sizeof(buffer), 0); + req->bytes = (int)recv(req->sock, buffer, sizeof(buffer), 0); //errno = WSAGetLastError(); if ((verbatim || cfig.dhcpLogLevel >= 1) && (errno || req->bytes <= 0)) { @@ -832,8 +999,9 @@ void procHTTP(data19 *req) { pthread_attr_destroy(&attr); return; } +#endif } - +#if 0 void sendStatus(data19 *req) { char ipbuff[16]; char extbuff[16]; @@ -940,8 +1108,7 @@ void sendStatus(data19 *req) { MYWORD ipfree = 0; MYWORD ind = 0; - for (MYDWORD iip = cfig.dhcpRanges[rangeInd].rangeStart; iip <= cfig.dhcpRanges[rangeInd].rangeEnd; - iip++, ind++) { + for (MYDWORD i = cfig.dhcpRanges[rangeInd].rangeStart; i <= cfig.dhcpRanges[rangeInd].rangeEnd; i++, ind++) { if (cfig.dhcpRanges[rangeInd].expiry[ind] != MY_MAX_TIME) { if (cfig.dhcpRanges[rangeInd].expiry[ind] < t) { ipfree++; @@ -1004,7 +1171,7 @@ void sendStatus(data19 *req) { pthread_attr_destroy(&attr); return; } - +#endif /* void sendScopeStatus(data19 *req) { @@ -1069,13 +1236,13 @@ void sendScopeStatus(data19 *req) */ void *sendHTTP(void *lpParam) { - data19 *req = (data19 *)lpParam; + auto *req = (data19 *)lpParam; //char logBuff[512]; //sprintf(logBuff, "sendHTTP memsize=%d bytes=%d", req->memSize, req->bytes); char *dp = req->dp; - timeval tv1; + timeval tv1 {}; fd_set writefds1; int sent = 0; bool sendheader = true; @@ -1093,9 +1260,9 @@ void *sendHTTP(void *lpParam) { send(req->sock, header, strlen(header), 0); sendheader = false; } else if (req->bytes > 1024) { - sent = send(req->sock, dp, 1024, 0); + sent = (int)send(req->sock, dp, 1024, 0); } else if (req->bytes > 0) { - sent = send(req->sock, dp, req->bytes, 0); + sent = (int)send(req->sock, dp, req->bytes, 0); } else { break; } @@ -1153,7 +1320,7 @@ bool checkIP(data9 *req, data17 *rangeData, MYDWORD ip) { MYDWORD rangeStart; MYDWORD rangeEnd; - char rangeInd = getRangeInd(ip); + char rangeInd = (char)(getRangeInd(ip) & 0xFF); if (rangeInd < 0) { return false; @@ -1241,7 +1408,7 @@ MYDWORD resad(data9 *req) { MYDWORD iipNew = 0; MYDWORD iipExp = 0; bool rangeFound = false; - data17 rangeData; + data17 rangeData {}; memset(&rangeData, 0, sizeof(data17)); if (cfig.hasFilter) { @@ -1337,7 +1504,7 @@ MYDWORD resad(data9 *req) { if (cfig.replication == 2) { for (MYDWORD m = rangeEnd; m >= rangeStart; m--) { - int ind = m - range->rangeStart; + unsigned int ind = m - range->rangeStart; if (!range->expiry[ind]) { iipNew = m; @@ -1348,7 +1515,7 @@ MYDWORD resad(data9 *req) { } } else { for (MYDWORD m = rangeStart; m <= rangeEnd; m++) { - int ind = m - range->rangeStart; + unsigned int ind = m - range->rangeStart; //sprintf(logBuff, "Ind=%u Exp=%u", m, range->expiry[ind]); //logDHCPMess(logBuff, 1); @@ -1452,10 +1619,10 @@ MYDWORD chkaddr(data9 *req) { MYDWORD rangeEnd = 0; if (req->dhcpEntry->rangeInd >= 0) { - data17 rangeData; + data17 rangeData {}; memset(&rangeData, 0, sizeof(data17)); data13 *range = &cfig.dhcpRanges[req->dhcpEntry->rangeInd]; - int ind = getIndex(req->dhcpEntry->rangeInd, req->dhcpEntry->ip); + int ind = getIndex((char)req->dhcpEntry->rangeInd, req->dhcpEntry->ip); bool rangeOK = true; if (cfig.hasFilter) { @@ -1701,7 +1868,7 @@ MYDWORD sdmess(data9 *req) { } addOptions(req); - int packSize = req->vp - (MYBYTE *)&req->dhcpp; + int packSize = (int)(req->vp - (MYBYTE *)&req->dhcpp); packSize++; if (req->req_type == DHCP_MESS_NONE) { @@ -1732,20 +1899,18 @@ MYDWORD sdmess(data9 *req) { req->dhcpp.header.bp_op = BOOTP_REPLY; errno = 0; + sockaddr_in cliAddr = get_cliAddr(nicif, tempbuff, req); + if (req->req_type == DHCP_MESS_DISCOVER && !req->remote.sin_addr.s_addr) { - req->bytes = sendto(network.dhcpConn[req->sockInd].sock, - req->raw, - packSize, - MSG_DONTROUTE, - (sockaddr *)&req->remote, - sizeof(req->remote)); + req->bytes = (int)sendto(network.dhcpConn[req->sockInd].sock, + req->raw, + packSize, + MSG_DONTROUTE, + (sockaddr *)&cliAddr, + sizeof(cliAddr)); } else { - req->bytes = sendto(network.dhcpConn[req->sockInd].sock, - req->raw, - packSize, - 0, - (sockaddr *)&req->remote, - sizeof(req->remote)); + req->bytes = (int) + sendto(network.dhcpConn[req->sockInd].sock, req->raw, packSize, 0, (sockaddr *)&cliAddr, sizeof(cliAddr)); } if (errno || req->bytes <= 0) { @@ -1826,7 +1991,7 @@ MYDWORD alad(data9 *req) { void addOptions(data9 *req) { //debug("addOptions"); - data3 op; + data3 op {}; int i; if (req->req_type && req->resp_type) { @@ -2009,7 +2174,7 @@ void setTempLease(data7 *dhcpEntry) { dhcpEntry->local = false; dhcpEntry->expiry = t + 20; - int ind = getIndex(dhcpEntry->rangeInd, dhcpEntry->ip); + int ind = getIndex((char)dhcpEntry->rangeInd, dhcpEntry->ip); if (ind >= 0) { if (cfig.dhcpRanges[dhcpEntry->rangeInd].expiry[ind] != INT_MAX) { @@ -2030,7 +2195,7 @@ void setLeaseExpiry(data7 *dhcpEntry, MYDWORD lease) { dhcpEntry->expiry = t + lease; } - int ind = getIndex(dhcpEntry->rangeInd, dhcpEntry->ip); + int ind = getIndex((char)dhcpEntry->rangeInd, dhcpEntry->ip); if (ind >= 0) { if (cfig.dhcpRanges[dhcpEntry->rangeInd].expiry[ind] != INT_MAX) { @@ -2044,7 +2209,7 @@ void setLeaseExpiry(data7 *dhcpEntry, MYDWORD lease) { void setLeaseExpiry(data7 *dhcpEntry) { if (dhcpEntry && dhcpEntry->ip) { - int ind = getIndex(dhcpEntry->rangeInd, dhcpEntry->ip); + int ind = getIndex((char)dhcpEntry->rangeInd, dhcpEntry->ip); if (ind >= 0) { if (cfig.dhcpRanges[dhcpEntry->rangeInd].expiry[ind] != INT_MAX) { @@ -2062,7 +2227,7 @@ void lockIP(MYDWORD ip) { for (char rangeInd = 0; rangeInd < cfig.rangeCount; rangeInd++) { if (iip >= cfig.dhcpRanges[rangeInd].rangeStart && iip <= cfig.dhcpRanges[rangeInd].rangeEnd) { - int ind = iip - cfig.dhcpRanges[rangeInd].rangeStart; + unsigned int ind = iip - cfig.dhcpRanges[rangeInd].rangeStart; if (cfig.dhcpRanges[rangeInd].expiry[ind] != INT_MAX) { cfig.dhcpRanges[rangeInd].expiry[ind] = INT_MAX; @@ -2080,7 +2245,7 @@ void holdIP(MYDWORD ip) { for (char rangeInd = 0; rangeInd < cfig.rangeCount; rangeInd++) { if (iip >= cfig.dhcpRanges[rangeInd].rangeStart && iip <= cfig.dhcpRanges[rangeInd].rangeEnd) { - int ind = iip - cfig.dhcpRanges[rangeInd].rangeStart; + unsigned int ind = iip - cfig.dhcpRanges[rangeInd].rangeStart; if (cfig.dhcpRanges[rangeInd].expiry[ind] == 0) { cfig.dhcpRanges[rangeInd].expiry[ind] = 1; @@ -2116,7 +2281,7 @@ void *sendToken(void *lpParam) { MYDWORD sendRepl(data9 *req) { char logBuff[256]; char ipbuff[32]; - data3 op; + data3 op {}; MYBYTE *opPointer = req->dhcpp.vend_data; @@ -2149,17 +2314,13 @@ MYDWORD sendRepl(data9 *req) { *(req->vp) = DHCP_OPTION_END; req->vp++; - req->bytes = req->vp - (MYBYTE *)req->raw; + req->bytes = (int)(req->vp - (MYBYTE *)req->raw); req->dhcpp.header.bp_op = BOOTP_REQUEST; errno = 0; - req->bytes = sendto(cfig.dhcpReplConn.sock, - req->raw, - req->bytes, - 0, - (sockaddr *)&token.remote, - sizeof(token.remote)); + req->bytes = (int) + sendto(cfig.dhcpReplConn.sock, req->raw, req->bytes, 0, (sockaddr *)&token.remote, sizeof(token.remote)); //errno = WSAGetLastError(); @@ -2238,10 +2399,10 @@ void recvRepl(data9 *req) { return; } - char rInd = getRangeInd(ip); + int rInd = getRangeInd(ip); if (rInd >= 0) { - int ind = getIndex(rInd, ip); + int ind = getIndex((char)rInd, ip); req->dhcpEntry = cfig.dhcpRanges[rInd].dhcpEntry[ind]; if (req->dhcpEntry && !req->dhcpEntry->fixed && strcasecmp(req->dhcpEntry->mapname, req->chaddr)) { @@ -2268,10 +2429,10 @@ void recvRepl(data9 *req) { logDHCPMess(logBuff, 1); return; } else if (req->dhcpEntry->rangeInd >= 0) { - int ind = getIndex(req->dhcpEntry->rangeInd, req->dhcpEntry->ip); + int ind = getIndex((char)req->dhcpEntry->rangeInd, req->dhcpEntry->ip); if (ind >= 0) { - cfig.dhcpRanges[req->dhcpEntry->rangeInd].dhcpEntry[ind] = 0; + cfig.dhcpRanges[req->dhcpEntry->rangeInd].dhcpEntry[ind] = nullptr; } } } @@ -2359,7 +2520,7 @@ void recvRepl(data9 *req) { } } -char getRangeInd(MYDWORD ip) { +int getRangeInd(MYDWORD ip) { if (ip) { MYDWORD iip = htonl(ip); @@ -2376,7 +2537,7 @@ int getIndex(char rangeInd, MYDWORD ip) { if (ip && rangeInd >= 0 && rangeInd < cfig.rangeCount) { MYDWORD iip = htonl(ip); if (iip >= cfig.dhcpRanges[rangeInd].rangeStart && iip <= cfig.dhcpRanges[rangeInd].rangeEnd) { - return (iip - cfig.dhcpRanges[rangeInd].rangeStart); + return (int)(iip - cfig.dhcpRanges[rangeInd].rangeStart); } } return -1; @@ -2483,9 +2644,9 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) { } else { memcpy(value, hoption, valSize); } - } else if (isInt(value) && atol(value) > USHRT_MAX) { + } else if (isInt(value) && strtol(value, nullptr, 10) > USHRT_MAX) { valType = 4; - } else if (isInt(value) && atoi(value) > UCHAR_MAX) { + } else if (isInt(value) && STR2INT(value) > UCHAR_MAX) { valType = 5; } else if (isInt(value)) { valType = 6; @@ -2504,8 +2665,8 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) { for (; *ptr; ptr = myGetToken(ptr, 1)) { //printf("%s:", ptr); - if (isInt(ptr) && atoi(ptr) <= UCHAR_MAX) { - hoption[valSize] = atoi(ptr); + if (isInt(ptr) && STR2INT(ptr) <= UCHAR_MAX) { + hoption[valSize] = STR2INT(ptr); valSize++; } else { break; @@ -2558,7 +2719,7 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) { logDHCPMess(logBuff, 1); } else if (!strcasecmp(sectionName, RANGESET)) { addServer(cfig.rangeSet[optionData->rangeSetInd].subnetIP, MAX_RANGE_FILTERS, fIP(value)); - cfig.hasFilter = 1; + cfig.hasFilter = true; } else { sprintf(logBuff, "Warning: section [%s] option %s not allowed in this section, option ignored", @@ -2587,13 +2748,13 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) { opTag = 0; if (isInt(name)) { - if (atoi(name) < 1 || atoi(name) >= 254) { + if (STR2INT(name) < 1 || STR2INT(name) >= 254) { sprintf(logBuff, "Warning: section [%s] invalid option %s, ignored", sectionName, raw); logDHCPMess(logBuff, 1); continue; } - opTag = atoi(name); + opTag = STR2INT(name); opType = 0; } @@ -2737,7 +2898,7 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) { if (valType == 2 && valSize == 4) { j = fULong(value); } else if (valType >= 4 && valType <= 6) { - j = atol(value); + j = strtol(value, nullptr, 10); } else { sprintf(logBuff, "Warning: section [%s] option %s, value should be integer between 0 & %u or 4 bytes, " @@ -2798,7 +2959,7 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) { if (valType == 2 && valSize == 2) { j = fUShort(value); } else if (valType == 5 || valType == 6) { - j = atol(value); + j = strtol(value, nullptr, 10); } else { sprintf( logBuff, @@ -2829,7 +2990,7 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) { if (valType == 2 && valSize == 1) { j = *value; } else if (valType == 6) { - j = atol(value); + j = strtol(value, nullptr, 10); } else { sprintf(logBuff, "Warning: section [%s] option %s, value should be between 0 & %u or single byte, option " @@ -2866,8 +3027,8 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) { } else if (valType == 1 && (!strcasecmp(value, "no") || !strcasecmp(value, "off") || !strcasecmp(value, "false"))) { j = 0; - } else if (valType == 6 && atoi(value) < 2) { - j = atoi(value); + } else if (valType == 6 && STR2INT(value) < 2) { + j = STR2INT(value); } else { sprintf(logBuff, "Warning: section [%s] option %s, value should be yes/on/true/1 or no/off/false/0, option " @@ -2896,7 +3057,7 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) { if (valType == 6) { valType = 2; valSize = 1; - *value = atoi(value); + *value = STR2INT(value); } if (opType == 2 && valType != 2) { @@ -2951,7 +3112,7 @@ void lockOptions(FILE *f) { for (op_index = 0; op_index < n; op_index++) { if (!strcasecmp(name, opData[op_index].opName) || - (opData[op_index].opTag && atoi(name) == opData[op_index].opTag)) { + (opData[op_index].opTag && STR2INT(name) == opData[op_index].opTag)) { break; } } @@ -2969,8 +3130,8 @@ void lockOptions(FILE *f) { for (; *ptr; ptr = myGetToken(ptr, 1)) { if (valueSize >= UCHAR_MAX) { break; - } else if (isInt(ptr) && atoi(ptr) <= UCHAR_MAX) { - hoption[valueSize] = atoi(ptr); + } else if (isInt(ptr) && STR2INT(ptr) <= UCHAR_MAX) { + hoption[valueSize] = STR2INT(ptr); valueSize++; } else { break; @@ -3032,9 +3193,7 @@ int addDHCPRange(char *dp) { range->rangeStart = rs; range->rangeEnd = re; range->expiry = (time_t *)calloc((re - rs + 1), sizeof(time_t)); - memset(range->expiry, (re - rs + 1) * sizeof(time_t), 0); - range->dhcpEntry = (data7 **)calloc((re - rs + 1), sizeof(data7 *)); - memset(range->dhcpEntry, (re - rs + 1) * sizeof(data7 *), 0); + range->dhcpEntry = (data7 **)calloc((re - rs + 1), sizeof(data7 *)); if (!range->expiry || !range->dhcpEntry) { if (range->expiry) { @@ -3143,10 +3302,10 @@ void addMacRange(MYBYTE rangeSetInd, char *macRange) { sprintf(logBuff, "Section [%s], invalid Filter_Mac_Range %s, ignored", RANGESET, macRange); logDHCPMess(logBuff, 1); } else { - MYBYTE macSize1 = 16; - MYBYTE macSize2 = 16; - MYBYTE *macStart = (MYBYTE *)calloc(1, macSize1); - MYBYTE *macEnd = (MYBYTE *)calloc(1, macSize2); + MYBYTE macSize1 = 16; + MYBYTE macSize2 = 16; + auto *macStart = (MYBYTE *)calloc(1, macSize1); + auto *macEnd = (MYBYTE *)calloc(1, macSize2); if (!macStart || !macEnd) { sprintf(logBuff, "DHCP Range Load, Memory Allocation Error"); @@ -3187,13 +3346,13 @@ void loadDHCP() { char ipbuff[32]; char logBuff[512]; data7 *dhcpEntry = nullptr; - data8 dhcpData; + data8 dhcpData {}; char mapname[64]; FILE *f = nullptr; FILE *ff = nullptr; - if (f = openSection(GLOBALOPTIONS, 1)) { - data20 optionData; + if ((f = openSection(GLOBALOPTIONS, 1))) { + data20 optionData {}; loadOptions(f, GLOBALOPTIONS, &optionData); cfig.options = (MYBYTE *)calloc(1, optionData.optionSize); memcpy(cfig.options, optionData.options, optionData.optionSize); @@ -3204,10 +3363,13 @@ void loadDHCP() { cfig.mask = inet_addr("255.255.255.0"); } +#if 1 + opendhcp_add_ip_pool_set(); +#else for (MYBYTE i = 1; i <= MAX_RANGE_SETS; i++) { - if (f = openSection(RANGESET, i)) { + if ((f = openSection(RANGESET, i))) { MYBYTE m = cfig.rangeCount; - data20 optionData; + data20 optionData {}; optionData.rangeSetInd = i - 1; loadOptions(f, RANGESET, &optionData); MYBYTE *options = nullptr; @@ -3223,12 +3385,12 @@ void loadDHCP() { cfig.dhcpRanges[m].options = options; cfig.dhcpRanges[m].mask = optionData.mask; } - cfig.rangeCount = m; + cfig.rangeCount = (char)m; } else { break; } } - +#endif //printf("%s\n", IP2String(ipbuff, cfig.mask)); for (char rangeInd = 0; rangeInd < cfig.rangeCount; rangeInd++) { @@ -3246,12 +3408,12 @@ void loadDHCP() { } } - if (f = openSection(GLOBALOPTIONS, 1)) { + if ((f = openSection(GLOBALOPTIONS, 1))) { lockOptions(f); } for (MYBYTE i = 1; i <= MAX_RANGE_SETS; i++) { - if (f = openSection(RANGESET, i)) { + if ((f = openSection(RANGESET, i))) { lockOptions(f); } else { break; @@ -3259,7 +3421,9 @@ void loadDHCP() { } ff = fopen(iniFile, "rt"); - +#if 1 + opendhcp_add_mac_filter(); +#else if (ff) { char sectionName[512]; @@ -3286,21 +3450,21 @@ void loadDHCP() { MYBYTE hexValue[UCHAR_MAX]; MYBYTE hexValueSize = sizeof(hexValue); - data20 optionData; + data20 optionData {}; if (strlen(sectionName) <= 48 && !getHexValue(hexValue, sectionName, &hexValueSize)) { if (hexValueSize <= 16) { dhcpEntry = findDHCPEntry(hex2String(mapname, hexValue, hexValueSize)); if (!dhcpEntry) { - if (f = openSection(sectionName, 1)) { + if ((f = openSection(sectionName, 1))) { loadOptions(f, sectionName, &optionData); } - if (f = openSection(sectionName, 1)) { + if ((f = openSection(sectionName, 1))) { lockOptions(f); } - dhcpMap::iterator p = dhcpCache.begin(); + auto p = dhcpCache.begin(); for (; p != dhcpCache.end(); p++) { if (p->second && p->second->ip && p->second->ip == optionData.ip) { @@ -3356,13 +3520,13 @@ void loadDHCP() { fclose(ff); } - +#endif f = fopen(leaFile, "rb"); if (f) { while (fread(&dhcpData, sizeof(data8), 1, f)) { - char rangeInd = -1; - int ind = -1; + int rangeInd = -1; + int ind = -1; //sprintf(logBuff, "Loading %s=%s", dhcpData.hostname, IP2String(ipbuff, dhcpData.ip)); //logDHCPMess(logBuff, 1); @@ -3370,7 +3534,7 @@ void loadDHCP() { !findServer(network.allServers, MAX_SERVERS, dhcpData.ip)) { hex2String(mapname, dhcpData.bp_chaddr, dhcpData.bp_hlen); - dhcpMap::iterator p = dhcpCache.begin(); + auto p = dhcpCache.begin(); for (; p != dhcpCache.end(); p++) { dhcpEntry = p->second; @@ -3417,7 +3581,7 @@ void loadDHCP() { f = fopen(leaFile, "rb+"); if (f) { - dhcpMap::iterator p = dhcpCache.begin(); + auto p = dhcpCache.begin(); for (; p != dhcpCache.end(); p++) { if ((dhcpEntry = p->second) && dhcpEntry->expiry > (t - 31 * 24 * 3600)) { @@ -3434,7 +3598,7 @@ void loadDHCP() { dhcpEntry->dhcpInd = cfig.dhcpInd; dhcpData.dhcpInd = dhcpEntry->dhcpInd; - if (fseek(f, (dhcpData.dhcpInd - 1) * sizeof(data8), SEEK_SET) >= 0) { + if (fseek(f, (long)((dhcpData.dhcpInd - 1) * sizeof(data8)), SEEK_SET) >= 0) { fwrite(&dhcpData, sizeof(data8), 1, f); } } @@ -3443,7 +3607,7 @@ void loadDHCP() { fclose(f); } } - +#if 0 bool getSection(const char *sectionName, char *buffer, MYBYTE serial, char *fileName) { //printf("%s=%s\n",fileName,sectionName); char section[128]; @@ -3486,6 +3650,7 @@ bool getSection(const char *sectionName, char *buffer, MYBYTE serial, char *file *(buffer + 1) = 0; return (found == serial); } +#endif FILE *openSection(const char *sectionName, MYBYTE serial) { char logBuff[256]; @@ -3641,7 +3806,7 @@ char *myTrim(char *target, char *source) { return target; } -void mySplit(char *name, char *value, char *source, char splitChar) { +void mySplit(char *name, char *value, const char *source, char splitChar) { int i = 0; int j = 0; int k = 0; @@ -3666,7 +3831,7 @@ void mySplit(char *name, char *value, char *source, char splitChar) { } MYDWORD getClassNetwork(MYDWORD ip) { - data15 data; + data15 data {}; data.ip = ip; data.octate[3] = 0; @@ -3701,9 +3866,9 @@ return tempbuff; char *IP2String(char *target, MYDWORD ip, MYBYTE dnsType) { char *dp = target; - (*dp) = dnsType; + (*dp) = (char)dnsType; dp++; - data15 inaddr; + data15 inaddr {}; inaddr.ip = ip; sprintf(dp, "%u.%u.%u.%u", inaddr.octate[0], inaddr.octate[1], inaddr.octate[2], inaddr.octate[3]); //MYBYTE *octate = (MYBYTE*)&ip; @@ -3712,7 +3877,7 @@ char *IP2String(char *target, MYDWORD ip, MYBYTE dnsType) { } char *IP2String(char *target, MYDWORD ip) { - data15 inaddr; + data15 inaddr {}; inaddr.ip = ip; sprintf(target, "%u.%u.%u.%u", inaddr.octate[0], inaddr.octate[1], inaddr.octate[2], inaddr.octate[3]); //MYBYTE *octate = (MYBYTE*)&ip; @@ -3952,7 +4117,7 @@ MYBYTE fromUUE(MYBYTE *target, char *source) return bp_hlen; } */ -char *hex2String(char *target, MYBYTE *hex, MYBYTE bytes) { +char *hex2String(char *target, const MYBYTE *hex, MYBYTE bytes) { char *dp = target; if (bytes) { @@ -3968,7 +4133,7 @@ char *hex2String(char *target, MYBYTE *hex, MYBYTE bytes) { return target; } -char *genHostName(char *target, MYBYTE *hex, MYBYTE bytes) { +char *genHostName(char *target, const MYBYTE *hex, MYBYTE bytes) { char *dp = target; if (bytes) { @@ -4105,7 +4270,7 @@ char *myUpper(char *string) { MYWORD len = strlen(string); for (int i = 0; i < len; i++) { if (string[i] >= 'a' && string[i] <= 'z') { - string[i] -= diff; + string[i] = (char)(string[i] - diff); } } return string; @@ -4116,7 +4281,7 @@ char *myLower(char *string) { MYWORD len = strlen(string); for (int i = 0; i < len; i++) { if (string[i] >= 'A' && string[i] <= 'Z') { - string[i] += diff; + string[i] = (char)(string[i] + diff); } } return string; @@ -4130,7 +4295,7 @@ bool wildcmp(char *string, char *wild) { while ((*string) && (*wild != '*')) { if ((*wild != *string) && (*wild != '?')) { - return 0; + return false; } wild++; string++; @@ -4139,7 +4304,7 @@ bool wildcmp(char *string, char *wild) { while (*string) { if (*wild == '*') { if (!*++wild) { - return 1; + return true; } mp = wild; @@ -4173,7 +4338,7 @@ bool isLocal(MYDWORD ip) { char *setMapName(char *tempbuff, char *mapname, MYBYTE dnsType) { char *dp = tempbuff; - (*dp) = dnsType; + (*dp) = (char)dnsType; dp++; strcpy(dp, mapname); myLower(dp); @@ -4181,9 +4346,9 @@ char *setMapName(char *tempbuff, char *mapname, MYBYTE dnsType) { } void listDhcpCache() { - char logBuff[256]; - dhcpMap::iterator p = dhcpCache.begin(); - data7 *cache = nullptr; + char logBuff[256]; + auto p = dhcpCache.begin(); + data7 *cache = nullptr; while (p != dhcpCache.end()) { cache = p->second; @@ -4211,45 +4376,10 @@ bool checkMask(MYDWORD mask) { return true; } -MYDWORD calcMask(MYDWORD rangeStart, MYDWORD rangeEnd) { - data15 ip1, ip2, mask; - - ip1.ip = htonl(rangeStart); - ip2.ip = htonl(rangeEnd); - - for (MYBYTE i = 0; i < 4; i++) { - mask.octate[i] = ip1.octate[i] ^ ip2.octate[i]; - - if (i && mask.octate[i - 1] < 255) { - mask.octate[i] = 0; - } else if (mask.octate[i] == 0) { - mask.octate[i] = 255; - } else if (mask.octate[i] < 2) { - mask.octate[i] = 254; - } else if (mask.octate[i] < 4) { - mask.octate[i] = 252; - } else if (mask.octate[i] < 8) { - mask.octate[i] = 248; - } else if (mask.octate[i] < 16) { - mask.octate[i] = 240; - } else if (mask.octate[i] < 32) { - mask.octate[i] = 224; - } else if (mask.octate[i] < 64) { - mask.octate[i] = 192; - } else if (mask.octate[i] < 128) { - mask.octate[i] = 128; - } else { - mask.octate[i] = 0; - } - } - - return mask.ip; -} - data7 *findDHCPEntry(char *key) { //printf("finding %u=%s\n",ind,key); myLower(key); - dhcpMap::iterator it = dhcpCache.find(key); + auto it = dhcpCache.find(key); if (it != dhcpCache.end() && it->second) { return it->second; @@ -4299,12 +4429,16 @@ void *init(void *lparam) { sprintf(icoFile, "%s%s", filePATH, "opendhcp.png"); } - if (!logFile[0]) { - sprintf(logFile, "%s%s", filePATH, "log/opendhcp%Y%m%d.log"); - } - - if (f = openSection("LOGGING", 1)) { - cfig.dhcpLogLevel = 1; + // if (!logFile[0]) { + // sprintf(logFile, "%s%s", filePATH, "log/opendhcp%Y%m%d.log"); + // } +#if 1 + cfig.dhcpLogLevel = 2; + sprintf(logBuff, "%s Starting...", sVersion); + logDHCPMess(logBuff, 1); +#else + if ((f = openSection("LOGGING", 1))) { + cfig.dhcpLogLevel = 2; tempbuff[0] = 0; while (readSection(raw, f)) { @@ -4328,6 +4462,7 @@ void *init(void *lparam) { sprintf(tempbuff, "Section [LOGGING], Invalid Entry %s ignored", raw); } } + if (tempbuff[0]) { logDHCPMess(logBuff, 1); } @@ -4337,7 +4472,7 @@ void *init(void *lparam) { } else { printf("%s Starting...\n", sVersion); } - +#endif sleep(1); if ((f = fopen(iniFile, "rt"))) { @@ -4375,7 +4510,7 @@ void *init(void *lparam) { if (f) { if (cfig.dhcpLogLevel >= 2 || verbatim) { - logDHCPMess("icon file:", icoFile); + logDHCPMess(icoFile, 2); } fseek(f, 0, SEEK_END); @@ -4386,14 +4521,14 @@ void *init(void *lparam) { fclose(f); } - if (verbatim || cfig.dhcpLogLevel >= 1) { - logDHCPMess("exe file:", exeFile); - logDHCPMess("ini file:", iniFile); - logDHCPMess("log file:", logFile); - logDHCPMess("state file:", leaFile); - } + // if (verbatim || cfig.dhcpLogLevel >= 1) { + // logDHCPMess(exeFile, 2); + // logDHCPMess(iniFile, 2); + // logDHCPMess(logFile, 2); + // logDHCPMess(leaFile, 2); + // } - if (f = openSection("LISTEN_ON", 1)) { + if ((f = openSection("LISTEN_ON", 1))) { while (readSection(raw, f)) { if (isIP(raw)) { MYDWORD addr = inet_addr(raw); @@ -4405,7 +4540,10 @@ void *init(void *lparam) { } } - cfig.lease = 36000; + // 合并 vcpe.cfg 配置文件配置内容 + opendhcp_add_listener(); + + cfig.lease = opendhcp_set_lease_time(); cfig.fixedSocket = socket(AF_INET, SOCK_DGRAM, 0); @@ -4418,8 +4556,10 @@ void *init(void *lparam) { getInterfaces(&network); sprintf(cfig.servername_fqn, "%s.%s", cfig.servername, cfig.zone); - - if (f = openSection("REPLICATION_SERVERS", 1)) { +#if 1 + opendhcp_set_replication_svr(); +#else + if ((f = openSection("REPLICATION_SERVERS", 1))) { while (readSection(raw, f)) { mySplit(name, value, raw, '='); @@ -4443,7 +4583,7 @@ void *init(void *lparam) { } } } - +#endif if (!cfig.zoneServers[0] && cfig.zoneServers[1]) { sprintf(logBuff, "Section [REPLICATION_SERVERS] Missing Primary Server"); logDHCPMess(logBuff, 1); @@ -4515,7 +4655,7 @@ void *init(void *lparam) { cfig.dhcpReplConn.loaded = true; cfig.dhcpReplConn.ready = true; - data3 op; + data3 op {}; memset(&token, 0, sizeof(data9)); token.vp = token.dhcpp.vend_data; token.messsize = sizeof(dhcp_packet); @@ -4549,7 +4689,7 @@ void *init(void *lparam) { token.vp[0] = DHCP_OPTION_END; token.vp++; - token.bytes = token.vp - (MYBYTE *)token.raw; + token.bytes = (int)(token.vp - (MYBYTE *)token.raw); //if (cfig.replication == 2) // _beginthread(sendToken, 0, 0); @@ -4559,7 +4699,7 @@ void *init(void *lparam) { pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - int errcode = pthread_create(&threadId, &attr, sendToken, 0); + int errcode = pthread_create(&threadId, &attr, sendToken, nullptr); pthread_attr_destroy(&attr); } } @@ -4718,11 +4858,15 @@ void *init(void *lparam) { } } +#if 1 + network.httpConn.ready = false; + opendhcp_init_http_server(); +#else newNetwork.httpConn.port = 6789; newNetwork.httpConn.server = newNetwork.dhcpConn[0].server; newNetwork.httpConn.loaded = true; - if (f = openSection("HTTP_INTERFACE", 1)) { + if ((f = openSection("HTTP_INTERFACE", 1))) { while (readSection(raw, f)) { mySplit(name, value, raw, '='); @@ -4739,8 +4883,8 @@ void *init(void *lparam) { } if (value[0]) { - if (atoi(value)) { - newNetwork.httpConn.port = atoi(value); + if (STR2INT(value)) { + newNetwork.httpConn.port = STR2INT(value); } else { newNetwork.httpConn.loaded = false; sprintf(logBuff, "Warning: Section [HTTP_INTERFACE], Invalid port %s, ignored", value); @@ -4834,6 +4978,7 @@ void *init(void *lparam) { } } } +#endif for (MYBYTE m = 0; m < MAX_SERVERS && newNetwork.allServers[m]; m++) { lockIP(newNetwork.allServers[m]); @@ -4879,13 +5024,13 @@ void *init(void *lparam) { logDHCPMess(logBuff, 1); } - for (int i = 0; i < MAX_SERVERS && network.listenServers[i]; i++) { + for (int k = 0; k < MAX_SERVERS && network.listenServers[k]; k++) { for (MYBYTE j = 0; j < MAX_SERVERS; j++) { if (!network.dhcpConn[j].server && !network.dnsUdpConn[j].server) { break; - } else if (network.dhcpConn[j].server == network.listenServers[i] || - network.dnsUdpConn[j].server == network.listenServers[i]) { - sprintf(logBuff, "Listening On: %s", IP2String(ipbuff, network.listenServers[i])); + } else if (network.dhcpConn[j].server == network.listenServers[k] || + network.dnsUdpConn[j].server == network.listenServers[k]) { + sprintf(logBuff, "Listening On: %s", IP2String(ipbuff, network.listenServers[k])); logDHCPMess(logBuff, 1); break; } @@ -4941,10 +5086,12 @@ bool getInterfaces(data1 *pNetwork) { Ifc.ifc_buf = (char *)IfcBuf; if (ioctl(cfig.fixedSocket, SIOCGIFCONF, &Ifc) >= 0) { - MYDWORD addr, mask; - short flags; - struct ifreq pIfr; - MYBYTE numInterfaces = Ifc.ifc_len / sizeof(ifreq); + MYDWORD addr, mask; + short flags; + + struct ifreq pIfr {}; + + MYBYTE numInterfaces = Ifc.ifc_len / sizeof(ifreq); for (MYBYTE i = 0; i < numInterfaces; i++) { memcpy(&pIfr, &(IfcBuf[i]), sizeof(ifreq)); @@ -5070,8 +5217,8 @@ bool getInterfaces(data1 *pNetwork) { void *updateStateFile(void *lparam) { pthread_mutex_lock(&mutStateFile); - data7 *dhcpEntry = (data7 *)lparam; - data8 dhcpData; + auto *dhcpEntry = (data7 *)lparam; + data8 dhcpData {}; memset(&dhcpData, 0, sizeof(data8)); MYBYTE bp_hlen = 16; getHexValue(dhcpData.bp_chaddr, dhcpEntry->mapname, &bp_hlen); @@ -5091,7 +5238,7 @@ void *updateStateFile(void *lparam) { FILE *f = fopen(leaFile, "rb+"); if (f) { - if (fseek(f, (dhcpData.dhcpInd - 1) * sizeof(data8), SEEK_SET) >= 0) { + if (fseek(f, (long)((dhcpData.dhcpInd - 1) * sizeof(data8)), SEEK_SET) >= 0) { fwrite(&dhcpData, sizeof(data8), 1, f); } @@ -5114,6 +5261,7 @@ void debug(int i) { logDHCPMess(ts, 1); } +#if 0 void *logThread(void *lpParam) { pthread_mutex_lock(&mutLogFile); char *mess = (char *)lpParam; @@ -5183,6 +5331,7 @@ void logDHCPMess(const char *title, const char *mess) { sprintf(ts, "%s %s", title, mess); logDHCPMess(ts, 1); } +#endif MYWORD gdmess(data9 *req, MYBYTE sockInd) { char ipbuff[32]; @@ -5203,7 +5352,7 @@ MYWORD gdmess(data9 *req, MYBYTE sockInd) { req->msg.msg_flags = msgflags; int flags = 0; - req->bytes = recvmsg(network.dhcpListener.sock, &req->msg, flags); + req->bytes = (int)recvmsg(network.dhcpListener.sock, &req->msg, flags); if (errno || req->bytes <= 0) { return 0; @@ -5242,12 +5391,12 @@ MYWORD gdmess(data9 *req, MYBYTE sockInd) { req->sockInd = sockInd; req->sockLen = sizeof(req->remote); errno = 0; - req->bytes = recvfrom(network.dhcpConn[sockInd].sock, - req->raw, - sizeof(dhcp_packet), - 0, - (sockaddr *)&req->remote, - &req->sockLen); + req->bytes = (int)recvfrom(network.dhcpConn[sockInd].sock, + req->raw, + sizeof(dhcp_packet), + 0, + (sockaddr *)&req->remote, + &req->sockLen); if (errno || req->bytes <= 0) { return 0; @@ -5312,6 +5461,11 @@ MYWORD gdmess(data9 *req, MYBYTE sockInd) { case DHCP_OPTION_VENDORCLASSID: memcpy(&req->vendClass, op, op->size + 2); + if (op->size > 16) { + if (process_iptv_multicast(op->value, op->size, req->chaddr) == 0) { + return 0; + } + } break; case DHCP_OPTION_USERCLASS: @@ -5429,7 +5583,7 @@ MYWORD gdmess(data9 *req, MYBYTE sockInd) { data7 *createCache(data71 *pLump) { MYWORD dataSize = 70 + sizeof(data7) + strlen(pLump->mapname) + pLump->optionSize; - data7 *cache = (data7 *)calloc(1, dataSize); + auto *cache = (data7 *)calloc(1, dataSize); if (!cache) { return nullptr; diff --git a/srcs/opendhcp183/opendhcpd.h b/srcs/opendhcp183/opendhcpd.h index 3b1a97c..7b56605 100644 --- a/srcs/opendhcp183/opendhcpd.h +++ b/srcs/opendhcp183/opendhcpd.h @@ -76,6 +76,21 @@ typedef struct in_pktinfo IN_PKTINFO; #define STR2INT(val) ((int)strtol((val), nullptr, 10)) +#define logDHCPMess(logBuff, logLevel) \ + do { \ + switch ((logLevel)) { \ + case 2: \ + dzlog_debug("%s\n", logBuff); \ + break; \ + case 0: \ + dzlog_error("%s\n", logBuff); \ + break; \ + default: \ + dzlog_info("%s\n", logBuff); \ + break; \ + } \ + } while (0) + enum { CTYPE_NONE, CTYPE_DHCP_ENTRY, @@ -691,13 +706,13 @@ MYBYTE pInt(void *, MYDWORD); MYBYTE pUInt(void *raw, MYDWORD data); MYBYTE pUShort(void *, MYWORD); MYBYTE addServer(MYDWORD *, MYBYTE, MYDWORD); -char getRangeInd(MYDWORD); +int getRangeInd(MYDWORD); char *myTrim(char *, char *); char *myGetToken(char *, MYBYTE); char *cloneString(char *); char *getHexValue(MYBYTE *, char *, MYBYTE *); -char *genHostName(char *, MYBYTE *, MYBYTE); -char *hex2String(char *, MYBYTE *, MYBYTE); +char *genHostName(char *, const MYBYTE *, MYBYTE); +char *hex2String(char *, const MYBYTE *, MYBYTE); char *IP2String(char *, MYDWORD); char *IP2arpa(char *, MYDWORD); char *IP62String(char *, MYBYTE *); @@ -729,9 +744,7 @@ void getSecondary(); void *init(void *); void lockOptions(FILE *); void loadOptions(FILE *, const char *, data20 *); -void logDHCPMess(char *, MYBYTE); -void logDHCPMess(const char *title, const char *mess); -void mySplit(char *, char *, char *, char); +void mySplit(char *, char *, const char *, char); void *sendHTTP(void *); void procHTTP(data19 *); void pvdata(data9 *, data3 *);