fix(rpc): fix invalide fqdn
This commit is contained in:
parent
129819db97
commit
ce77983ff2
|
@ -26,7 +26,6 @@ typedef struct TdDirEntry {
|
|||
WIN32_FIND_DATA findFileData;
|
||||
} TdDirEntry;
|
||||
|
||||
|
||||
typedef struct TdDir {
|
||||
TdDirEntry dirEntry;
|
||||
HANDLE hFind;
|
||||
|
@ -78,14 +77,14 @@ void taosRemoveDir(const char *dirname) {
|
|||
taosRemoveDir(filename);
|
||||
} else {
|
||||
(void)taosRemoveFile(filename);
|
||||
//printf("file:%s is removed\n", filename);
|
||||
// printf("file:%s is removed\n", filename);
|
||||
}
|
||||
}
|
||||
|
||||
taosCloseDir(&pDir);
|
||||
rmdir(dirname);
|
||||
|
||||
//printf("dir:%s is removed\n", dirname);
|
||||
// printf("dir:%s is removed\n", dirname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -102,8 +101,8 @@ int32_t taosMkDir(const char *dirname) {
|
|||
|
||||
int32_t taosMulMkDir(const char *dirname) {
|
||||
if (dirname == NULL) return -1;
|
||||
char *temp = strdup(dirname);
|
||||
char *pos = temp;
|
||||
char * temp = strdup(dirname);
|
||||
char * pos = temp;
|
||||
int32_t code = 0;
|
||||
|
||||
if (strncmp(temp, "/", 1) == 0) {
|
||||
|
@ -112,7 +111,7 @@ int32_t taosMulMkDir(const char *dirname) {
|
|||
pos += 2;
|
||||
}
|
||||
|
||||
for ( ; *pos != '\0'; pos++) {
|
||||
for (; *pos != '\0'; pos++) {
|
||||
if (*pos == '/') {
|
||||
*pos = '\0';
|
||||
code = mkdir(temp, 0755);
|
||||
|
@ -173,9 +172,9 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
|
|||
int32_t days = (int32_t)(TABS(sec - fileSec) / 86400 + 1);
|
||||
if (days > keepDays) {
|
||||
(void)taosRemoveFile(filename);
|
||||
//printf("file:%s is removed, days:%d keepDays:%d", filename, days, keepDays);
|
||||
// printf("file:%s is removed, days:%d keepDays:%d", filename, days, keepDays);
|
||||
} else {
|
||||
//printf("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays);
|
||||
// printf("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +186,7 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
|
|||
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
|
||||
wordexp_t full_path;
|
||||
if (0 != wordexp(dirname, &full_path, 0)) {
|
||||
//printf("failed to expand path:%s since %s", dirname, strerror(errno));
|
||||
// printf("failed to expand path:%s since %s", dirname, strerror(errno));
|
||||
wordfree(&full_path);
|
||||
return -1;
|
||||
}
|
||||
|
@ -228,7 +227,7 @@ bool taosIsDir(const char *dirname) {
|
|||
return false;
|
||||
}
|
||||
|
||||
char* taosDirName(char *name) {
|
||||
char *taosDirName(char *name) {
|
||||
#ifdef WINDOWS
|
||||
char Drive1[MAX_PATH], Dir1[MAX_PATH];
|
||||
_splitpath(name, Drive1, Dir1, NULL, NULL);
|
||||
|
@ -242,13 +241,13 @@ char* taosDirName(char *name) {
|
|||
#endif
|
||||
}
|
||||
|
||||
char* taosDirEntryBaseName(char *name) {
|
||||
char *taosDirEntryBaseName(char *name) {
|
||||
#ifdef WINDOWS
|
||||
char Filename1[MAX_PATH], Ext1[MAX_PATH];
|
||||
_splitpath(name, NULL, NULL, Filename1, Ext1);
|
||||
return name + (strlen(name) - strlen(Filename1) - strlen(Ext1));
|
||||
#else
|
||||
return (char*)basename(name);
|
||||
return (char *)basename(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -275,7 +274,6 @@ TdDirPtr taosOpenDir(const char *dirname) {
|
|||
#else
|
||||
return (TdDirPtr)opendir(dirname);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
|
||||
|
@ -286,9 +284,9 @@ TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
|
|||
if (!FindNextFile(pDir->hFind, &(pDir->dirEntry.findFileData))) {
|
||||
return NULL;
|
||||
}
|
||||
return (TdDirEntryPtr)&(pDir->dirEntry.findFileData);
|
||||
return (TdDirEntryPtr) & (pDir->dirEntry.findFileData);
|
||||
#else
|
||||
return (TdDirEntryPtr)readdir((DIR*)pDir);
|
||||
return (TdDirEntryPtr)readdir((DIR *)pDir);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -299,18 +297,18 @@ bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) {
|
|||
#ifdef WINDOWS
|
||||
return (pDirEntry->findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
#else
|
||||
return (((dirent*)pDirEntry)->d_type & DT_DIR) != 0;
|
||||
return (((dirent *)pDirEntry)->d_type & DT_DIR) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
char* taosGetDirEntryName(TdDirEntryPtr pDirEntry) {
|
||||
char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) {
|
||||
if (pDirEntry == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
#ifdef WINDOWS
|
||||
return pDirEntry->findFileData.cFileName;
|
||||
#else
|
||||
return ((dirent*)pDirEntry)->d_name;
|
||||
return ((dirent *)pDirEntry)->d_name;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -324,7 +322,7 @@ int32_t taosCloseDir(TdDirPtr *ppDir) {
|
|||
*ppDir = NULL;
|
||||
return 0;
|
||||
#else
|
||||
closedir((DIR*)*ppDir);
|
||||
closedir((DIR *)*ppDir);
|
||||
*ppDir = NULL;
|
||||
return 0;
|
||||
#endif
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#else
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <net/if.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
|
@ -638,6 +639,72 @@ int32_t taosKeepTcpAlive(TdSocketPtr pSocket) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int taosGetLocalIp(const char *eth, char *ip) {
|
||||
#if defined(WINDOWS)
|
||||
// DO NOTHAING
|
||||
return 0;
|
||||
#else
|
||||
int fd;
|
||||
struct ifreq ifr;
|
||||
struct sockaddr_in sin;
|
||||
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (-1 == fd) {
|
||||
return -1;
|
||||
}
|
||||
strncpy(ifr.ifr_name, eth, IFNAMSIZ);
|
||||
ifr.ifr_name[IFNAMSIZ - 1] = 0;
|
||||
|
||||
if (ioctl(fd, SIOCGIFADDR, &ifr) < 0) {
|
||||
taosCloseSocketNoCheck1(fd);
|
||||
return -1;
|
||||
}
|
||||
memcpy(&sin, &ifr.ifr_addr, sizeof(sin));
|
||||
snprintf(ip, 64, "%s", inet_ntoa(sin.sin_addr));
|
||||
taosCloseSocketNoCheck1(fd);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
int taosValidIp(uint32_t ip) {
|
||||
#if defined(WINDOWS)
|
||||
// DO NOTHAING
|
||||
return 0;
|
||||
#else
|
||||
int ret = -1;
|
||||
int fd;
|
||||
|
||||
struct ifconf ifconf;
|
||||
|
||||
char buf[512] = {0};
|
||||
ifconf.ifc_len = 512;
|
||||
ifconf.ifc_buf = buf;
|
||||
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ioctl(fd, SIOCGIFCONF, &ifconf);
|
||||
struct ifreq *ifreq = (struct ifreq *)ifconf.ifc_buf;
|
||||
for (int i = (ifconf.ifc_len / sizeof(struct ifreq)); i > 0; i--) {
|
||||
char ip_str[64] = {0};
|
||||
if (ifreq->ifr_flags == AF_INET) {
|
||||
ret = taosGetLocalIp(ifreq->ifr_name, ip_str);
|
||||
if (ret != 0) {
|
||||
break;
|
||||
}
|
||||
ifreq++;
|
||||
}
|
||||
if (ip == (uint32_t)taosInetAddr(ip_str)) {
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
taosCloseSocketNoCheck1(fd);
|
||||
return ret;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
|
||||
struct sockaddr_in serverAdd;
|
||||
SocketFd fd;
|
||||
|
@ -677,13 +744,8 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
|
|||
taosCloseSocket(&pSocket);
|
||||
return false;
|
||||
}
|
||||
if (listen(pSocket->fd, 1024) < 0) {
|
||||
// printf("listen tcp server socket failed, 0x%x:%hu(%s)", ip, port, strerror(errno));
|
||||
taosCloseSocket(&pSocket);
|
||||
return false;
|
||||
}
|
||||
taosCloseSocket(&pSocket);
|
||||
return true;
|
||||
return 0 == taosValidIp(ip) ? true : false;
|
||||
}
|
||||
TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port) {
|
||||
struct sockaddr_in serverAdd;
|
||||
|
|
Loading…
Reference in New Issue