From ce285b1f404fd93ab52d0735c0e58495886c8264 Mon Sep 17 00:00:00 2001 From: Rob Swindell <rob@synchro.net> Date: Sun, 15 May 2022 23:48:19 -0700 Subject: [PATCH] Replace deprecated inet_ntoa and inet_addr function calls Use inet_ntop and inet_pton instead. Use 32-bit arguments and return values for IPv4 addressess for all target platforms (ulong is 64-bit on LP64, e.g. Linux-x64, targets). --- src/xpdev/ini_file.c | 15 +++++++++------ src/xpdev/ini_file.h | 10 +++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c index 05d3e1829b..ccf5eaac32 100644 --- a/src/xpdev/ini_file.c +++ b/src/xpdev/ini_file.c @@ -713,12 +713,13 @@ char* iniSetDuration(str_list_t* list, const char* section, const char* key #if !defined(NO_SOCKET_SUPPORT) -char* iniSetIpAddress(str_list_t* list, const char* section, const char* key, ulong value +char* iniSetIpAddress(str_list_t* list, const char* section, const char* key, uint32_t value ,ini_style_t* style) { + char buf[128]; struct in_addr in_addr; in_addr.s_addr=htonl(value); - return iniSetString(list, section, key, inet_ntoa(in_addr), style); + return iniSetString(list, section, key, inet_ntop(AF_INET, &in_addr, buf, sizeof(buf)), style); } char* iniSetIp6Address(str_list_t* list, const char* section, const char* key, struct in6_addr value @@ -1630,12 +1631,14 @@ int iniGetSocketOptions(str_list_t list, const char* section, SOCKET sock return(0); } -static ulong parseIpAddress(const char* value) +static uint32_t parseIpAddress(const char* value) { if(strchr(value,'.')==NULL) return(strtol(value,NULL,0)); - return(ntohl(inet_addr(value))); + uint32_t result = 0; + inet_pton(AF_INET, value, &result); + return ntohl(result); } static struct in6_addr parseIp6Address(const char* value) @@ -1661,7 +1664,7 @@ static struct in6_addr parseIp6Address(const char* value) return ret; } -ulong iniReadIpAddress(FILE* fp, const char* section, const char* key, ulong deflt) +uint32_t iniReadIpAddress(FILE* fp, const char* section, const char* key, uint32_t deflt) { char buf[INI_MAX_VALUE_LEN]; char* value; @@ -1689,7 +1692,7 @@ struct in6_addr iniReadIp6Address(FILE* fp, const char* section, const char* key return(parseIp6Address(value)); } -ulong iniGetIpAddress(str_list_t list, const char* section, const char* key, ulong deflt) +uint32_t iniGetIpAddress(str_list_t list, const char* section, const char* key, uint32_t deflt) { char* vp=NULL; diff --git a/src/xpdev/ini_file.h b/src/xpdev/ini_file.h index cdeb48447c..c890085ccd 100644 --- a/src/xpdev/ini_file.h +++ b/src/xpdev/ini_file.h @@ -193,11 +193,11 @@ DLLEXPORT str_list_t iniGetSection(str_list_t, const char *section); #define iniGetLogLevel(l,s,k,d) iniGetEnum(l,s,k,iniLogLevelStringList(),d) #if !defined(NO_SOCKET_SUPPORT) -DLLEXPORT ulong iniReadIpAddress(FILE*, const char* section, const char* key - ,ulong deflt); -DLLEXPORT ulong iniGetIpAddress(str_list_t, const char* section, const char* key - ,ulong deflt); -DLLEXPORT char* iniSetIpAddress(str_list_t*, const char* section, const char* key, ulong value +DLLEXPORT uint32_t iniReadIpAddress(FILE*, const char* section, const char* key + ,uint32_t deflt); +DLLEXPORT uint32_t iniGetIpAddress(str_list_t, const char* section, const char* key + ,uint32_t deflt); +DLLEXPORT char* iniSetIpAddress(str_list_t*, const char* section, const char* key, uint32_t value ,ini_style_t*); DLLEXPORT struct in6_addr iniReadIp6Address(FILE*, const char* section, const char* key -- GitLab