Browse Source

fix tray icon disappearing, var type warning, code tabulation

pull/1295/head
R4SAS 6 years ago
parent
commit
a14d554947
  1. 2
      Win32/DaemonWin32.cpp
  2. 9
      Win32/Win32App.cpp
  3. 66
      libi2pd/util.cpp

2
Win32/DaemonWin32.cpp

@ -50,7 +50,7 @@ namespace util
if (isDaemon) if (isDaemon)
{ {
LogPrint(eLogDebug, "Daemon: running as service"); LogPrint(eLogDebug, "Daemon: running as service");
I2PService service(SERVICE_NAME); I2PService service((PSTR)SERVICE_NAME);
if (!I2PService::Run(service)) if (!I2PService::Run(service))
{ {
LogPrint(eLogError, "Daemon: Service failed to run w/err 0x%08lx\n", GetLastError()); LogPrint(eLogError, "Daemon: Service failed to run w/err 0x%08lx\n", GetLastError());

9
Win32/Win32App.cpp

@ -166,10 +166,13 @@ namespace win32
static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
static UINT s_uTaskbarRestart;
switch (uMsg) switch (uMsg)
{ {
case WM_CREATE: case WM_CREATE:
{ {
s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
AddTrayIcon (hWnd); AddTrayIcon (hWnd);
break; break;
} }
@ -318,6 +321,12 @@ namespace win32
EndPaint(hWnd, &ps); EndPaint(hWnd, &ps);
break; break;
} }
default:
{
if (uMsg == s_uTaskbarRestart)
AddTrayIcon (hWnd);
break;
}
} }
return DefWindowProc( hWnd, uMsg, wParam, lParam); return DefWindowProc( hWnd, uMsg, wParam, lParam);
} }

66
libi2pd/util.cpp

