This repository has been archived by the owner on Jan 6, 2020. It is now read-only.
forked from cavaliercoder/sysinv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nics.cpp
669 lines (591 loc) · 29.6 KB
/
nics.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
#include "stdafx.h"
#include "sysinv.h"
#pragma comment(lib, "IPHLPAPI.lib")
#pragma comment(lib, "Ws2_32.lib")
#include <WinSock2.h>
#include <IPHlpApi.h>
#define BUFFER_SIZE 16384
#define IPV4 0x02
#define IPV6 0x17
DWORD IP_TO_UNICODE(LPSOCKADDR addr, DWORD addrLength, LPWSTR szBuffer, LPDWORD bufferSize);
// http://www.iana.org/assignments/ianaiftype-mib/ianaiftype-mib
static LOOKUP_ENTRY IF_TYPES[] = {
{ 1, _T("other"), _T("Other") },
{ 2, _T("regular1822"), _T("Regular 1822") },
{ 3, _T("hdh1822"), _T("HDH1822") },
{ 4, _T("ddnX25"), _T("DDNX25") },
{ 5, _T("rfc877x25"), _T("RFC877x25") },
{ 6, _T("ethernetCsmacd"), _T("Ethernet") },
{ 7, _T("iso88023Csmacd"), _T("Deprecated via RFC3635") },
{ 8, _T("iso88024TokenBus"), _T("Token Bus") },
{ 9, _T("iso88025TokenRing"), _T("Token Ring") },
{ 10, _T("iso88026Man"), _T("") },
{ 11, _T("starLan"), _T("Deprecated via RFC3635") },
{ 12, _T("proteon10Mbit"), _T("Proteon 10Mbit") },
{ 13, _T("proteon80Mbit"), _T("Proteon 80Mbit") },
{ 14, _T("hyperchannel"), _T("HyperChanne;") },
{ 15, _T("fddi"), _T("") },
{ 16, _T("lapb"), _T("") },
{ 17, _T("sdlc"), _T("") },
{ 18, _T("ds1"), _T("DS1-MIB") },
{ 19, _T("e1"), _T("E1") },
{ 20, _T("basicISDN"), _T("Basic ISDN") },
{ 21, _T("primaryISDN"), _T("Primary ISDN") },
{ 22, _T("propPointToPointSerial"), _T("Proprietary PPP Serial") },
{ 23, _T("ppp"), _T("PPP") },
{ 24, _T("softwareLoopback"), _T("Loopback") },
{ 25, _T("eon"), _T("CLNP over IP") },
{ 26, _T("ethernet3Mbit"), _T("") },
{ 27, _T("nsip"), _T("XNS over IP") },
{ 28, _T("slip"), _T("generic SLIP") },
{ 29, _T("ultra"), _T("ULTRA technologies") },
{ 30, _T("ds3"), _T("DS3-MIB") },
{ 31, _T("sip"), _T("SMDS, coffee") },
{ 32, _T("frameRelay"), _T("DTE only.") },
{ 33, _T("rs232"), _T("") },
{ 34, _T("para"), _T("parallel-port") },
{ 35, _T("arcnet"), _T("arcnet") },
{ 36, _T("arcnetPlus"), _T("arcnet plus") },
{ 37, _T("atm"), _T("ATM cells") },
{ 38, _T("miox25"), _T("") },
{ 39, _T("sonet"), _T("SONET or SDH") },
{ 40, _T("x25ple"), _T("") },
{ 41, _T("iso88022llc"), _T("") },
{ 42, _T("localTalk"), _T("") },
{ 43, _T("smdsDxi"), _T("") },
{ 44, _T("frameRelayService"), _T("FRNETSERV-MIB") },
{ 45, _T("v35"), _T("") },
{ 46, _T("hssi"), _T("") },
{ 47, _T("hippi"), _T("") },
{ 48, _T("modem"), _T("Generic modem") },
{ 49, _T("aal5"), _T("AAL5 over ATM") },
{ 50, _T("sonetPath"), _T("") },
{ 51, _T("sonetVT"), _T("") },
{ 52, _T("smdsIcip"), _T("SMDS InterCarrier Interface") },
{ 53, _T("propVirtual"), _T("proprietary virtual/internal") },
{ 54, _T("propMultiplexor"), _T("proprietary multiplexing") },
{ 55, _T("ieee80212"), _T("100BaseVG") },
{ 56, _T("fibreChannel"), _T("Fibre Channel") },
{ 57, _T("hippiInterface"), _T("HIPPI interfaces") },
{ 58, _T("frameRelayInterconnect"), _T("Obsolete, use either") },
{ 59, _T("aflane8023"), _T("ATM Emulated LAN for 802.3") },
{ 60, _T("aflane8025"), _T("ATM Emulated LAN for 802.5") },
{ 61, _T("cctEmul"), _T("ATM Emulated circuit") },
{ 62, _T("fastEther"), _T("Obsoleted via RFC3635") },
{ 63, _T("isdn"), _T("ISDN and X.25") },
{ 64, _T("v11"), _T("CCITT V.11/X.21") },
{ 65, _T("v36"), _T("CCITT V.36") },
{ 66, _T("g703at64k"), _T("CCITT G703 at 64Kbps") },
{ 67, _T("g703at2mb"), _T("Obsolete see DS1-MIB") },
{ 68, _T("qllc"), _T("SNA QLLC") },
{ 69, _T("fastEtherFX"), _T("Obsoleted via RFC3635") },
{ 70, _T("channel"), _T("channel") },
{ 71, _T("ieee80211"), _T("802.11 Wireless") },
{ 72, _T("ibm370parChan"), _T("IBM System 360/370 OEMI Channel") },
{ 73, _T("escon"), _T("IBM Enterprise Systems Connection") },
{ 74, _T("dlsw"), _T("Data Link Switching") },
{ 75, _T("isdns"), _T("ISDN S/T interface") },
{ 76, _T("isdnu"), _T("ISDN U interface") },
{ 77, _T("lapd"), _T("Link Access Protocol D") },
{ 78, _T("ipSwitch"), _T("IP Switching Objects") },
{ 79, _T("rsrb"), _T("Remote Source Route Bridging") },
{ 80, _T("atmLogical"), _T("ATM Logical Port") },
{ 81, _T("ds0"), _T("Digital Signal Level 0") },
{ 82, _T("ds0Bundle"), _T("group of ds0s on the same ds1") },
{ 83, _T("bsc"), _T("Bisynchronous Protocol") },
{ 84, _T("async"), _T("Asynchronous Protocol") },
{ 85, _T("cnr"), _T("Combat Net Radio") },
{ 86, _T("iso88025Dtr"), _T("ISO 802.5r DTR") },
{ 87, _T("eplrs"), _T("Ext Pos Loc Report Sys") },
{ 88, _T("arap"), _T("Appletalk Remote Access Protocol") },
{ 89, _T("propCnls"), _T("Proprietary Connectionless Protocol") },
{ 90, _T("hostPad"), _T("CCITT-ITU X.29 PAD Protocol") },
{ 91, _T("termPad"), _T("CCITT-ITU X.3 PAD Facility") },
{ 92, _T("frameRelayMPI"), _T("Multiproto Interconnect over FR") },
{ 93, _T("x213"), _T("CCITT-ITU X213") },
{ 94, _T("adsl"), _T("Asymmetric Digital Subscriber Loop") },
{ 95, _T("radsl"), _T("Rate-Adapt. Digital Subscriber Loop") },
{ 96, _T("sdsl"), _T("Symmetric Digital Subscriber Loop") },
{ 97, _T("vdsl"), _T("Very H-Speed Digital Subscrib. Loop") },
{ 98, _T("iso88025CRFPInt"), _T("ISO 802.5 CRFP") },
{ 99, _T("myrinet"), _T("Myricom Myrinet") },
{ 100, _T("voiceEM"), _T("voice recEive and transMit") },
{ 101, _T("voiceFXO"), _T("voice Foreign Exchange Office") },
{ 102, _T("voiceFXS"), _T("voice Foreign Exchange Station") },
{ 103, _T("voiceEncap"), _T("voice encapsulation") },
{ 104, _T("voiceOverIp"), _T("voice over IP encapsulation") },
{ 105, _T("atmDxi"), _T("ATM DXI") },
{ 106, _T("atmFuni"), _T("ATM FUNI") },
{ 107, _T("atmIma"), _T("ATM IMA") },
{ 108, _T("pppMultilinkBundle"), _T("PPP Multilink Bundle") },
{ 109, _T("ipOverCdlc"), _T("IBM ipOverCdlc") },
{ 110, _T("ipOverClaw"), _T("IBM Common Link Access to Workstn") },
{ 111, _T("stackToStack"), _T("IBM stackToStack") },
{ 112, _T("virtualIpAddress"), _T("IBM VIPA") },
{ 113, _T("mpc"), _T("IBM multi-protocol channel support") },
{ 114, _T("ipOverAtm"), _T("IBM ipOverAtm") },
{ 115, _T("iso88025Fiber"), _T("ISO 802.5j Fiber Token Ring") },
{ 116, _T("tdlc"), _T("IBM twinaxial data link control") },
{ 117, _T("gigabitEthernet"), _T("Obsoleted via RFC3635") },
{ 118, _T("hdlc"), _T("HDLC") },
{ 119, _T("lapf"), _T("LAP F") },
{ 120, _T("v37"), _T("V.37") },
{ 121, _T("x25mlp"), _T("Multi-Link Protocol") },
{ 122, _T("x25huntGroup"), _T("X25 Hunt Group") },
{ 123, _T("transpHdlc"), _T("Transp HDLC") },
{ 124, _T("interleave"), _T("Interleave channel") },
{ 125, _T("fast"), _T("Fast channel") },
{ 126, _T("ip"), _T("IP (for APPN HPR in IP networks)") },
{ 127, _T("docsCableMaclayer"), _T("CATV Mac Layer") },
{ 128, _T("docsCableDownstream"), _T("CATV Downstream interface") },
{ 129, _T("docsCableUpstream"), _T("CATV Upstream interface") },
{ 130, _T("a12MppSwitch"), _T("Avalon Parallel Processor") },
{ 131, _T("tunnel"), _T("Tunnel Encapsulation") },
{ 132, _T("coffee"), _T("coffee pot") },
{ 133, _T("ces"), _T("Circuit Emulation Service") },
{ 134, _T("atmSubInterface"), _T("ATM Sub Interface") },
{ 135, _T("l2vlan"), _T("Layer 2 Virtual LAN using 802.1Q") },
{ 136, _T("l3ipvlan"), _T("Layer 3 Virtual LAN using IP") },
{ 137, _T("l3ipxvlan"), _T("Layer 3 Virtual LAN using IPX") },
{ 138, _T("digitalPowerline"), _T("IP over Power Lines") },
{ 139, _T("mediaMailOverIp"), _T("Multimedia Mail over IP") },
{ 140, _T("dtm"), _T("Dynamic syncronous Transfer Mode") },
{ 141, _T("dcn"), _T("Data Communications Network") },
{ 142, _T("ipForward"), _T("IP Forwarding Interface") },
{ 143, _T("msdsl"), _T("Multi-rate Symmetric DSL") },
{ 144, _T("ieee1394"), _T("IEEE1394 High Performance Serial Bus") },
{ 145, _T("if-gsn"), _T(" HIPPI-6400") },
{ 146, _T("dvbRccMacLayer"), _T("DVB-RCC MAC Layer") },
{ 147, _T("dvbRccDownstream"), _T("DVB-RCC Downstream Channel") },
{ 148, _T("dvbRccUpstream"), _T("DVB-RCC Upstream Channel") },
{ 149, _T("atmVirtual"), _T("ATM Virtual Interface") },
{ 150, _T("mplsTunnel"), _T("MPLS Tunnel Virtual Interface") },
{ 151, _T("srp"), _T("Spatial Reuse Protocol") },
{ 152, _T("voiceOverAtm"), _T("Voice Over ATM") },
{ 153, _T("voiceOverFrameRelay"), _T("Voice Over Frame Relay") },
{ 154, _T("idsl"), _T("Digital Subscriber Loop over ISDN") },
{ 155, _T("compositeLink"), _T("Avici Composite Link Interface") },
{ 156, _T("ss7SigLink"), _T("SS7 Signaling Link") },
{ 157, _T("propWirelessP2P"), _T(" Prop. P2P wireless interface") },
{ 158, _T("frForward"), _T("Frame Forward Interface") },
{ 159, _T("rfc1483"), _T("Multiprotocol over ATM AAL5") },
{ 160, _T("usb"), _T("USB Interface") },
{ 161, _T("ieee8023adLag"), _T("IEEE 802.3ad Link Aggregate") },
{ 162, _T("bgppolicyaccounting"), _T("BGP Policy Accounting") },
{ 163, _T("frf16MfrBundle"), _T("FRF .16 Multilink Frame Relay") },
{ 164, _T("h323Gatekeeper"), _T("H323 Gatekeeper") },
{ 165, _T("h323Proxy"), _T("H323 Voice and Video Proxy") },
{ 166, _T("mpls"), _T("MPLS") },
{ 167, _T("mfSigLink"), _T("Multi-frequency signaling link") },
{ 168, _T("hdsl2"), _T("High Bit-Rate DSL - 2nd generation") },
{ 169, _T("shdsl"), _T("Multirate HDSL2") },
{ 170, _T("ds1FDL"), _T("Facility Data Link 4Kbps on a DS1") },
{ 171, _T("pos"), _T("Packet over SONET/SDH Interface") },
{ 172, _T("dvbAsiIn"), _T("DVB-ASI Input") },
{ 173, _T("dvbAsiOut"), _T("DVB-ASI Output") },
{ 174, _T("plc"), _T("Power Line Communtications") },
{ 175, _T("nfas"), _T("Non Facility Associated Signaling") },
{ 176, _T("tr008"), _T("TR008") },
{ 177, _T("gr303RDT"), _T("Remote Digital Terminal") },
{ 178, _T("gr303IDT"), _T("Integrated Digital Terminal") },
{ 179, _T("isup"), _T("ISUP") },
{ 180, _T("propDocsWirelessMaclayer"), _T("Cisco proprietary Maclayer") },
{ 181, _T("propDocsWirelessDownstream"), _T("Cisco proprietary Downstream") },
{ 182, _T("propDocsWirelessUpstream"), _T("Cisco proprietary Upstream") },
{ 183, _T("hiperlan2"), _T("HIPERLAN Type 2 Radio Interface") },
{ 184, _T("propBWAp2Mp"), _T("PropBroadbandWirelessAccesspt2multipt") },
{ 185, _T("sonetOverheadChannel"), _T("SONET Overhead Channel") },
{ 186, _T("digitalWrapperOverheadChannel"), _T("Digital Wrapper") },
{ 187, _T("aal2"), _T("ATM adaptation layer 2") },
{ 188, _T("radioMAC"), _T("MAC layer over radio links") },
{ 189, _T("atmRadio"), _T("ATM over radio links") },
{ 190, _T("imt"), _T("Inter Machine Trunks") },
{ 191, _T("mvl"), _T("Multiple Virtual Lines DSL") },
{ 192, _T("reachDSL"), _T("Long Reach DSL") },
{ 193, _T("frDlciEndPt"), _T("Frame Relay DLCI End Point") },
{ 194, _T("atmVciEndPt"), _T("ATM VCI End Point") },
{ 195, _T("opticalChannel"), _T("Optical Channel") },
{ 196, _T("opticalTransport"), _T("Optical Transport") },
{ 197, _T("propAtm"), _T(" Proprietary ATM") },
{ 198, _T("voiceOverCable"), _T("Voice Over Cable Interface") },
{ 199, _T("infiniband"), _T("Infiniband") },
{ 200, _T("teLink"), _T("TE Link") },
{ 201, _T("q2931"), _T("Q.2931") },
{ 202, _T("virtualTg"), _T("Virtual Trunk Group") },
{ 203, _T("sipTg"), _T("SIP Trunk Group") },
{ 204, _T("sipSig"), _T("SIP Signaling") },
{ 205, _T("docsCableUpstreamChannel"), _T("CATV Upstream Channel") },
{ 206, _T("econet"), _T("Acorn Econet") },
{ 207, _T("pon155"), _T("FSAN 155Mb Symetrical PON interface") },
{ 208, _T("pon622"), _T("FSAN622Mb Symetrical PON interface") },
{ 209, _T("bridge"), _T("Transparent bridge interface") },
{ 210, _T("linegroup"), _T("Interface common to multiple lines") },
{ 211, _T("voiceEMFGD"), _T("voice E&M Feature Group D") },
{ 212, _T("voiceFGDEANA"), _T("voice FGD Exchange Access North American") },
{ 213, _T("voiceDID"), _T("voice Direct Inward Dialing") },
{ 214, _T("mpegTransport"), _T("MPEG transport interface") },
{ 215, _T("sixToFour"), _T("6to4 interface (DEPRECATED)") },
{ 216, _T("gtp"), _T("GTP (GPRS Tunneling Protocol)") },
{ 217, _T("pdnEtherLoop1"), _T("Paradyne EtherLoop 1") },
{ 218, _T("pdnEtherLoop2"), _T("Paradyne EtherLoop 2") },
{ 219, _T("opticalChannelGroup"), _T("Optical Channel Group") },
{ 220, _T("homepna"), _T("HomePNA ITU-T G.989") },
{ 221, _T("gfp"), _T("Generic Framing Procedure (GFP)") },
{ 222, _T("ciscoISLvlan"), _T("Layer 2 Virtual LAN using Cisco ISL") },
{ 223, _T("actelisMetaLOOP"), _T("Acteleis proprietary MetaLOOP High Speed Link") },
{ 224, _T("fcipLink"), _T("FCIP Link") },
{ 225, _T("rpr"), _T("Resilient Packet Ring Interface Type") },
{ 226, _T("qam"), _T("RF Qam Interface") },
{ 227, _T("lmp"), _T("Link Management Protocol") },
{ 228, _T("cblVectaStar"), _T("Cambridge Broadband Networks Limited VectaStar") },
{ 229, _T("docsCableMCmtsDownstream"), _T("CATV Modular CMTS Downstream Interface") },
{ 230, _T("adsl2"), _T("Asymmetric Digital Subscriber Loop Version 2") },
{ 231, _T("macSecControlledIF"), _T("MACSecControlled") },
{ 232, _T("macSecUncontrolledIF"), _T("MACSecUncontrolled") },
{ 233, _T("aviciOpticalEther"), _T("Avici Optical Ethernet Aggregate") },
{ 234, _T("atmbond"), _T("atmbond") },
{ 235, _T("voiceFGDOS"), _T("voice FGD Operator Services") },
{ 236, _T("mocaVersion1"), _T("MultiMedia over Coax Alliance (MoCA) Interface") },
{ 237, _T("ieee80216WMAN"), _T("IEEE 802.16 WMAN interface") },
{ 238, _T("adsl2plus"), _T("Asymmetric Digital Subscriber Loop Version 2,") },
{ 239, _T("dvbRcsMacLayer"), _T("DVB-RCS MAC Layer") },
{ 240, _T("dvbTdm"), _T("DVB Satellite TDM") },
{ 241, _T("dvbRcsTdma"), _T("DVB-RCS TDMA") },
{ 242, _T("x86Laps"), _T("LAPS based on ITU-T X.86/Y.1323") },
{ 243, _T("wwanPP"), _T("3GPP WWAN") },
{ 244, _T("wwanPP2"), _T("3GPP2 WWAN") },
{ 245, _T("voiceEBS"), _T("voice P-phone EBS physical interface") },
{ 246, _T("ifPwType"), _T("Pseudowire interface type") },
{ 247, _T("ilan"), _T("Internal LAN on a bridge per IEEE 802.1ap") },
{ 248, _T("pip"), _T("Provider Instance Port on a bridge per IEEE 802.1ah PBB") },
{ 249, _T("aluELP"), _T("Alcatel-Lucent Ethernet Link Protection") },
{ 250, _T("gpon"), _T("Gigabit-capable passive optical networks (G-PON) as per ITU-T G.948") },
{ 251, _T("vdsl2"), _T("Very high speed digital subscriber line Version 2 (as per ITU-T Recommendation G.993.2)") },
{ 252, _T("capwapDot11Profile"), _T("WLAN Profile Interface") },
{ 253, _T("capwapDot11Bss"), _T("WLAN BSS Interface") },
{ 254, _T("capwapWtpVirtualRadio"), _T("WTP Virtual Radio Interface") },
{ 255, _T("bits"), _T("bitsport") },
{ 256, _T("docsCableUpstreamRfPort"), _T("DOCSIS CATV Upstream RF Port") },
{ 257, _T("cableDownstreamRfPort"), _T("CATV downstream RF port") },
{ 258, _T("vmwareVirtualNic"), _T("VMware Virtual Network Interface") },
{ 259, _T("ieee802154"), _T("IEEE 802.15.4 WPAN interface") },
{ 260, _T("otnOdu"), _T("OTN Optical Data Unit") },
{ 261, _T("otnOtu"), _T("OTN Optical channel Transport Unit") },
{ 262, _T("ifVfiType"), _T("VPLS Forwarding Instance Interface Type") },
{ 263, _T("g9981"), _T("G.998.1 bonded interface") },
{ 264, _T("g9982"), _T("G.998.2 bonded interface") },
{ 265, _T("g9983"), _T("G.998.3 bonded interface") },
{ 266, _T("aluEpon"), _T("Ethernet Passive Optical Networks (E-PON)") },
{ 267, _T("aluEponOnu"), _T("EPON Optical Network Unit") },
{ 268, _T("aluEponPhysicalUni"), _T("EPON physical User to Network interface") },
{ 269, _T("aluEponLogicalLink"), _T("The emulation of a point-to-point link over the EPON layer") },
{ 270, _T("aluGponOnu"), _T("GPON Optical Network Unit") },
{ 271, _T("aluGponPhysicalUni"), _T("GPON physical User to Network interface") },
{ 272, _T("vmwareNicTeam"), _T("VMware NIC Team") }
};
// http://www.ietf.org/rfc/rfc2863.txt Pg 31
static LOOKUP_ENTRY IF_OPER_STATUSES[] = {
{ 1, _T("Up"), NULL },
{ 2, _T("Down"), NULL },
{ 3, _T("Testing"), NULL},
{ 4, _T("Unknown"), NULL },
{ 5, _T("Dormant"), NULL },
{ 6, _T("Not present"), NULL },
{ 7, _T("Lower layer down"), NULL }
};
// NET_IF_CONNECTION_TYPE
static LOOKUP_ENTRY IF_CONN_TYPES[] = {
{ NET_IF_CONNECTION_DEDICATED, _T("Dedicated"), NULL },
{ NET_IF_CONNECTION_PASSIVE, _T("Passive"), NULL },
{ NET_IF_CONNECTION_DEMAND, _T("On-Demand"), NULL }
};
// IP_ADAPTER_ADDRESSES.Flags
static LOOKUP_ENTRY IF_FLAGS[] = {
{ IP_ADAPTER_DDNS_ENABLED, NULL, _T("Dynamic DNS is enabled on this adapter.") },
{ IP_ADAPTER_REGISTER_ADAPTER_SUFFIX, NULL, _T("Register the DNS suffix for this adapter.") },
{ IP_ADAPTER_DHCP_ENABLED, NULL, _T("The Dynamic Host Configuration Protocol (DHCP) is enabled on this adapter.") },
{ IP_ADAPTER_RECEIVE_ONLY, NULL, _T("The adapter is a receive-only adapter.") },
{ IP_ADAPTER_NO_MULTICAST, NULL, _T("The adapter is not a multicast recipient.") },
{ IP_ADAPTER_IPV6_OTHER_STATEFUL_CONFIG, NULL, _T("The adapter contains other IPv6-specific stateful configuration information.") },
{ IP_ADAPTER_NETBIOS_OVER_TCPIP_ENABLED, NULL, _T("The adapter is enabled for NetBIOS over TCP/IP.") },
{ IP_ADAPTER_IPV4_ENABLED, NULL, _T("The adapter is enabled for IPv4.") },
{ IP_ADAPTER_IPV6_ENABLED, NULL, _T("The adapter is enabled for IPv6.") },
{ IP_ADAPTER_IPV6_MANAGE_ADDRESS_CONFIG, NULL, _T("The adapter is enabled for IPv6 managed address configuration.") },
};
// IP_PREFIX_ORIGIN
static LOOKUP_ENTRY IP_PREFIX_ORIGINS[] = {
{ IpPrefixOriginOther, _T("Other"), NULL },
{ IpPrefixOriginManual, _T("Manual"), NULL },
{ IpPrefixOriginWellKnown, _T("Well Known"), NULL },
{ IpPrefixOriginDhcp, _T("DHCP"), NULL, },
{ IpPrefixOriginRouterAdvertisement, _T("Router Advertisement"), NULL },
{ IpPrefixOriginUnchanged, _T("Unchanged"), NULL }
};
// IP_SUFFIX_ORIGIN
static LOOKUP_ENTRY IP_SUFFIX_ORIGINS[] = {
{ IpSuffixOriginOther, _T("Other"), NULL },
{ IpSuffixOriginManual, _T("Manual"), NULL },
{ IpSuffixOriginWellKnown, _T("Well Known"), NULL },
{ IpSuffixOriginDhcp, _T("DHCP"), NULL },
{ IpSuffixOriginLinkLayerAddress, _T("Link-Layer Address"), NULL },
{ IpSuffixOriginRandom, _T("Random"), NULL },
{ IpSuffixOriginRandom, _T("Unchanged"), NULL }
};
DWORD IP_TO_UNICODE(LPSOCKADDR addr, DWORD addrLength, LPWSTR szBuffer, LPDWORD bufferSize) {
DWORD dwRetVal = 0;
WSADATA wsaData;
if (0 == WSAStartup(MAKEWORD(1, 1), &wsaData)) {
if (0 != (WSAAddressToString(addr, addrLength, NULL, szBuffer, bufferSize))) {
dwRetVal = WSAGetLastError();
SetError(ERR_CRIT, dwRetVal, _T("Failed to traslate IP Address to String"));
}
else {
dwRetVal = 0;
}
WSACleanup();
}
else {
dwRetVal = GetLastError();
SetError(ERR_CRIT, dwRetVal, _T("Failed to start WSA"));
}
return dwRetVal;
}
PNODE EnumNetworkInterfaces()
{
PNODE nicsNode = node_alloc(_T("Interfaces"), NFLG_TABLE);
PNODE nicNode = NULL;
PNODE linkNode = NULL;
PNODE ipv4Node = NULL;
PNODE ipv4AddressesNode = NULL;
PNODE ipv4DnsServersNode = NULL;
PNODE ipv6Node = NULL;
PNODE ipv6AddressesNode = NULL;
PNODE ipv6DnsServersNode = NULL;
PNODE addressNode = NULL;
PNODE dnsNode = NULL;
ULONG bufferSize = BUFFER_SIZE;
PIP_ADAPTER_ADDRESSES pAddresses = (PIP_ADAPTER_ADDRESSES) MALLOC(bufferSize);
PIP_ADAPTER_ADDRESSES pCurrent = pAddresses;
PIP_ADAPTER_UNICAST_ADDRESS pUnicast = NULL;
PIP_ADAPTER_MULTICAST_ADDRESS pMulticast = NULL;
PIP_ADAPTER_ANYCAST_ADDRESS pAnycast = NULL;
PIP_ADAPTER_DNS_SERVER_ADDRESS pDnsServer = NULL;
ULONG result = 0;
TCHAR szBuffer[SZBUFFERLEN];
LPTSTR pszBuffer = NULL;
DWORD i = 0;
PLOOKUP_ENTRY lookupResult = NULL;
// Get network adapters
while (ERROR_BUFFER_OVERFLOW == (result = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, pAddresses, &bufferSize))){
FREE(pAddresses);
pAddresses = (PIP_ADAPTER_ADDRESSES)MALLOC(bufferSize);
}
// Handle errors
if (ERROR_SUCCESS != result) {
SetError(ERR_CRIT, result, _T("Failed to enumerate Network Adapters."));
return nicsNode;
}
// Parse each adapter
// TODO: Prevent NIC enumeration from reading structure parts not available pre-Vista
while (NULL != pCurrent) {
nicNode = node_append_new(nicsNode, _T("Interface"), NFLG_TABLE_ROW);
linkNode = node_append_new(nicNode, _T("Link"), 0);
ipv4Node = node_append_new(nicNode, _T("IPv4"), 0);
ipv4AddressesNode = node_append_new(ipv4Node, _T("Addresses"), NFLG_TABLE);
ipv4DnsServersNode = node_append_new(ipv4Node, _T("DnsServers"), NFLG_TABLE);
ipv6Node = node_append_new(nicNode, _T("IPv6"), 0);
ipv6AddressesNode = node_append_new(ipv6Node, _T("Addresses"), NFLG_TABLE);
ipv6DnsServersNode = node_append_new(ipv6Node, _T("DnsServers"), NFLG_TABLE);
dnsNode = node_append_new(nicNode, _T("Dns"), 0);
// DEBUG
SWPRINTF(szBuffer, L"%u", pCurrent->Length);
node_att_set(nicNode, L"SIZE", szBuffer, 0);
node_att_set(nicNode, _T("Name"), pCurrent->FriendlyName, NAFLG_KEY);
node_att_set(nicNode, _T("Description"), pCurrent->Description, 0);
UTF8_TO_UNICODE(pCurrent->AdapterName, szBuffer, SZBUFFERLEN);
node_att_set(nicNode, _T("Guid"), szBuffer, NAFLG_FMT_GUID);
// IPv4 Adapter index
SWPRINTF(szBuffer, _T("%u"), pCurrent->IfIndex);
node_att_set(ipv4Node, _T("AdapterIndex"), szBuffer, NAFLG_KEY | NAFLG_FMT_NUMERIC);
// Interface type
if (NULL != (lookupResult = Lookup(IF_TYPES, pCurrent->IfType))) {
node_att_set(nicNode, _T("Type"), lookupResult->Description, 0);
}
else {
node_att_set(nicNode, _T("Type"), _T("Unknown"), NAFLG_ERROR);
SetError(ERR_WARN, 0, _T("Unknown Network Adapter Type: %u"), pCurrent->IfType);
}
// Parse Physical Address (MAC)
if (pCurrent->PhysicalAddressLength) {
pszBuffer = &szBuffer[0];
for (i = 0; i < pCurrent->PhysicalAddressLength; i++) {
if (i < pCurrent->PhysicalAddressLength - 1) {
swprintf_s(pszBuffer, 4, _T("%.2X:"), pCurrent->PhysicalAddress[i]);
pszBuffer += 3;
}
else {
swprintf_s(pszBuffer, 4, _T("%.2X"), pCurrent->PhysicalAddress[i]);
}
}
node_att_set(linkNode, _T("PhysicalAddress"), szBuffer, 0);
}
// Unicast addresses
pUnicast = pCurrent->FirstUnicastAddress;
while (NULL != pUnicast) {
switch (pUnicast->Address.lpSockaddr->sa_family) {
case IPV4:
addressNode = node_append_new(ipv4AddressesNode, _T("Address"), NFLG_TABLE_ROW);
break;
case IPV6:
addressNode = node_append_new(ipv6AddressesNode, _T("Address"), NFLG_TABLE_ROW);
break;
default:
SetError(ERR_WARN, 0, _T("Unknown Unicast IP Address family: %u"), pUnicast->Address.lpSockaddr->sa_family);
continue;
}
node_att_set(addressNode, _T("Type"), _T("Unicast"), 0);
bufferSize = ARRAYSIZE(szBuffer);
if (0 == IP_TO_UNICODE(pUnicast->Address.lpSockaddr, pUnicast->Address.iSockaddrLength, szBuffer, &bufferSize))
node_att_set(addressNode, _T("Address"), szBuffer, NAFLG_FMT_IPADDR);
// Is address a clustered address?
node_att_set_bool(addressNode, _T("Transient"), pUnicast->Flags & IP_ADAPTER_ADDRESS_TRANSIENT, 0);
// Eligible for DNS registration?
node_att_set_bool(addressNode, _T("DnsEligible"), pUnicast->Flags & IP_ADAPTER_ADDRESS_DNS_ELIGIBLE, 0);
// Prefix Origin
if (NULL != (lookupResult = Lookup(IP_PREFIX_ORIGINS, pUnicast->PrefixOrigin))) {
node_att_set(addressNode, _T("PrefixOrigin"), lookupResult->Code, 0);
}
// Suffix origin
if (NULL != (lookupResult = Lookup(IP_SUFFIX_ORIGINS, pUnicast->SuffixOrigin))) {
node_att_set(addressNode, _T("SuffixOrigin"), lookupResult->Code, 0);
}
pUnicast = pUnicast->Next;
}
// Multicast addresses
pMulticast = pCurrent->FirstMulticastAddress;
while (NULL != pMulticast) {
switch (pMulticast->Address.lpSockaddr->sa_family) {
case IPV4:
addressNode = node_append_new(ipv4AddressesNode, _T("Address"), NFLG_TABLE_ROW);
break;
case IPV6:
addressNode = node_append_new(ipv6AddressesNode, _T("Address"), NFLG_TABLE_ROW);
break;
default:
SetError(ERR_WARN, 0, _T("Unknown Multicast IP Address family: %u"), pMulticast->Address.lpSockaddr->sa_family);
continue;
}
node_att_set(addressNode, _T("Type"), _T("Multicast"), 0);
bufferSize = ARRAYSIZE(szBuffer);
if (0 == IP_TO_UNICODE(pMulticast->Address.lpSockaddr, pMulticast->Address.iSockaddrLength, szBuffer, &bufferSize))
node_att_set(addressNode, _T("Address"), szBuffer, 0);
// Is address a clustered address?
node_att_set_bool(addressNode, _T("Transient"), pMulticast->Flags & IP_ADAPTER_ADDRESS_TRANSIENT, 0);
// Eligible for DNS registration?
node_att_set_bool(addressNode, _T("DnsEligible"), pMulticast->Flags & IP_ADAPTER_ADDRESS_DNS_ELIGIBLE, 0);
pMulticast = pMulticast->Next;
}
// Anycast addresses
pAnycast = pCurrent->FirstAnycastAddress;
while (NULL != pAnycast) {
switch (pAnycast->Address.lpSockaddr->sa_family) {
case IPV4:
addressNode = node_append_new(ipv4AddressesNode, _T("Address"), NFLG_TABLE_ROW);
break;
case IPV6:
addressNode = node_append_new(ipv6AddressesNode, _T("Address"), NFLG_TABLE_ROW);
break;
default:
SetError(ERR_WARN, 0, _T("Unknown Anycast IP Address family: %u"), pAnycast->Address.lpSockaddr->sa_family);
continue;
}
bufferSize = ARRAYSIZE(szBuffer);
if (0 == IP_TO_UNICODE(pAnycast->Address.lpSockaddr, pAnycast->Address.iSockaddrLength, szBuffer, &bufferSize))
node_att_set(addressNode, _T("Address"), szBuffer, 0);
// Is address a clustered address?
node_att_set_bool(addressNode, _T("Transient"), pAnycast->Flags & IP_ADAPTER_ADDRESS_TRANSIENT, 0);
// Eligible for DNS registration?
node_att_set_bool(addressNode, _T("DnsEligible"), pAnycast->Flags & IP_ADAPTER_ADDRESS_DNS_ELIGIBLE, 0);
pAnycast = pAnycast->Next;
}
// DNS Servers
i = 0;
pDnsServer = pCurrent->FirstDnsServerAddress;
while (NULL != pDnsServer) {
switch (pDnsServer->Address.lpSockaddr->sa_family) {
case IPV4:
addressNode = node_append_new(ipv4DnsServersNode, _T("DnsServer"), NFLG_TABLE_ROW);
break;
case IPV6:
addressNode = node_append_new(ipv6DnsServersNode, _T("DnsServer"), NFLG_TABLE_ROW);
break;
default:
SetError(ERR_WARN, 0, _T("Unknown DNS Server IP Address family: %u"), pMulticast->Address.lpSockaddr->sa_family);
continue;
}
bufferSize = ARRAYSIZE(szBuffer);
if (0 == IP_TO_UNICODE(pDnsServer->Address.lpSockaddr, pDnsServer->Address.iSockaddrLength, szBuffer, &bufferSize))
node_att_set(addressNode, _T("Address"), szBuffer, 0);
SWPRINTF(szBuffer, _T("%u"), ++i);
node_att_set(addressNode, _T("Index"), szBuffer, 0);
pDnsServer = pDnsServer->Next;
}
// DNS Flags
node_att_set_bool(dnsNode, _T("DynamicDnsEnabled"), IP_ADAPTER_DDNS_ENABLED & pCurrent->Flags, 0);
node_att_set_bool(dnsNode, _T("RegisterSuffix"), IP_ADAPTER_REGISTER_ADAPTER_SUFFIX & pCurrent->Flags, 0);
// IPv4 Flags
node_att_set_bool(ipv4Node, _T("Enabled"), IP_ADAPTER_IPV4_ENABLED & pCurrent->Flags, 0);
node_att_set_bool(ipv4Node, _T("DhcpEnabled"), IP_ADAPTER_DHCP_ENABLED & pCurrent->Flags, 0);
// IPv6 Flags
node_att_set_bool(ipv6Node, _T("Enabled"), IP_ADAPTER_IPV6_ENABLED & pCurrent->Flags, 0);
node_att_set_bool(ipv6Node, _T("StatefulConfig"), IP_ADAPTER_IPV6_OTHER_STATEFUL_CONFIG & pCurrent->Flags, 0);
node_att_set_bool(ipv6Node, _T("ManagedAddressConfig"), IP_ADAPTER_IPV6_MANAGE_ADDRESS_CONFIG & pCurrent->Flags, 0);
// Interface flags
node_att_set_bool(nicNode, _T("ReceiveOnly"), IP_ADAPTER_RECEIVE_ONLY & pCurrent->Flags, 0);
node_att_set_bool(nicNode, _T("MulticastEnabled"), 0 == (IP_ADAPTER_NO_MULTICAST & pCurrent->Flags), 0);
node_att_set_bool(nicNode, _T("NetbiosOverTcpIp"), IP_ADAPTER_NETBIOS_OVER_TCPIP_ENABLED & pCurrent->Flags, 0);
// Maximum Transmission Unit size
SWPRINTF(szBuffer, _T("%llu"), pCurrent->Mtu);
node_att_set(linkNode, _T("MtuSize"), szBuffer, NAFLG_FMT_BYTES);
// Operational status
if (NULL != (lookupResult = Lookup(IF_OPER_STATUSES, pCurrent->OperStatus))) {
node_att_set(linkNode, _T("OperationalState"), lookupResult->Code, 0);
}
else {
node_att_set(linkNode, _T("OperationalState"), _T("Unknown"), NAFLG_ERROR);
SetError(ERR_WARN, 0, _T("Unknown Network Adapter Operational Status: %u"), pCurrent->OperStatus);
}
/*************************/
/* Windows XP/2003 SP1 + */
/*************************/
// IPv6 Adapter index
SWPRINTF(szBuffer, _T("%u"), pCurrent->Ipv6IfIndex);
node_att_set(ipv6Node, _T("AdapterIndex"), szBuffer, NAFLG_KEY | NAFLG_FMT_NUMERIC);
/************************/
/* Windows Vista/2008 + */
/************************/
if (pCurrent->Length <= 144) // Structure size in XP/2003 SP1 is 144
goto next_adapter;
// Connection speed
SWPRINTF(szBuffer, _T("%I64u"), pCurrent->TransmitLinkSpeed);
node_att_set(linkNode, _T("TransmitSpeed"), szBuffer, NAFLG_FMT_NUMERIC);
SWPRINTF(szBuffer, _T("%I64u"), pCurrent->ReceiveLinkSpeed);
node_att_set(linkNode, _T("ReceiveSpeed"), szBuffer, NAFLG_FMT_NUMERIC);
// Connection type
if (NULL != (lookupResult = Lookup(IF_CONN_TYPES, pCurrent->ConnectionType))) {
node_att_set(nicNode, _T("ConnectionType"), lookupResult->Code, 0);
}
else {
node_att_set(nicNode, _T("ConnectionType"), _T("Unknown"), NAFLG_ERROR);
SetError(ERR_WARN, 0, _T("Unknown Connection Type: %u"), pCurrent->IfType);
}
// DNS suffix
node_att_set(dnsNode, _T("DnsSuffix"), pCurrent->DnsSuffix, 0);
/****************************/
/* Windows Vista/2008 SP1 + */
/****************************/
next_adapter:
pCurrent = pCurrent->Next;
}
return nicsNode;
}