Skip to content
Snippets Groups Projects
Commit ce285b1f authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

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).
parent 254176a6
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -713,12 +713,13 @@ char* iniSetDuration(str_list_t* list, const char* section, const char* key ...@@ -713,12 +713,13 @@ char* iniSetDuration(str_list_t* list, const char* section, const char* key
#if !defined(NO_SOCKET_SUPPORT) #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) ,ini_style_t* style)
{ {
char buf[128];
struct in_addr in_addr; struct in_addr in_addr;
in_addr.s_addr=htonl(value); 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 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 ...@@ -1630,12 +1631,14 @@ int iniGetSocketOptions(str_list_t list, const char* section, SOCKET sock
return(0); return(0);
} }
static ulong parseIpAddress(const char* value) static uint32_t parseIpAddress(const char* value)
{ {
if(strchr(value,'.')==NULL) if(strchr(value,'.')==NULL)
return(strtol(value,NULL,0)); 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) static struct in6_addr parseIp6Address(const char* value)
...@@ -1661,7 +1664,7 @@ static struct in6_addr parseIp6Address(const char* value) ...@@ -1661,7 +1664,7 @@ static struct in6_addr parseIp6Address(const char* value)
return ret; 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 buf[INI_MAX_VALUE_LEN];
char* value; char* value;
...@@ -1689,7 +1692,7 @@ struct in6_addr iniReadIp6Address(FILE* fp, const char* section, const char* key ...@@ -1689,7 +1692,7 @@ struct in6_addr iniReadIp6Address(FILE* fp, const char* section, const char* key
return(parseIp6Address(value)); 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; char* vp=NULL;
......
...@@ -193,11 +193,11 @@ DLLEXPORT str_list_t iniGetSection(str_list_t, const char *section); ...@@ -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) #define iniGetLogLevel(l,s,k,d) iniGetEnum(l,s,k,iniLogLevelStringList(),d)
#if !defined(NO_SOCKET_SUPPORT) #if !defined(NO_SOCKET_SUPPORT)
DLLEXPORT ulong iniReadIpAddress(FILE*, const char* section, const char* key DLLEXPORT uint32_t iniReadIpAddress(FILE*, const char* section, const char* key
,ulong deflt); ,uint32_t deflt);
DLLEXPORT ulong iniGetIpAddress(str_list_t, const char* section, const char* key DLLEXPORT uint32_t iniGetIpAddress(str_list_t, const char* section, const char* key
,ulong deflt); ,uint32_t deflt);
DLLEXPORT char* iniSetIpAddress(str_list_t*, const char* section, const char* key, ulong value DLLEXPORT char* iniSetIpAddress(str_list_t*, const char* section, const char* key, uint32_t value
,ini_style_t*); ,ini_style_t*);
DLLEXPORT struct in6_addr DLLEXPORT struct in6_addr
iniReadIp6Address(FILE*, const char* section, const char* key iniReadIp6Address(FILE*, const char* section, const char* key
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment