Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get the current network speed

198 views
Skip to first unread message

SvenC

unread,
Dec 25, 2009, 10:22:58 AM12/25/09
to
Hi,

I would like to enable/disable functions of my software depending on the
available network speed. Comparable to Outlook which can fall back to
download only message headers instead of complete messages when
connected over a slow network.

Does anybody know how I can determine the current network speed?
Native Win32 APIs for C++ programming would be good.

--
SvenC

Pavel A.

unread,
Dec 25, 2009, 4:32:31 PM12/25/09
to
"SvenC" <Sv...@nospam.nospam> wrote in message
news:e63qjYXh...@TK2MSFTNGP02.phx.gbl...

AFAIK, this can be done in two steps:
a. Get the max declared speed of the physical connection
(for LAN based interfaces, can be obtained from WMI;
for dialup or PPPOE - I don't remember ).

b. Measure the round trip time.
Vista+ has QWAVE API to help with evaluation of the actual point to point
speed;
on earlier systems, roll your own.

Regards,
--pa

Rong-Chun Zhang [MSFT]

unread,
Dec 28, 2009, 6:14:39 AM12/28/09
to
Hello SvenC,

Happy New Year! And thank you for contacting Microsoft Support.

As per my understanding, if you just want check the available network speed
of the device, you can try Pavel's
suggestion(Win32_PerfRawData_Tcpip_NetworkInterface Class and
DeviceIoControl Function).

More information
http://msdn.microsoft.com/en-us/library/aa394340%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/aa363216%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/aa363147%28VS.85%29.aspx

If you want detect the real-time speed as the network bandwidth might be
consumed by other processes, we need to try to use it and measure the speed.

Best regards,
Rongchun Zhang (v-rz...@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

SvenC

unread,
Dec 28, 2009, 1:00:50 PM12/28/09
to
Thank you Pavel and Rong-Chun,

> As per my understanding, if you just want check the available network speed
> of the device, you can try Pavel's
> suggestion(Win32_PerfRawData_Tcpip_NetworkInterface Class

OK, I'll try the WMI classes Win32_PerfRawData_Tcpip_NetworkInterface
and Win32_PerfFormattedData_RemoteAccess_RASTotal.

> and DeviceIoControl Function).

How could the DeviceIoControl function help to measure network speed?
I didn't find any information in the links you provided.

--
SvenC

Rong-Chun Zhang [MSFT]

unread,
Dec 29, 2009, 3:59:19 AM12/29/09
to

Hello SvenC,

Thanks for your feedback.

> How could the DeviceIoControl function help to measure network speed?

Please take a look at the following article
http://software.intel.com/en-us/articles/implementing-network-detection-for-
mobility/

<Quote>
The connection type requires a bit more work, because the information
reported in the interface and adapter tables may not be sufficient to
distinguish between a wired and wireless LAN connection. To get the most
accurate data we have to ask the device driver for the adapter itself. This
can be done using the function DeviceIoControl to send the
OID_GEN_PHYSICAL_MEDIUM request to the driver.
</Quote>

Regards,


Rongchun Zhang (v-rz...@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

Pavel A.

unread,
Dec 29, 2009, 11:39:38 PM12/29/09
to
Hi Sven,

Usually you don't need to use ioctls, the information is available on higher
level: performance counters, WMI objects such as Win32_NetworkAdapter, or
MSNDIS_* objects.
The most difficult is to find which interface you actually use for specific
end to end connection,
in case the machine has several interfaces, and the underlying network
limits.

For example, I have pppoe over Gigabyte ethernet. Though the physical
netcard happily reports
link speed 1GB, the actual link is the pppoe, and it runs thru a DSL modem
whose speed
is capped by my provider. The speed here can be determined only by
measurement.

Regards,
--pa

"SvenC" <Sv...@nospam.nospam> wrote in message

news:OumEye#hKHA...@TK2MSFTNGP04.phx.gbl...

SvenC

unread,
Dec 30, 2009, 4:28:05 AM12/30/09
to
Hi Pavel,

> Usually you don't need to use ioctls, the information is available on higher
> level: performance counters, WMI objects such as Win32_NetworkAdapter, or
> MSNDIS_* objects.
> The most difficult is to find which interface you actually use for specific
> end to end connection, in case the machine has several interfaces, and
> the underlying network limits.

With the help of Rong-Chun's links I came up with this code:

DWORD getSpeed()
{
// get the best interface by asking for any internet IP address
unsigned long dwBestIfIndex = 0;
IPAddr dwDestAddr = (IPAddr)inet_addr("8.8.8.8");
if(GetBestInterface(dwDestAddr,&dwBestIfIndex) != NO_ERROR)
return 200;

// get information for the interface index found above
PMIB_IFTABLE pMIFT = NULL;
MIB_IFROW *pIFR = NULL;
ULONG cbMIFT = 0;
GetIfTable(NULL, &cbMIFT, TRUE);
if(cbMIFT > 0)
{
pMIFT = (PMIB_IFTABLE)GlobalAlloc(GMEM_ZEROINIT, cbMIFT);
if(pMIFT)
{
GetIfTable(pMIFT, &cbMIFT, TRUE);
for(DWORD i = 0; pIFR == NULL && i < pMIFT->dwNumEntries; ++i)
{
if(pMIFT->table[i].dwIndex == dwBestIfIndex)
{
pIFR = &pMIFT->table[i];
}
}
}
}

// get the interface speed if it is at least in the connected state
DWORD r = pIFR && pIFR->dwOperStatus >= MIB_IF_OPER_STATUS_CONNECTED ? pIFR->dwSpeed : 0;

if(pMIFT)
{
GlobalFree(pMIFT);
pMIFT = NULL;
}

return r;
}

> For example, I have pppoe over Gigabyte ethernet. Though the physical
> netcard happily reports link speed 1GB, the actual link is the pppoe,
> and it runs thru a DSL modem whose speed is capped by my provider.
> The speed here can be determined only by measurement.

You are right about this one. I will have a look at your hint about qWave.

Thank you,
SvenC

0 new messages