-
Notifications
You must be signed in to change notification settings - Fork 0
/
netpage.cpp
3825 lines (2904 loc) · 93.9 KB
/
netpage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//+-------------------------------------------------------------------------
//
// TaskMan - NT TaskManager
// Copyright (C) Microsoft
//
// File: netpage.cpp
//
// History: Oct-18-2000 Olaf Miller Created
//
//--------------------------------------------------------------------------
#include "precomp.h"
#define MIN_GRAPH_HEIGHT 120
#define SCROLLBAR_WIDTH 17
#define INVALID_VALUE 0xFFFFFFFF
#define PERCENT_SHIFT 10000000
#define PERCENT_DECIMAL_POINT 7
//
// Determines how the graphs are drawen (zoomed level)
//
static int g_NetScrollamount = 0;
extern WCHAR g_szG[];
extern WCHAR g_szM[];
extern WCHAR g_szK[];
extern WCHAR g_szZero[];
extern WCHAR g_szPackets[];
extern WCHAR g_szBitsPerSec[];
extern WCHAR g_szScaleFont[SHORTSTRLEN];
extern WCHAR g_szPercent[];
extern WCHAR g_szNonOperational[];
extern WCHAR g_szUnreachable[];
extern WCHAR g_szDisconnected[];
extern WCHAR g_szConnecting[];
extern WCHAR g_szConnected[];
extern WCHAR g_szOperational[];
extern WCHAR g_szUnknownStatus[];
extern WCHAR g_szGroupThousSep[];
extern WCHAR g_szDecimal[];
extern ULONG g_ulGroupSep;
//
// Window Proc the Network Tab
//
INT_PTR CALLBACK NetPageProc(
HWND hwnd, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
//
// Colors of the pens
//
static const COLORREF aNetColors[] =
{
RGB(255, 000, 0),
RGB(255, 255, 0),
RGB(000, 255, 0),
};
//
// Default values for the Networking Page's statistics columns
//
struct
{
SHORT Format;
SHORT Width;
} NetColumnDefaults[NUM_NETCOLUMN] =
{
{ LVCFMT_LEFT, 96 }, // COL_ADAPTERNAME
{ LVCFMT_LEFT, 96 }, // COL_ADAPTERDESC
{ LVCFMT_RIGHT, 96 }, // COL_NETWORKUTIL
{ LVCFMT_RIGHT, 60 }, // COL_LINKSPEED
{ LVCFMT_RIGHT, 96 }, // COL_STATE
{ LVCFMT_RIGHT, 70 }, // COL_BYTESSENTTHRU
{ LVCFMT_RIGHT, 70 }, // COL_BYTESRECTHRU
{ LVCFMT_RIGHT, 75 }, // COL_BYTESTOTALTHRU
{ LVCFMT_RIGHT, 70 }, // COL_BYTESSENT
{ LVCFMT_RIGHT, 70 }, // COL_BYTESREC
{ LVCFMT_RIGHT, 50 }, // COL_BYTESTOTAL
{ LVCFMT_RIGHT, 70 }, // COL_BYTESSENTPERINTER
{ LVCFMT_RIGHT, 70 }, // COL_BYTESRECPERINTER
{ LVCFMT_RIGHT, 70 }, // COL_BYTESTOTALPERINTER
{ LVCFMT_RIGHT, 70 }, // COL_UNICASTSSSENT
{ LVCFMT_RIGHT, 70 }, // COL_UNICASTSREC
{ LVCFMT_RIGHT, 50 }, // COL_UNICASTSTOTAL
{ LVCFMT_RIGHT, 70 }, // COL_UNICASTSSENTPERINTER
{ LVCFMT_RIGHT, 70 }, // COL_UNICASTSRECPERINTER
{ LVCFMT_RIGHT, 70 }, // COL_UNICASTSTOTALPERINTER
{ LVCFMT_RIGHT, 70 }, // COL_NONUNICASTSSSENT
{ LVCFMT_RIGHT, 70 }, // COL_NONUNICASTSREC
{ LVCFMT_RIGHT, 50 }, // COL_NONUNICASTSTOTAL
{ LVCFMT_RIGHT, 70 }, // COL_NONUNICASTSSENTPERINTER
{ LVCFMT_RIGHT, 70 }, // COL_NONUNICASTSRECPERINTER
{ LVCFMT_RIGHT, 70 }, // COL_NONUNICASTSTOTALPERINTER
};
//
// List of the name of the columns. These strings appear in the column header
//
static const int _aIDNetColNames[NUM_NETCOLUMN] =
{
IDS_COL_ADAPTERNAME,
IDS_COL_ADAPTERDESC,
IDS_COL_NETWORKUTIL,
IDS_COL_LINKSPEED,
IDS_COL_STATE,
IDS_COL_BYTESSENTTHRU,
IDS_COL_BYTESRECTHRU,
IDS_COL_BYTESTOTALTHRU,
IDS_COL_BYTESSENT,
IDS_COL_BYTESREC,
IDS_COL_BYTESTOTAL,
IDS_COL_BYTESSENTPERINTER,
IDS_COL_BYTESRECPERINTER,
IDS_COL_BYTESTOTALPERINTER,
IDS_COL_UNICASTSSSENT,
IDS_COL_UNICASTSREC,
IDS_COL_UNICASTSTOTAL,
IDS_COL_UNICASTSSENTPERINTER,
IDS_COL_UNICASTSRECPERINTER,
IDS_COL_UNICASTSTOTALPERINTER,
IDS_COL_NONUNICASTSSSENT,
IDS_COL_NONUNICASTSREC,
IDS_COL_NONUNICASTSTOTAL,
IDS_COL_NONUNICASTSSENTPERINTER,
IDS_COL_NONUNICASTSRECPERINTER,
IDS_COL_NONUNICASTSTOTALPERINTER,
};
//
// List of window checkbox IDs. These check boxes appear in the Select a column diaglog box.
//
const int g_aNetDlgColIDs[] =
{
IDC_ADAPTERNAME,
IDC_ADAPTERDESC,
IDC_NETWORKUTIL,
IDC_LINKSPEED,
IDC_STATE,
IDC_BYTESSENTTHRU,
IDC_BYTESRECTHRU,
IDC_BYTESTOTALTHRU,
IDC_BYTESSENT,
IDC_BYTESREC,
IDC_BYTESTOTAL,
IDC_BYTESSENTPERINTER,
IDC_BYTESRECPERINTER,
IDC_BYTESTOTALPERINTER,
IDC_UNICASTSSSENT,
IDC_UNICASTSREC,
IDC_UNICASTSTOTAL,
IDC_UNICASTSSENTPERINTER,
IDC_UNICASTSRECPERINTER,
IDC_UNICASTSTOTALPERINTER,
IDC_NONUNICASTSSSENT,
IDC_NONUNICASTSREC,
IDC_NONUNICASTSTOTAL,
IDC_NONUNICASTSSENTPERINTER,
IDC_NONUNICASTSRECPERINTER,
IDC_NONUNICASTSTOTALPERINTER,
};
/*++
Routine Description:
Changes the size of an array. Allocates new memory for the array and
copies the data in the old array to the new array. If the new array is
larger then the old array the extra memory is zeroed out.
Arguments:
ppSrc -- Pointer to the source array.
dwNewSize -- The size (in bytes) of the new array.
Return Value:
HRESULT
Revision History:
1-6-2000 Created by omiller
--*/
HRESULT ChangeArraySize(LPVOID *ppSrc, DWORD dwNewSize)
{
if( ppSrc == NULL )
{
return E_INVALIDARG;
}
if( NULL == *ppSrc )
{
//
// The array is empty. Allocate new space for it,
//
*ppSrc = (LPVOID) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwNewSize);
if( NULL == *ppSrc )
{
return E_OUTOFMEMORY;
}
}
else
{
LPVOID pTmp;
//
// The array contains data. Allocate new memory for it and copy over the data in the array.
// If the new array is larger then the old array the extra memory is zeroed out.
//
pTmp = (LPVOID)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *ppSrc, dwNewSize);
if( pTmp )
{
*ppSrc = pTmp;
}
else
{
return E_OUTOFMEMORY;
}
}
return S_OK;
}
/*++
Routine Description:
Initialize all of the CAdapter class members. The CAdapter class
use the Ip Helper api's to collect information about the Network
adapters on the local system.
Arguments:
NONE
Return Value:
VOID
Revision History:
1-6-2000 Created by omiller
--*/
CAdapter::CAdapter()
{
m_dwAdapterCount = 0;
m_ppaiAdapterStats = NULL;
m_pifTable = NULL;
m_bToggle = 0;
m_dwLastReportedNumberOfAdapters = 0;
}
/*++
Routine Description:
Adds any new adapters reported by the IPHLPAPI and removes any old adapters
that are no longer reported by the IPHLPAPI
Arguments:
void
Return Value:
HRESULT
Revision History:
1-6-2000 Created by omiller
--*/
HRESULT CAdapter::RefreshAdapterTable()
{
DWORD dwSize;
DWORD dwRetVal;
BOOLEAN bFound;
HRESULT hr;
LONG i, j;
//
// Get the list of active adapters
//
do
{
//
// Determine the size of the adapter array
//
if ( NULL != m_pifTable )
{
dwSize = (DWORD) HeapSize( GetProcessHeap(), 0, m_pifTable );
}
else
{
dwSize = 0;
}
//
// Collect all of the adapter information for all adapters (WAN and LAN)
//
dwRetVal = GetInterfaceInfo(m_pifTable, &dwSize);
switch(dwRetVal)
{
case ERROR_INSUFFICIENT_BUFFER:
//
// The array is to small. Need to make it bigger and try again.
//
hr = ChangeArraySize( (LPVOID *) &m_pifTable, dwSize );
if( FAILED(hr) )
{
// Unable to expand the size of the array
//
return hr;
}
break;
case NO_ERROR:
//
// Everything is happy
//
break;
case ERROR_MORE_DATA: // Error code 234
// For some reason this error message means that there are no adapters. BUG?
//
m_dwAdapterCount = 0;
return S_FALSE;
default:
// Something went wrong fail.
//
m_dwAdapterCount = 0;
return E_FAIL;
}
}
while(dwRetVal);
//
// Fixed Bug: 669937 Av in taskmgr !CAdapter::RefreshAdapterTable
// Determine which adapters are common in both lists.
//
for(i=0; i<(LONG)m_dwAdapterCount; i++)
{
for(j=0, bFound = FALSE; bFound == FALSE && j<m_pifTable->NumAdapters; j++)
{
if( m_ppaiAdapterStats[i]->ifRowStartStats.dwIndex == m_pifTable->Adapter[j].Index )
{
m_pifTable->Adapter[j].Index = INVALID_VALUE;
bFound = TRUE;
}
}
if( !bFound )
{
if( m_dwAdapterCount > (DWORD)(i+1))
{
memmove(&m_ppaiAdapterStats[i],&m_ppaiAdapterStats[i+1],(m_dwAdapterCount - (i+1)) * sizeof(ADAPTER_INFOEX));
}
m_dwAdapterCount--;
i--;
}
}
//
// Add any new adapters
//
hr = ChangeArraySize( (LPVOID *) &m_ppaiAdapterStats, sizeof(ADAPTER_INFOEX) * min(m_pifTable->NumAdapters,MAX_ADAPTERS));
for(i=0; SUCCEEDED(hr) && i<m_pifTable->NumAdapters; i++)
{
if( m_pifTable->Adapter[i].Index != INVALID_VALUE )
{
hr = InitializeAdapter( &m_ppaiAdapterStats[ m_dwAdapterCount++ ], &m_pifTable->Adapter[ i ] );
}
}
if( FAILED(hr) )
{
m_dwAdapterCount = 0;
}
return hr;
}
/*++
Routine Description:
Update the connection names of the network adapter. This function is only called when the
user selects the refresh menu item. The connection rarely change, so it would be a waste of
time to update the connection name every time the get the adapter statistics.
Arguments:
void
Return Value:
HRESULT
Revision History:
1-6-2000 Created by omiller
--*/
void CAdapter::RefreshConnectionNames()
{
//
// Update the connection name for each adapter in out list
//
for(DWORD dwAdapter=0; dwAdapter < m_dwAdapterCount; dwAdapter++)
{
GetConnectionName( m_ppaiAdapterStats[dwAdapter]->wszGuid
, m_ppaiAdapterStats[dwAdapter]->wszConnectionName
, ARRAYSIZE(m_ppaiAdapterStats[dwAdapter]->wszConnectionName)
);
}
}
/*++
Routine Description:
Get the connection name of an adapter.
Arguments:
pwszAdapterGuid -- The guid of the adapter
pwszConnectionName -- returns the connection name of the adapter
Return Value:
HRESULT
Revision History:
1-6-2000 Created by omiller
--*/
HRESULT CAdapter::GetConnectionName(LPWSTR pwszAdapterGuid, LPWSTR pwszConnectionName, DWORD cchConnectionName)
{
GUID IfGuid;
WCHAR wszConnName[MAXLEN_IFDESCR+1];
DWORD Size;
DWORD dwRetVal;
HRESULT hr;
//
// Make sure the string is NULL terminated
//
Size = sizeof(wszConnName) - sizeof(WCHAR);
wszConnName[MAXLEN_IFDESCR] = L'\0';
//
// Convert the GUID into a string
//
hr = CLSIDFromString( pwszAdapterGuid, &IfGuid );
if( SUCCEEDED(hr) )
{
//
// Use the private IPHLPAPI to get the connection name of the device. Size is the size fo the buffer,
// not the number of chars
//
dwRetVal = NhGetInterfaceNameFromDeviceGuid(&IfGuid, wszConnName, &Size, FALSE, TRUE);
if( NO_ERROR == dwRetVal )
{
StringCchCopy(pwszConnectionName, cchConnectionName, wszConnName);
return S_OK;
}
}
return E_FAIL;
}
/*++
Routine Description:
Initialize the adapter information. i.e. get the adapter name, guid, adapter description and the initial
adapter statistics (bytes sent, bytes recieved etc)
Arguments:
ppaiAdapterStats -- Adapter to initialize
pAdapterDescription -- Information about the adapter (Index and Adapter GUID)
Return Value:
HRESULT
Revision History:
1-6-2000 Created by omiller
--*/
HRESULT CAdapter::InitializeAdapter(PPADAPTER_INFOEX ppaiAdapterStats, PIP_ADAPTER_INDEX_MAP pAdapterDescription)
{
DWORD dwRetVal;
HRESULT hr;
INT iAdapterNameLength;
if( !ppaiAdapterStats || !pAdapterDescription)
{
return E_INVALIDARG;
}
if( NULL == *ppaiAdapterStats )
{
//
// This slot was never used before, we need to allocate memory for it
//
*ppaiAdapterStats = (PADAPTER_INFOEX) HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(**ppaiAdapterStats) );
}
if( *ppaiAdapterStats )
{
//
// Initialize the adapter by filling in all the adapter values.
//
(*ppaiAdapterStats)->ifRowStartStats.dwIndex = (DWORD)pAdapterDescription->Index;
// Get the initial statistics for this adapter
//
dwRetVal = GetIfEntry( &(*ppaiAdapterStats)->ifRowStartStats );
if( NO_ERROR == dwRetVal )
{
if( (*ppaiAdapterStats)->ifRowStartStats.dwType == MIB_IF_TYPE_PPP ||
(*ppaiAdapterStats)->ifRowStartStats.dwType == MIB_IF_TYPE_SLIP)
{
// We only need to adjust the link speed of modems since they compress data causing
// network utilization to exceed 100%. The link speed of modems also changes during a
// connection but the IPHLPAPIs do not report this change.
//
(*ppaiAdapterStats)->bAdjustLinkSpeed = TRUE;
}
else
{
(*ppaiAdapterStats)->bAdjustLinkSpeed = FALSE;
}
//
// Initialize the adapter values. The start current and last stats are all the same at the start
//
memcpy( &(*ppaiAdapterStats)->ifRowStats[0], &(*ppaiAdapterStats)->ifRowStartStats, sizeof((*ppaiAdapterStats)->ifRowStats[0]) );
memcpy( &(*ppaiAdapterStats)->ifRowStats[1], &(*ppaiAdapterStats)->ifRowStartStats, sizeof((*ppaiAdapterStats)->ifRowStats[1]) );
memset( &(*ppaiAdapterStats)->ulHistory[0], INVALID_VALUE, sizeof((*ppaiAdapterStats)->ulHistory[0]) );
memset( &(*ppaiAdapterStats)->ulHistory[1], INVALID_VALUE, sizeof((*ppaiAdapterStats)->ulHistory[1]) );
mbstowcs( (*ppaiAdapterStats)->wszDesc, (LPCSTR)(*ppaiAdapterStats)->ifRowStartStats.bDescr, ARRAYSIZE((*ppaiAdapterStats)->wszDesc) );
//
// Extract the Device guid of the adapter
//
hr = E_FAIL;
iAdapterNameLength = lstrlen(pAdapterDescription->Name);
if( iAdapterNameLength >= GUID_STR_LENGTH )
{
// The Guid is the last GUID_STR_LENGTH chars in the name. Get the guid and from the guid get the connection name
//
StringCchCopy( (*ppaiAdapterStats)->wszGuid
, ARRAYSIZE((*ppaiAdapterStats)->wszGuid)
, &pAdapterDescription->Name[iAdapterNameLength - GUID_STR_LENGTH]
);
hr = GetConnectionName( (*ppaiAdapterStats)->wszGuid
, (*ppaiAdapterStats)->wszConnectionName
, ARRAYSIZE((*ppaiAdapterStats)->wszConnectionName)
);
}
if( FAILED(hr) )
{
//
// We were unable to get the connection name, use the adapter description as the connection name
//
StringCchCopy( (*ppaiAdapterStats)->wszConnectionName
, ARRAYSIZE((*ppaiAdapterStats)->wszConnectionName)
, (*ppaiAdapterStats)->wszDesc
);
}
return S_OK;
}
}
return E_OUTOFMEMORY;
}
/*++
Routine Description:
Adjusts the link speed of an adapter. Modems change link speed during a connection and the also
compress data. This often causes taskmgr to report network utilization greater than 100%. To avoid
confusing the user modems use the max link speed that taskmgr sees. If the link speed changes
the adapters graph is adjusted to reflect the change in link speed.
Arguments:
pAdapterInfo -- Adapter whos link speed needs to be adjusted.
Return Value:
void
Revision History:
1-6-2000 Created by omiller
--*/
void CAdapter::AdjustLinkSpeed(PADAPTER_INFOEX pAdapterInfo)
{
if( pAdapterInfo && pAdapterInfo->ullTickCountDiff)
{
ULONGLONG ullBitsPerSecond;
ULONGLONG ullBytesMoved;
// Compute the total number of bits moved in this interval
//
ullBytesMoved = (pAdapterInfo->ifRowStats[m_bToggle].dwInOctets + pAdapterInfo->ifRowStats[m_bToggle].dwOutOctets) -
(pAdapterInfo->ifRowStats[!m_bToggle].dwInOctets + pAdapterInfo->ifRowStats[!m_bToggle].dwOutOctets);
// Compute the real link speed. Modems lie about there link speed based on the number of bytes moved in this interval
//
ullBitsPerSecond = ullBytesMoved * 8 * 1000 / pAdapterInfo->ullTickCountDiff;
// Memorize and use the highest link speed
//
pAdapterInfo->ifRowStats[m_bToggle].dwSpeed = (DWORD) max( max( ullBitsPerSecond, pAdapterInfo->ullLinkspeed )
, pAdapterInfo->ifRowStats[m_bToggle].dwSpeed
);
if( pAdapterInfo->ullLinkspeed == 0 )
{
// First time run, no need to adjust the graphs
//
pAdapterInfo->ullLinkspeed = (DWORD) pAdapterInfo->ifRowStats[m_bToggle].dwSpeed;
}
else if( pAdapterInfo->ullLinkspeed != pAdapterInfo->ifRowStats[m_bToggle].dwSpeed )
{
// Adjust the points on the adapters graphs to reflect the new link speed.
//
for(DWORD dwPoint=0; dwPoint<HIST_SIZE; dwPoint++)
{
if( pAdapterInfo->ulHistory[BYTES_RECEIVED_UTIL][dwPoint] != INVALID_VALUE )
{
pAdapterInfo->ulHistory[BYTES_RECEIVED_UTIL][dwPoint] = (ULONG)(pAdapterInfo->ulHistory[BYTES_RECEIVED_UTIL][dwPoint] * pAdapterInfo->ullLinkspeed / pAdapterInfo->ifRowStats[m_bToggle].dwSpeed);
pAdapterInfo->ulHistory[BYTES_SENT_UTIL][dwPoint] = (ULONG)(pAdapterInfo->ulHistory[BYTES_SENT_UTIL][dwPoint] * pAdapterInfo->ullLinkspeed / pAdapterInfo->ifRowStats[m_bToggle].dwSpeed);
}
}
// Remember the new linkspeed
//
pAdapterInfo->ullLinkspeed = (DWORD) pAdapterInfo->ifRowStats[m_bToggle].dwSpeed;
}
}
}
/*++
Routine Description:
Every few seconds this function is called to collect data about each of active network adapter
(Adapter name, bytes sent, bytes received, unicasts packets sent, unicast packets received etc).
The CAdapter class memorizes the first and last set of data that it collected. It does this so the
user can determine i.e. the number of bytes sent between now and when taskmgr started and the number
of bytes sent between now and the last interval. Furthermore it memorizes the length of the interval
(in milliseconds)
Arguments:
bAdapterListChange -- Indicates if the adapters have been added or removed.
Return Value:
HRESULT
Note:
The current and last data is stored in a two dimentional array. When the data is collected the next
time (i.e. when this function is called again), the Current data becomes the last data. Inorder to save time
Current and last data are stored in a two dimensional array and m_bToggle is used to indicate which dimenstion
is current (m_bToggle) and which is the last set of data (!m_bToggle).
Revision History:
1-6-2000 Created by omiller
--*/
HRESULT CAdapter::Update(BOOLEAN & bAdapterListChange)
{
DWORD dwRetVal;
DWORD dwNumberOfAdaptersReported = 0;
HRESULT hr = S_OK;
bAdapterListChange = FALSE;
if( m_dwAdapterCount < MAX_ADAPTERS )
{
//
// Check if there are any new adapters. If we already have 32 adapters don't bother, our list is full
// If an Adapter is removed we will catch that later.
//
dwRetVal = GetNumberOfInterfaces( &dwNumberOfAdaptersReported );
if( NO_ERROR == dwRetVal )
{
//
// Make sure the number of interfaces is still the same. If not we need to update our interface table.
//
if( m_dwLastReportedNumberOfAdapters != dwNumberOfAdaptersReported )
{
//
// The number of adapters changed, refresh our list
//
hr = RefreshAdapterTable();
bAdapterListChange = TRUE;
m_dwLastReportedNumberOfAdapters = dwNumberOfAdaptersReported;
}
}
else
{
//
// Unknow error, abort
//
hr = E_FAIL;
}
}
if( SUCCEEDED(hr) )
{
m_bToggle = !m_bToggle;
// Get the statistics for each adapter
//
for(DWORD dwAdapter=0; dwAdapter < m_dwAdapterCount; dwAdapter++)
{
dwRetVal = GetIfEntry(&m_ppaiAdapterStats[dwAdapter]->ifRowStats[m_bToggle]);
if( NO_ERROR == dwRetVal )
{
// Compute the sampling interval for this adapter. If it the first run make sure delta time is 0
// Advance the adapter's throughput history
//
ULONGLONG ullTickCount = GetTickCount();
m_ppaiAdapterStats[dwAdapter]->ullTickCountDiff
= ullTickCount - (m_ppaiAdapterStats[dwAdapter]->ullLastTickCount ? m_ppaiAdapterStats[dwAdapter]->ullLastTickCount : ullTickCount);
m_ppaiAdapterStats[dwAdapter]->ullLastTickCount = ullTickCount;
m_ppaiAdapterStats[dwAdapter]->ifRowStartStats.dwSpeed = m_ppaiAdapterStats[dwAdapter]->ifRowStats[m_bToggle].dwSpeed;
if( m_ppaiAdapterStats[dwAdapter]->bAdjustLinkSpeed )
{
AdjustLinkSpeed(m_ppaiAdapterStats[dwAdapter]);
}
AdvanceAdapterHistory(dwAdapter);
}
else if( ERROR_INVALID_DATA == dwRetVal )
{
// The adapter is no longer active. When the list is refreshed the adapter will be removed.
//
bAdapterListChange = TRUE;
}
else
{
// Something went wrong abort
//
hr = E_FAIL;
break;
}
}
}
if( bAdapterListChange )
{
// Our adapter list is not uptodate, adapters that were active are no longer active. Remove them from our list
//
hr = RefreshAdapterTable();
}
return hr;
}
/*++
Routine Description:
Adds commas into a number string to make it more readable
Arguments:
ullValue - Number to simplify
pwsz - Buffer to store resulting string
cchNumber -- size of the buffer pwsz.
Return Value:
String containing the simplified number
Revision History:
1-6-2000 Created by omiller
--*/
WCHAR * CNetPage::CommaNumber(ULONGLONG ullValue, WCHAR *pwsz, int cchNumber)
{
WCHAR wsz[100];
NUMBERFMT nfmt;
nfmt.NumDigits = 0;
nfmt.LeadingZero = 0;
nfmt.Grouping = UINT(g_ulGroupSep);
nfmt.lpDecimalSep = g_szDecimal;
nfmt.lpThousandSep = g_szGroupThousSep;
nfmt.NegativeOrder = 0;
_ui64tow(ullValue,wsz,10);
GetNumberFormat(LOCALE_USER_DEFAULT,
0,
wsz,
&nfmt,
pwsz,
cchNumber);
return pwsz;
}
/*++
Routine Description:
Simplifies a number by converting the number into Giga, Mega or Kilo
Arguments:
ullValue - Number to simplify
psz - Buffer to store resulting string
bBytes - Indicates if the number is in bytes
Return Value:
String containing the simplified number
Revision History:
1-6-2000 Created by omiller
--*/
WCHAR * CNetPage::SimplifyNumber(ULONGLONG ullValue, WCHAR *psz, DWORD cch)
{
ULONG ulDivValue=1;
LPCWSTR pwszUnit=L"";
WCHAR wsz[100];
// ullValue is not number of bytes so div by 10^X
//
if( ullValue >= 1000000000 )
{
ulDivValue = 1000000000;
pwszUnit = g_szG;
}
else if( ullValue >= 1000000 )
{
ulDivValue = 1000000;
pwszUnit = g_szM;
}
else if( ullValue >= 1000 )
{
ulDivValue = 1000;
pwszUnit = g_szK;
}
//
// Shown in the UI - don't care if these get chopped.
//
StringCchCopy( psz, cch, CommaNumber( ullValue / ulDivValue, wsz, ARRAYSIZE(wsz) ) );
StringCchCat( psz, cch, L" " );
StringCchCat( psz, cch, pwszUnit );
return psz;
}
/*++
Routine Description:
Converts a floating point value (Stored as an integer shifted by PERCENT_SHIFT) into a string
Arguments:
ulValue - floating point value to convert
psz - Buffer to store resulting string
bDisplayDecimal - Indicates if the decimal value should be displayed.
Return Value:
String containg the Floating point string
Revision History:
1-6-2000 Created by omiller
--*/
WCHAR * CNetPage::FloatToString(ULONGLONG ullValue, WCHAR *psz, DWORD cch, BOOLEAN bDisplayDecimal)
{
ULONGLONG ulDecimal = 0;
ULONGLONG ulNumber = 0;
WCHAR wsz[100];
// Get the integer value of the number
//
ulNumber = ullValue / PERCENT_SHIFT;
if( _ui64tow(ulNumber,wsz,10) )
{
StringCchCopy( psz, cch, wsz ); // Shown in UI - don't care if it gets chopped.
if( ulNumber )
{
ullValue = ullValue - ulNumber * PERCENT_SHIFT;
}
if( !ulNumber || bDisplayDecimal)
{
ulDecimal = ullValue * 100 / PERCENT_SHIFT;
if( ulDecimal && _ui64tow(ulDecimal,wsz,10) )
{
StringCchCat( psz, cch, g_szDecimal ); // Shown in UI - don't care if it gets chopped.
if( ulDecimal < 10 )
{
StringCchCat( psz, cch, g_szZero ); // Shown in UI - don't care if it gets chopped.
}
if( wsz[1] == L'0' )
{
wsz[1] = L'\0';
}
StringCchCat( psz, cch, wsz ); // Shown in UI - don't care if it gets chopped.
}
}
}
return psz;
}
/*++
Routine Description:
Initialize the networking tab. This function always returns 1. The networking tab
displays all active connections (LAN and WAN). If no connections are present when
taskmgr is started, the Network tab should still be displayed (thus return 1) incase
a connection is established after taskmgr has started. The network tab will detect any
newly established connections.
Arguments:
None
Return Value:
1
Revision History:
1-6-2000 Created by omiller
--*/
BYTE InitNetInfo()
{
// The network page should always appear even if there are no Network Adapters currently present.
//
return 1;
}
/*++
Routine Description:
Uninitialize all CAdapter class members. Frees all memory that
was allocated by the class.
Arguments:
NONE
Return Value:
VOID
Revision History: