Skip to content
Snippets Groups Projects
Commit 02fb1f29 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 287d03ac
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment