Browse Source

Use GetProcAddress for inet_pton. Fixed build error

pull/1441/head
orignal 5 years ago
parent
commit
515c086099
  1. 6
      libi2pd/RouterContext.cpp
  2. 16
      libi2pd/util.cpp

6
libi2pd/RouterContext.cpp

@ -27,12 +27,8 @@ namespace i2p @@ -27,12 +27,8 @@ namespace i2p
void RouterContext::Init ()
{
srand (i2p::util::GetMillisecondsSinceEpoch () % 1000);
#ifdef WIN32
// for compatibility with WinXP
m_StartupTime = i2p::util::GetSecondsSinceEpoch ();
#else
m_StartupTime = std::chrono::steady_clock::now();
#endif
if (!Load ())
CreateNewRouter ();
m_Decryptor = m_Keys.CreateDecryptor (nullptr);

16
libi2pd/util.cpp

@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
// inet_pton exists Windows since Vista, but XP haven't that function!
// inet_pton exists Windows since Vista, but XP doesn't have that function!
// This function was written by Petar Korponai?. See http://stackoverflow.com/questions/15660203/inet-pton-identifier-not-found
int inet_pton_xp(int af, const char *src, void *dst)
{
@ -207,24 +207,20 @@ namespace net @@ -207,24 +207,20 @@ namespace net
std::string localAddressUniversal = localAddress.to_string();
#endif
bool isXP = IsWindowsXPorLater();
typedef int (* IPN)(int af, const char *src, void *dst);
IPN inetpton = (IPN)GetProcAddress (GetModuleHandle ("ws2_32.dll"), "InetPton");
if (!inetpton) inetpton = inet_pton_xp; // use own implementation if not found
if(localAddress.is_v4())
{
sockaddr_in inputAddress;
if (isXP)
inet_pton_xp(AF_INET, localAddressUniversal.c_str(), &(inputAddress.sin_addr));
else
inet_pton(AF_INET, localAddressUniversal.c_str(), &(inputAddress.sin_addr));
inetpton(AF_INET, localAddressUniversal.c_str(), &(inputAddress.sin_addr));
return GetMTUWindowsIpv4(inputAddress, fallback);
}
else if(localAddress.is_v6())
{
sockaddr_in6 inputAddress;
if (isXP)
inet_pton_xp(AF_INET6, localAddressUniversal.c_str(), &(inputAddress.sin6_addr));
else
inet_pton(AF_INET6, localAddressUniversal.c_str(), &(inputAddress.sin6_addr));
inetpton(AF_INET6, localAddressUniversal.c_str(), &(inputAddress.sin6_addr));
return GetMTUWindowsIpv6(inputAddress, fallback);
} else {
LogPrint(eLogError, "NetIface: GetMTU(): address family is not supported");

Loading…
Cancel
Save