XWidgetSoft Forum

XWidget & XLaunchpad , Desktop customization
It is currently May 7th, 2025, 11:28 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: March 29th, 2014, 1:20 am 
Offline
User avatar

Joined: March 8th, 2013, 10:27 pm
Posts: 353
These days I was doing a a bit of studies on C++ and Networking,IP and WinSock and found out a method to query *ALL* interfaces and find out the speed, data transfer etc...
The secret lies in the API function GetIfTable in IpHlpApi.dll. It could be put to work in XWidget, ending all the speculations and bug reports of NetMonitorCore not showing any data.

The code was tested to work for modems,bluetooth pan networks,Wi-Fi,LAN,Ethernet,and VPN's. And it works accurately with all of them. With a very little effort it could be put to use in XWidget.

Here is some C++ code that XWidget developers may find useful. (Not for Widget developers)\
Code:
#include <iostream>
#include <stdio.h>
#include <tchar.h>

#include <vector>
#include <winsock2.h>
//#include <ws2tcpip.h>
#include <Iphlpapi.h>

void UpdateData()
{
   DWORD ret, size = 0, c_NumOfTables;

   PMIB_IFTABLE ifTable = nullptr;

   if ((ret = GetIfTable(ifTable, &size, FALSE)) == ERROR_INSUFFICIENT_BUFFER)
   {

      ifTable = (PMIB_IFTABLE)malloc(size);
      ret = GetIfTable(ifTable, &size, FALSE);

   }

   if (ret == NO_ERROR)
   {
      c_NumOfTables = ifTable->dwNumEntries;
      wprintf(L"------------------------------\n");
      wprintf(L"* NETWORK-INTERFACE: Count=%i\n", c_NumOfTables);

      for (size_t i = 0; i < c_NumOfTables; ++i)
      {
         const WCHAR* type = L"";
         switch (ifTable->table[i].dwType)
         {
         case IF_TYPE_ETHERNET_CSMACD:
            type = L"Ethernet";
            break;
         case IF_TYPE_PPP:
            type = L"PPP";
            break;
         case IF_TYPE_SOFTWARE_LOOPBACK:
            type = L"Loopback";
            break;
         case IF_TYPE_IEEE80211:
            type = L"IEEE802.11";
            break;
         case IF_TYPE_TUNNEL:
            type = L"Tunnel";
            break;
         case IF_TYPE_IEEE1394:
            type = L"IEEE1394";
            break;
         default:
            type = L"Other";
            break;
         }

         wprintf(L"%i: %.*S\n", (int)i + 1, ifTable->table[i].dwDescrLen, (char*)ifTable->table[i].bDescr);
         wprintf(L" Type=%s(%i)\n", type, ifTable->table[i].dwType);

         wprintf(L" Bytes sent: %d Bytes Received %d\n",ifTable->table[i].dwInOctets,ifTable->table[i].dwOutOctets);
      }
      wprintf(L"------------------------------\n");

   }
}
int _tmain(int argc, _TCHAR* argv[])
{
   printf("Initializing netmon\n");
   while(true) {
      UpdateData();
      Sleep(1000);
   }
}



Compiles with absolutely any compiler. I used Visual Studio 2012 though.

Another long standing request is to release an API to allow independent developers to write cores in languages like C++. The popular Rainmeter holds this feature since long. And, it's rather easy to add such a feature. Except for the designer integration part, but still holds a solution! :D

_________________
Life is a myriad game... Just play it!


Top
 Profile  
 
PostPosted: March 29th, 2014, 4:37 am 
Offline
User avatar

Joined: December 5th, 2012, 5:52 pm
Posts: 4887
Thank you very much for this DG! I asked Tony about the v2.0 of XWidget and needs a couple of months for a beta. You can try to send a pm here to Tony about all this, so if it's possible collaborate for the next version..

_________________
...and remember: don't take life too seriously...
My profile on Deviantart: http://jimking.deviantart.com/


Top
 Profile  
 
PostPosted: March 29th, 2014, 9:33 pm 
Offline
User avatar

Joined: May 12th, 2012, 8:32 pm
Posts: 594
Thanks digigamer, I will try to add this into XWidget

_________________
XWidget Software Developer
[XWidget for Android] [Lastest version of XWidget] [Lastest patch of XWidget]
[XDesktop for Android/Windows]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group