提交 ce77983f 编写于 作者: dengyihao's avatar dengyihao

fix(rpc): fix invalide fqdn

上级 129819db
...@@ -26,7 +26,6 @@ typedef struct TdDirEntry { ...@@ -26,7 +26,6 @@ typedef struct TdDirEntry {
WIN32_FIND_DATA findFileData; WIN32_FIND_DATA findFileData;
} TdDirEntry; } TdDirEntry;
typedef struct TdDir { typedef struct TdDir {
TdDirEntry dirEntry; TdDirEntry dirEntry;
HANDLE hFind; HANDLE hFind;
...@@ -78,14 +77,14 @@ void taosRemoveDir(const char *dirname) { ...@@ -78,14 +77,14 @@ void taosRemoveDir(const char *dirname) {
taosRemoveDir(filename); taosRemoveDir(filename);
} else { } else {
(void)taosRemoveFile(filename); (void)taosRemoveFile(filename);
//printf("file:%s is removed\n", filename); // printf("file:%s is removed\n", filename);
} }
} }
taosCloseDir(&pDir); taosCloseDir(&pDir);
rmdir(dirname); rmdir(dirname);
//printf("dir:%s is removed\n", dirname); // printf("dir:%s is removed\n", dirname);
return; return;
} }
...@@ -102,8 +101,8 @@ int32_t taosMkDir(const char *dirname) { ...@@ -102,8 +101,8 @@ int32_t taosMkDir(const char *dirname) {
int32_t taosMulMkDir(const char *dirname) { int32_t taosMulMkDir(const char *dirname) {
if (dirname == NULL) return -1; if (dirname == NULL) return -1;
char *temp = strdup(dirname); char * temp = strdup(dirname);
char *pos = temp; char * pos = temp;
int32_t code = 0; int32_t code = 0;
if (strncmp(temp, "/", 1) == 0) { if (strncmp(temp, "/", 1) == 0) {
...@@ -112,7 +111,7 @@ int32_t taosMulMkDir(const char *dirname) { ...@@ -112,7 +111,7 @@ int32_t taosMulMkDir(const char *dirname) {
pos += 2; pos += 2;
} }
for ( ; *pos != '\0'; pos++) { for (; *pos != '\0'; pos++) {
if (*pos == '/') { if (*pos == '/') {
*pos = '\0'; *pos = '\0';
code = mkdir(temp, 0755); code = mkdir(temp, 0755);
...@@ -173,9 +172,9 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) { ...@@ -173,9 +172,9 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
int32_t days = (int32_t)(TABS(sec - fileSec) / 86400 + 1); int32_t days = (int32_t)(TABS(sec - fileSec) / 86400 + 1);
if (days > keepDays) { if (days > keepDays) {
(void)taosRemoveFile(filename); (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 { } 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) { ...@@ -187,7 +186,7 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
wordexp_t full_path; wordexp_t full_path;
if (0 != wordexp(dirname, &full_path, 0)) { 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); wordfree(&full_path);
return -1; return -1;
} }
...@@ -228,7 +227,7 @@ bool taosIsDir(const char *dirname) { ...@@ -228,7 +227,7 @@ bool taosIsDir(const char *dirname) {
return false; return false;
} }
char* taosDirName(char *name) { char *taosDirName(char *name) {
#ifdef WINDOWS #ifdef WINDOWS
char Drive1[MAX_PATH], Dir1[MAX_PATH]; char Drive1[MAX_PATH], Dir1[MAX_PATH];
_splitpath(name, Drive1, Dir1, NULL, NULL); _splitpath(name, Drive1, Dir1, NULL, NULL);
...@@ -242,13 +241,13 @@ char* taosDirName(char *name) { ...@@ -242,13 +241,13 @@ char* taosDirName(char *name) {
#endif #endif
} }
char* taosDirEntryBaseName(char *name) { char *taosDirEntryBaseName(char *name) {
#ifdef WINDOWS #ifdef WINDOWS
char Filename1[MAX_PATH], Ext1[MAX_PATH]; char Filename1[MAX_PATH], Ext1[MAX_PATH];
_splitpath(name, NULL, NULL, Filename1, Ext1); _splitpath(name, NULL, NULL, Filename1, Ext1);
return name + (strlen(name) - strlen(Filename1) - strlen(Ext1)); return name + (strlen(name) - strlen(Filename1) - strlen(Ext1));
#else #else
return (char*)basename(name); return (char *)basename(name);
#endif #endif
} }
...@@ -275,7 +274,6 @@ TdDirPtr taosOpenDir(const char *dirname) { ...@@ -275,7 +274,6 @@ TdDirPtr taosOpenDir(const char *dirname) {
#else #else
return (TdDirPtr)opendir(dirname); return (TdDirPtr)opendir(dirname);
#endif #endif
} }
TdDirEntryPtr taosReadDir(TdDirPtr pDir) { TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
...@@ -286,9 +284,9 @@ TdDirEntryPtr taosReadDir(TdDirPtr pDir) { ...@@ -286,9 +284,9 @@ TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
if (!FindNextFile(pDir->hFind, &(pDir->dirEntry.findFileData))) { if (!FindNextFile(pDir->hFind, &(pDir->dirEntry.findFileData))) {
return NULL; return NULL;
} }
return (TdDirEntryPtr)&(pDir->dirEntry.findFileData); return (TdDirEntryPtr) & (pDir->dirEntry.findFileData);
#else #else
return (TdDirEntryPtr)readdir((DIR*)pDir); return (TdDirEntryPtr)readdir((DIR *)pDir);
#endif #endif
} }
...@@ -299,18 +297,18 @@ bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) { ...@@ -299,18 +297,18 @@ bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) {
#ifdef WINDOWS #ifdef WINDOWS
return (pDirEntry->findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; return (pDirEntry->findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
#else #else
return (((dirent*)pDirEntry)->d_type & DT_DIR) != 0; return (((dirent *)pDirEntry)->d_type & DT_DIR) != 0;
#endif #endif
} }
char* taosGetDirEntryName(TdDirEntryPtr pDirEntry) { char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) {
if (pDirEntry == NULL) { if (pDirEntry == NULL) {
return NULL; return NULL;
} }
#ifdef WINDOWS #ifdef WINDOWS
return pDirEntry->findFileData.cFileName; return pDirEntry->findFileData.cFileName;
#else #else
return ((dirent*)pDirEntry)->d_name; return ((dirent *)pDirEntry)->d_name;
#endif #endif
} }
...@@ -324,7 +322,7 @@ int32_t taosCloseDir(TdDirPtr *ppDir) { ...@@ -324,7 +322,7 @@ int32_t taosCloseDir(TdDirPtr *ppDir) {
*ppDir = NULL; *ppDir = NULL;
return 0; return 0;
#else #else
closedir((DIR*)*ppDir); closedir((DIR *)*ppDir);
*ppDir = NULL; *ppDir = NULL;
return 0; return 0;
#endif #endif
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#else #else
#include <arpa/inet.h> #include <arpa/inet.h>
#include <fcntl.h> #include <fcntl.h>
#include <net/if.h>
#include <netdb.h> #include <netdb.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/ip.h> #include <netinet/ip.h>
...@@ -638,6 +639,72 @@ int32_t taosKeepTcpAlive(TdSocketPtr pSocket) { ...@@ -638,6 +639,72 @@ int32_t taosKeepTcpAlive(TdSocketPtr pSocket) {
return 0; 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) { bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
struct sockaddr_in serverAdd; struct sockaddr_in serverAdd;
SocketFd fd; SocketFd fd;
...@@ -677,13 +744,8 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) { ...@@ -677,13 +744,8 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
taosCloseSocket(&pSocket); taosCloseSocket(&pSocket);
return false; 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); taosCloseSocket(&pSocket);
return true; return 0 == taosValidIp(ip) ? true : false;
} }
TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port) { TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port) {
struct sockaddr_in serverAdd; struct sockaddr_in serverAdd;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册