diff --git a/include/os/osSocket.h b/include/os/osSocket.h index 4bad51e26322405d9c4187e3bd7a12a75ee011b9..c6729da76af0e59cb3ccda024709b86fe034b039 100644 --- a/include/os/osSocket.h +++ b/include/os/osSocket.h @@ -167,7 +167,7 @@ uint32_t ip2uint(const char *const ip_addr); void taosIgnSIGPIPE(); void taosSetMaskSIGPIPE(); uint32_t taosInetAddr(const char *ipAddr); -const char *taosInetNtoa(struct in_addr ipInt); +const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len); #ifdef __cplusplus } diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c index 15e94baee4f4d7ff32d2d956cc04f9d2ca3e240f..325073f3660172a1067d0bf92e11a8ae9f88fa01 100644 --- a/source/libs/sync/src/syncUtil.c +++ b/source/libs/sync/src/syncUtil.c @@ -57,7 +57,7 @@ void syncUtilU642Addr(uint64_t u64, char* host, size_t len, uint16_t* port) { struct in_addr addr; addr.s_addr = hostU32; - snprintf(host, len, "%s", taosInetNtoa(addr)); + taosInetNtoa(addr, host, len); *port = (uint16_t)((u64 & 0x00000000FFFF0000) >> 16); } diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 22b91ddf1d3d39b423253004f2c73f2418766225..b34d071773591600e06adc9b08873a89b7e2e1b4 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -312,10 +312,8 @@ uint32_t taosInetAddr(const char *ipAddr) { return inet_addr(ipAddr); #endif } -const char *taosInetNtoa(struct in_addr ipInt) { - // not thread safe, only for debug usage while print log - char tmpDstStr[16]; - return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN); +const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len) { + return inet_ntop(AF_INET, &ipInt, dstStr, len); } #ifndef SIGPIPE @@ -666,7 +664,7 @@ int taosGetLocalIp(const char *eth, char *ip) { return -1; } memcpy(&sin, &ifr.ifr_addr, sizeof(sin)); - snprintf(ip, 64, "%s", taosInetNtoa(sin.sin_addr)); + taosInetNtoa(sin.sin_addr, ip, 64); taosCloseSocketNoCheck1(fd); #endif return 0;