mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-22 00:59:08 +01:00
Use GetProcAddress for inet_pton. Fixed build error
This commit is contained in:
parent
34ce06ac17
commit
515c086099
2 changed files with 20 additions and 28 deletions
|
@ -27,12 +27,8 @@ namespace i2p
|
||||||
void RouterContext::Init ()
|
void RouterContext::Init ()
|
||||||
{
|
{
|
||||||
srand (i2p::util::GetMillisecondsSinceEpoch () % 1000);
|
srand (i2p::util::GetMillisecondsSinceEpoch () % 1000);
|
||||||
#ifdef WIN32
|
|
||||||
// for compatibility with WinXP
|
|
||||||
m_StartupTime = i2p::util::GetSecondsSinceEpoch ();
|
|
||||||
#else
|
|
||||||
m_StartupTime = std::chrono::steady_clock::now();
|
m_StartupTime = std::chrono::steady_clock::now();
|
||||||
#endif
|
|
||||||
if (!Load ())
|
if (!Load ())
|
||||||
CreateNewRouter ();
|
CreateNewRouter ();
|
||||||
m_Decryptor = m_Keys.CreateDecryptor (nullptr);
|
m_Decryptor = m_Keys.CreateDecryptor (nullptr);
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
|
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
|
||||||
#define FREE(x) HeapFree(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
|
// 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)
|
int inet_pton_xp(int af, const char *src, void *dst)
|
||||||
{
|
{
|
||||||
|
@ -207,24 +207,20 @@ namespace net
|
||||||
std::string localAddressUniversal = localAddress.to_string();
|
std::string localAddressUniversal = localAddress.to_string();
|
||||||
#endif
|
#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())
|
if(localAddress.is_v4())
|
||||||
{
|
{
|
||||||
sockaddr_in inputAddress;
|
sockaddr_in inputAddress;
|
||||||
if (isXP)
|
inetpton(AF_INET, localAddressUniversal.c_str(), &(inputAddress.sin_addr));
|
||||||
inet_pton_xp(AF_INET, localAddressUniversal.c_str(), &(inputAddress.sin_addr));
|
|
||||||
else
|
|
||||||
inet_pton(AF_INET, localAddressUniversal.c_str(), &(inputAddress.sin_addr));
|
|
||||||
return GetMTUWindowsIpv4(inputAddress, fallback);
|
return GetMTUWindowsIpv4(inputAddress, fallback);
|
||||||
}
|
}
|
||||||
else if(localAddress.is_v6())
|
else if(localAddress.is_v6())
|
||||||
{
|
{
|
||||||
sockaddr_in6 inputAddress;
|
sockaddr_in6 inputAddress;
|
||||||
if (isXP)
|
inetpton(AF_INET6, localAddressUniversal.c_str(), &(inputAddress.sin6_addr));
|
||||||
inet_pton_xp(AF_INET6, localAddressUniversal.c_str(), &(inputAddress.sin6_addr));
|
|
||||||
else
|
|
||||||
inet_pton(AF_INET6, localAddressUniversal.c_str(), &(inputAddress.sin6_addr));
|
|
||||||
return GetMTUWindowsIpv6(inputAddress, fallback);
|
return GetMTUWindowsIpv6(inputAddress, fallback);
|
||||||
} else {
|
} else {
|
||||||
LogPrint(eLogError, "NetIface: GetMTU(): address family is not supported");
|
LogPrint(eLogError, "NetIface: GetMTU(): address family is not supported");
|
||||||
|
|
Loading…
Add table
Reference in a new issue