@ -22,9 +22,10 @@
#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 in Windows Vista, but XP haven't that function! // inet_pton exists Windows since Vista, but XP haven't 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) int inet_pton_xp(int af, const char *src, void *dst)
{ // This function was written by Petar Korponai?. See http://stackoverflow.com/questions/15660203/inet-pton-identifier-not-found {
struct sockaddr_storage ss; struct sockaddr_storage ss;
int size = sizeof (ss); int size = sizeof (ss);
char src_copy[INET6_ADDRSTRLEN + 1]; char src_copy[INET6_ADDRSTRLEN + 1];
@ -59,12 +60,12 @@ namespace util
namespace net namespace net
{ {
#ifdef WIN32 #ifdef WIN32
bool IsWindowsXPorLater() { bool IsWindowsXPorLater()
{
OSVERSIONINFO osvi; OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi); GetVersionEx(&osvi);
if (osvi.dwMajorVersion <= 5) if (osvi.dwMajorVersion <= 5)
@ -80,9 +81,9 @@ namespace net
PIP_ADAPTER_ADDRESSES pCurrAddresses = nullptr; PIP_ADAPTER_ADDRESSES pCurrAddresses = nullptr;
PIP_ADAPTER_UNICAST_ADDRESS pUnicast = nullptr; PIP_ADAPTER_UNICAST_ADDRESS pUnicast = nullptr;
if(GetAdaptersAddresses(AF_INET, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAddresses, &outBufLen) if(GetAdaptersAddresses(AF_INET, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAddresses, &outBufLen)
== ERROR_BUFFER_OVERFLOW) { == ERROR_BUFFER_OVERFLOW)
{
FREE(pAddresses); FREE(pAddresses);
pAddresses = (IP_ADAPTER_ADDRESSES*) MALLOC(outBufLen); pAddresses = (IP_ADAPTER_ADDRESSES*) MALLOC(outBufLen);
} }
@ -91,24 +92,28 @@ namespace net
AF_INET, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAddresses, &outBufLen AF_INET, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAddresses, &outBufLen
); );
if(dwRetVal != NO_ERROR) { if(dwRetVal != NO_ERROR)
{
LogPrint(eLogError, "NetIface: GetMTU(): enclosed GetAdaptersAddresses() call has failed"); LogPrint(eLogError, "NetIface: GetMTU(): enclosed GetAdaptersAddresses() call has failed");
FREE(pAddresses); FREE(pAddresses);
return fallback; return fallback;
} }
pCurrAddresses = pAddresses; pCurrAddresses = pAddresses;
while(pCurrAddresses) { while(pCurrAddresses)
{
PIP_ADAPTER_UNICAST_ADDRESS firstUnicastAddress = pCurrAddresses->FirstUnicastAddress; PIP_ADAPTER_UNICAST_ADDRESS firstUnicastAddress = pCurrAddresses->FirstUnicastAddress;
pUnicast = pCurrAddresses->FirstUnicastAddress; pUnicast = pCurrAddresses->FirstUnicastAddress;
if(pUnicast == nullptr) { if(pUnicast == nullptr)
LogPrint(eLogError, "NetIface: GetMTU(): not a unicast ipv4 address, this is not supported"); LogPrint(eLogError, "NetIface: GetMTU(): not a unicast ipv4 address, this is not supported");
}
for(int i = 0; pUnicast != nullptr; ++i) { for(int i = 0; pUnicast != nullptr; ++i)
{
LPSOCKADDR lpAddr = pUnicast->Address.lpSockaddr; LPSOCKADDR lpAddr = pUnicast->Address.lpSockaddr;
sockaddr_in* localInterfaceAddress = (sockaddr_in*) lpAddr; sockaddr_in* localInterfaceAddress = (sockaddr_in*) lpAddr;
if(localInterfaceAddress->sin_addr.S_un.S_addr == inputAddress.sin_addr.S_un.S_addr) { if(localInterfaceAddress->sin_addr.S_un.S_addr == inputAddress.sin_addr.S_un.S_addr)
{
auto result = pAddresses->Mtu; auto result = pAddresses->Mtu;
FREE(pAddresses); FREE(pAddresses);
return result; return result;
@ -131,7 +136,8 @@ namespace net
PIP_ADAPTER_UNICAST_ADDRESS pUnicast = nullptr; PIP_ADAPTER_UNICAST_ADDRESS pUnicast = nullptr;
if(GetAdaptersAddresses(AF_INET6, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAddresses, &outBufLen) if(GetAdaptersAddresses(AF_INET6, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAddresses, &outBufLen)
== ERROR_BUFFER_OVERFLOW) { == ERROR_BUFFER_OVERFLOW)
{
FREE(pAddresses); FREE(pAddresses);
pAddresses = (IP_ADAPTER_ADDRESSES*) MALLOC(outBufLen); pAddresses = (IP_ADAPTER_ADDRESSES*) MALLOC(outBufLen);
} }
@ -140,7 +146,8 @@ namespace net
AF_INET6, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAddresses, &outBufLen AF_INET6, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAddresses, &outBufLen
); );
if(dwRetVal != NO_ERROR) { if(dwRetVal != NO_ERROR)
{
LogPrint(eLogError, "NetIface: GetMTU(): enclosed GetAdaptersAddresses() call has failed"); LogPrint(eLogError, "NetIface: GetMTU(): enclosed GetAdaptersAddresses() call has failed");
FREE(pAddresses); FREE(pAddresses);
return fallback; return fallback;
@ -148,23 +155,28 @@ namespace net
bool found_address = false; bool found_address = false;
pCurrAddresses = pAddresses; pCurrAddresses = pAddresses;
while(pCurrAddresses) { while(pCurrAddresses)
{
PIP_ADAPTER_UNICAST_ADDRESS firstUnicastAddress = pCurrAddresses->FirstUnicastAddress; PIP_ADAPTER_UNICAST_ADDRESS firstUnicastAddress = pCurrAddresses->FirstUnicastAddress;
pUnicast = pCurrAddresses->FirstUnicastAddress; pUnicast = pCurrAddresses->FirstUnicastAddress;
if(pUnicast == nullptr) { if(pUnicast == nullptr)
LogPrint(eLogError, "NetIface: GetMTU(): not a unicast ipv6 address, this is not supported"); LogPrint(eLogError, "NetIface: GetMTU(): not a unicast ipv6 address, this is not supported");
}
for(int i = 0; pUnicast != nullptr; ++i) { for(int i = 0; pUnicast != nullptr; ++i)
{
LPSOCKADDR lpAddr = pUnicast->Address.lpSockaddr; LPSOCKADDR lpAddr = pUnicast->Address.lpSockaddr;
sockaddr_in6 *localInterfaceAddress = (sockaddr_in6*) lpAddr; sockaddr_in6 *localInterfaceAddress = (sockaddr_in6*) lpAddr;
for (int j = 0; j != 8; ++j) { for (int j = 0; j != 8; ++j)
if (localInterfaceAddress->sin6_addr.u.Word[j] != inputAddress.sin6_addr.u.Word[j]) { {
if (localInterfaceAddress->sin6_addr.u.Word[j] != inputAddress.sin6_addr.u.Word[j])
break; break;
} else { else
found_address = true; found_address = true;
} }
} if (found_address) {
if (found_address)
{
auto result = pAddresses->Mtu; auto result = pAddresses->Mtu;
FREE(pAddresses); FREE(pAddresses);
pAddresses = nullptr; pAddresses = nullptr;
@ -193,11 +205,14 @@ namespace net
if (IsWindowsXPorLater()) if (IsWindowsXPorLater())
#define inet_pton inet_pton_xp #define inet_pton inet_pton_xp
if(localAddress.is_v4()) { if(localAddress.is_v4())
{
sockaddr_in inputAddress; sockaddr_in inputAddress;
inet_pton(AF_INET, localAddressUniversal.c_str(), &(inputAddress.sin_addr)); 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;
inet_pton(AF_INET6, localAddressUniversal.c_str(), &(inputAddress.sin6_addr)); inet_pton(AF_INET6, localAddressUniversal.c_str(), &(inputAddress.sin6_addr));
return GetMTUWindowsIpv6(inputAddress, fallback); return GetMTUWindowsIpv6(inputAddress, fallback);
@ -309,7 +324,8 @@ namespace net
} }
if(addrs) freeifaddrs(addrs); if(addrs) freeifaddrs(addrs);
std::string fallback; std::string fallback;
if(ipv6) { if(ipv6)
{
fallback = "::"; fallback = "::";
LogPrint(eLogWarning, "NetIface: cannot find ipv6 address for interface ", ifname); LogPrint(eLogWarning, "NetIface: cannot find ipv6 address for interface ", ifname);
} else { } else {

Loading…
Cancel
Save