Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error msg if failed get ip from fqdn #23919

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/common/src/tglobal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
static int32_t taosCheckGlobalCfg() {
uint32_t ipv4 = taosGetIpv4FromFqdn(tsLocalFqdn);
if (ipv4 == 0xffffffff) {
terrno = TAOS_SYSTEM_ERROR(errno);
terrno = TSDB_CODE_RPC_FQDN_ERROR;
uError("failed to get ip from fqdn:%s since %s, dnode can not be initialized", tsLocalFqdn, terrstr());
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion source/libs/transport/src/transCli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ static FORCE_INLINE uint32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn)
if (v == NULL) {
addr = taosGetIpv4FromFqdn(fqdn);
if (addr == 0xffffffff) {
terrno = TAOS_SYSTEM_ERROR(errno);
terrno = TSDB_CODE_RPC_FQDN_ERROR;
tError("failed to get ip from fqdn:%s since %s", fqdn, terrstr());
return addr;
}
Expand Down
29 changes: 29 additions & 0 deletions source/os/test/osTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,35 @@

#ifdef WINDOWS
#include <windows.h>
#else

#include <arpa/inet.h>

TEST(osTest, osFQDNSuccess) {
char fqdn[1024];
char ipString[INET_ADDRSTRLEN];
int code = taosGetFqdn(fqdn);
uint32_t ipv4 = taosGetIpv4FromFqdn(fqdn);
ASSERT_NE(ipv4, 0xffffffff);

struct in_addr addr;
addr.s_addr = htonl(ipv4);
snprintf(ipString, INET_ADDRSTRLEN, "%u.%u.%u.%u", (unsigned int)(addr.s_addr >> 24) & 0xFF,
(unsigned int)(addr.s_addr >> 16) & 0xFF, (unsigned int)(addr.s_addr >> 8) & 0xFF,
(unsigned int)(addr.s_addr) & 0xFF);
printf("fqdn:%s ip:%s\n", fqdn, ipString);
}

TEST(osTest, osFQDNFailed) {
char fqdn[1024] = "fqdn_test_not_found";
char ipString[24];
uint32_t ipv4 = taosGetIpv4FromFqdn(fqdn);
ASSERT_EQ(ipv4, 0xffffffff);

terrno = TSDB_CODE_RPC_FQDN_ERROR;
printf("fqdn:%s transfer to ip failed!\n", fqdn);
}

#endif // WINDOWS

TEST(osTest, osSystem) {
Expand Down