-
Notifications
You must be signed in to change notification settings - Fork 2
/
IpHlpApi.pas
758 lines (572 loc) · 32.1 KB
/
IpHlpApi.pas
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
{******************************************************************************}
{ }
{ Internet Protocol Helper API interface Unit for Object Pascal }
{ }
{ Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
{ Corporation. All Rights Reserved. }
{ }
{ The original file is: iphlpapi.h, released July 2000. The original Pascal }
{ code is: IpHlpApi.pas, released September 2000. The initial developer of the }
{ Pascal code is Marcel van Brakel (brakelm@chello.nl). }
{ }
{ Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
{ Marcel van Brakel. All Rights Reserved. }
{ }
{ Contributor(s): John C. Penman (jcp@craiglockhart.com) }
{ Vladimir Vassiliev (voldemarv@hotpop.com) }
{ }
{ Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
{ }
{ You may retrieve the latest version of this file at the Project JEDI home }
{ page, located at http://delphi-jedi.org or my personal homepage located at }
{ http://members.chello.nl/m.vanbrakel2 }
{ }
{ The contents of this file are used with permission, subject to the Mozilla }
{ Public License Version 1.1 (the "License"); you may not use this file except }
{ in compliance with the License. You may obtain a copy of the License at }
{ http://www.mozilla.org/MPL/MPL-1.1.html }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, }
{ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
{ the specific language governing rights and limitations under the License. }
{ }
{ Alternatively, the contents of this file may be used under the terms of the }
{ GNU Lesser General Public License (the "LGPL License"), in which case the }
{ provisions of the LGPL License are applicable instead of those above. }
{ If you wish to allow use of your version of this file only under the terms }
{ of the LGPL License and not to allow others to use your version of this file }
{ under the MPL, indicate your decision by deleting the provisions above and }
{ replace them with the notice and other provisions required by the LGPL }
{ License. If you do not delete the provisions above, a recipient may use }
{ your version of this file under either the MPL or the LGPL License. }
{ }
{ For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
{ }
{******************************************************************************}
unit IpHlpApi;
{$WEAKPACKAGEUNIT}
{$HPPEMIT ''}
{$HPPEMIT '#include "iphlpapi.h"'}
{$HPPEMIT ''}
//{$I WINDEFINES.INC}
{.$DEFINE IPHLPAPI_LINKONREQUEST}
{$IFDEF IPHLPAPI_LINKONREQUEST}
{$DEFINE IPHLPAPI_DYNLINK}
{$ENDIF}
{.$DEFINE IPHLPAPI_DYNLINK}
interface
uses
Windows, IpExport, IpRtrMib, IpTypes;
//////////////////////////////////////////////////////////////////////////////
// //
// IPRTRMIB.H has the definitions of the strcutures used to set and get //
// information //
// //
//////////////////////////////////////////////////////////////////////////////
// #include <iprtrmib.h>
// #include <ipexport.h>
// #include <iptypes.h>
//////////////////////////////////////////////////////////////////////////////
// //
// The GetXXXTable APIs take a buffer and a size of buffer. If the buffer //
// is not large enough, they APIs return ERROR_INSUFFICIENT_BUFFER and //
// *pdwSize is the required buffer size //
// The bOrder is a BOOLEAN, which if TRUE sorts the table according to //
// MIB-II (RFC XXXX) //
// //
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// //
// Retrieves the number of interfaces in the system. These include LAN and //
// WAN interfaces //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function GetNumberOfInterfaces(var pdwNumIf: DWORD): DWORD; stdcall;
{$EXTERNALSYM GetNumberOfInterfaces}
{$ELSE}
var
GetNumberOfInterfaces: function (var pdwNumIf: DWORD): DWORD; stdcall;
{$EXTERNALSYM GetNumberOfInterfaces}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Gets the MIB-II ifEntry //
// The dwIndex field of the MIB_IFROW should be set to the index of the //
// interface being queried //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function GetIfEntry(pIfRow: PMIB_IFROW): DWORD; stdcall;
{$EXTERNALSYM GetIfEntry}
{$ELSE}
var
GetIfEntry: function (pIfRow: PMIB_IFROW): DWORD; stdcall;
{$EXTERNALSYM GetIfEntry}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Gets the MIB-II IfTable //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function GetIfTable(pIfTable: PMIB_IFTABLE; var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIfTable}
{$ELSE}
var
GetIfTable: function (pIfTable: PMIB_IFTABLE; var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIfTable}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Gets the Interface to IP Address mapping //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function GetIpAddrTable(pIpAddrTable: PMIB_IPADDRTABLE; var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIpAddrTable}
{$ELSE}
var
GetIpAddrTable: function (pIpAddrTable: PMIB_IPADDRTABLE; var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIpAddrTable}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Gets the current IP Address to Physical Address (ARP) mapping //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function GetIpNetTable(pIpNetTable: PMIB_IPNETTABLE; var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIpNetTable}
{$ELSE}
var
GetIpNetTable: function (pIpNetTable: PMIB_IPNETTABLE; var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIpNetTable}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Gets the IP Routing Table (RFX XXXX) //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function GetIpForwardTable(pIpForwardTable: PMIB_IPFORWARDTABLE; var pdwSize: ULONG;
bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIpForwardTable}
{$ELSE}
var
GetIpForwardTable: function (pIpForwardTable: PMIB_IPFORWARDTABLE;
var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIpForwardTable}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Gets TCP Connection/UDP Listener Table //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function GetTcpTable(pTcpTable: PMIB_TCPTABLE; var pdwSize: DWORD; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetTcpTable}
function GetUdpTable(pUdpTable: PMIB_UDPTABLE; var pdwSize: DWORD; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetUdpTable}
{$ELSE}
var
GetTcpTable: function (pTcpTable: PMIB_TCPTABLE; var pdwSize: DWORD; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetTcpTable}
GetUdpTable: function (pUdpTable: PMIB_UDPTABLE; var pdwSize: DWORD; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetUdpTable}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Gets IP/ICMP/TCP/UDP Statistics //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function GetIpStatistics(var pStats: MIB_IPSTATS): DWORD; stdcall;
{$EXTERNALSYM GetIpStatistics}
function GetIcmpStatistics(var pStats: MIB_ICMP): DWORD; stdcall;
{$EXTERNALSYM GetIcmpStatistics}
function GetTcpStatistics(var pStats: MIB_TCPSTATS): DWORD; stdcall;
{$EXTERNALSYM GetTcpStatistics}
function GetUdpStatistics(var pStats: MIB_UDPSTATS): DWORD; stdcall;
{$EXTERNALSYM GetUdpStatistics}
{$ELSE}
var
GetIpStatistics: function (var pStats: MIB_IPSTATS): DWORD; stdcall;
{$EXTERNALSYM GetIpStatistics}
GetIcmpStatistics: function (var pStats: MIB_ICMP): DWORD; stdcall;
{$EXTERNALSYM GetIcmpStatistics}
GetTcpStatistics: function (var pStats: MIB_TCPSTATS): DWORD; stdcall;
{$EXTERNALSYM GetTcpStatistics}
GetUdpStatistics: function (var pStats: MIB_UDPSTATS): DWORD; stdcall;
{$EXTERNALSYM GetUdpStatistics}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Used to set the ifAdminStatus on an interface. The only fields of the //
// MIB_IFROW that are relevant are the dwIndex (index of the interface //
// whose status needs to be set) and the dwAdminStatus which can be either //
// MIB_IF_ADMIN_STATUS_UP or MIB_IF_ADMIN_STATUS_DOWN //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function SetIfEntry(const pIfRow: MIB_IFROW): DWORD; stdcall;
{$EXTERNALSYM SetIfEntry}
{$ELSE}
var
SetIfEntry: function (const pIfRow: MIB_IFROW): DWORD; stdcall;
{$EXTERNALSYM SetIfEntry}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Used to create, modify or delete a route. In all cases the //
// dwForwardIfIndex, dwForwardDest, dwForwardMask, dwForwardNextHop and //
// dwForwardPolicy MUST BE SPECIFIED. Currently dwForwardPolicy is unused //
// and MUST BE 0. //
// For a set, the complete MIB_IPFORWARDROW structure must be specified //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function CreateIpForwardEntry(const pRoute: MIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM CreateIpForwardEntry}
function SetIpForwardEntry(const pRoute: MIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM SetIpForwardEntry}
function DeleteIpForwardEntry(const pRoute: MIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM DeleteIpForwardEntry}
{$ELSE}
var
CreateIpForwardEntry: function (const pRoute: MIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM CreateIpForwardEntry}
SetIpForwardEntry: function (const pRoute: MIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM SetIpForwardEntry}
DeleteIpForwardEntry: function (const pRoute: MIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM DeleteIpForwardEntry}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Used to set the ipForwarding to ON or OFF (currently only ON->OFF is //
// allowed) and to set the defaultTTL. If only one of the fields needs to //
// be modified and the other needs to be the same as before the other field //
// needs to be set to MIB_USE_CURRENT_TTL or MIB_USE_CURRENT_FORWARDING as //
// the case may be //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function SetIpStatistics(const pIpStats: MIB_IPSTATS): DWORD; stdcall;
{$EXTERNALSYM SetIpStatistics}
{$ELSE}
var
SetIpStatistics: function (const pIpStats: MIB_IPSTATS): DWORD; stdcall;
{$EXTERNALSYM SetIpStatistics}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Used to set the defaultTTL. //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function SetIpTTL(nTTL: UINT): DWORD; stdcall;
{$EXTERNALSYM SetIpTTL}
{$ELSE}
SetIpTTL: function (nTTL: UINT): DWORD; stdcall;
{$EXTERNALSYM SetIpTTL}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Used to create, modify or delete an ARP entry. In all cases the dwIndex //
// dwAddr field MUST BE SPECIFIED. //
// For a set, the complete MIB_IPNETROW structure must be specified //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function CreateIpNetEntry(const pArpEntry: MIB_IPNETROW): DWORD; stdcall;
{$EXTERNALSYM CreateIpNetEntry}
function SetIpNetEntry(const pArpEntry: MIB_IPNETROW): DWORD; stdcall;
{$EXTERNALSYM SetIpNetEntry}
function DeleteIpNetEntry(const pArpEntry: MIB_IPNETROW): DWORD; stdcall;
{$EXTERNALSYM DeleteIpNetEntry}
function FlushIpNetTable(dwIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM FlushIpNetTable}
{$ELSE}
var
CreateIpNetEntry: function (const pArpEntry: MIB_IPNETROW): DWORD; stdcall;
{$EXTERNALSYM CreateIpNetEntry}
SetIpNetEntry: function (const pArpEntry: MIB_IPNETROW): DWORD; stdcall;
{$EXTERNALSYM SetIpNetEntry}
DeleteIpNetEntry: function (const pArpEntry: MIB_IPNETROW): DWORD; stdcall;
{$EXTERNALSYM DeleteIpNetEntry}
FlushIpNetTable: function (dwIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM FlushIpNetTable}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Used to create or delete a Proxy ARP entry. The dwIndex is the index of //
// the interface on which to PARP for the dwAddress. If the interface is //
// of a type that doesnt support ARP, e.g. PPP, then the call will fail //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function CreateProxyArpEntry(dwAddress, dwMask, dwIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM CreateProxyArpEntry}
function DeleteProxyArpEntry(dwAddress, dwMask, dwIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM DeleteProxyArpEntry}
{$ELSE}
var
CreateProxyArpEntry: function (dwAddress, dwMask, dwIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM CreateProxyArpEntry}
DeleteProxyArpEntry: function (dwAddress, dwMask, dwIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM DeleteProxyArpEntry}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Used to set the state of a TCP Connection. The only state that it can be //
// set to is MIB_TCP_STATE_DELETE_TCB. The complete MIB_TCPROW structure //
// MUST BE SPECIFIED //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function SetTcpEntry(const pTcpRow: MIB_TCPROW): DWORD; stdcall;
{$EXTERNALSYM SetTcpEntry}
function GetInterfaceInfo(pIfTable: PIP_INTERFACE_INFO; var dwOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetInterfaceInfo}
function GetUniDirectionalAdapterInfo(pIPIfInfo: PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS;
var dwOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetUniDirectionalAdapterInfo(OUT PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo}
{$ELSE}
var
SetTcpEntry: function (const pTcpRow: MIB_TCPROW): DWORD; stdcall;
{$EXTERNALSYM SetTcpEntry}
GetInterfaceInfo: function (pIfTable: PIP_INTERFACE_INFO; var dwOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetInterfaceInfo}
GetUniDirectionalAdapterInfo: function (pIPIfInfo: PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS;
var dwOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetUniDirectionalAdapterInfo(OUT PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Gets the "best" outgoing interface for the specified destination address //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function GetBestInterface(dwDestAddr: IPAddr; var pdwBestIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM GetBestInterface}
{$ELSE}
var
GetBestInterface: function (dwDestAddr: IPAddr; var pdwBestIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM GetBestInterface}
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////
// //
// Gets the best (longest matching prefix) route for the given destination //
// If the source address is also specified (i.e. is not 0x00000000), and //
// there are multiple "best" routes to the given destination, the returned //
// route will be one that goes out over the interface which has an address //
// that matches the source address //
// //
//////////////////////////////////////////////////////////////////////////////
{$IFNDEF IPHLPAPI_DYNLINK}
function GetBestRoute(dwDestAddr, dwSourceAddr: DWORD; pBestRoute: PMIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM GetBestRoute}
function NotifyAddrChange(var Handle: THandle; overlapped: POVERLAPPED): DWORD; stdcall;
{$EXTERNALSYM NotifyAddrChange}
function NotifyRouteChange(var Handle: THandle; overlapped: POVERLAPPED): DWORD; stdcall;
{$EXTERNALSYM NotifyRouteChange}
function GetAdapterIndex(AdapterName: LPWSTR; var IfIndex: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetAdapterIndex}
function AddIPAddress(Address: IPAddr; IpMask: IPMask; IfIndex: DWORD;
var NTEContext, NTEInstance: ULONG): DWORD; stdcall;
{$EXTERNALSYM AddIPAddress}
function DeleteIPAddress(NTEContext: ULONG): DWORD; stdcall;
{$EXTERNALSYM DeleteIPAddress}
function GetNetworkParams(pFixedInfo: PFIXED_INFO; var pOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetNetworkParams}
function GetAdaptersInfo(pAdapterInfo: PIP_ADAPTER_INFO; var pOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetAdaptersInfo}
function GetPerAdapterInfo(IfIndex: ULONG; pPerAdapterInfo: PIP_PER_ADAPTER_INFO;
var pOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetPerAdapterInfo}
function IpReleaseAddress(const AdapterInfo: IP_ADAPTER_INDEX_MAP): DWORD; stdcall;
{$EXTERNALSYM IpReleaseAddress}
function IpRenewAddress(const AdapterInfo: IP_ADAPTER_INDEX_MAP): DWORD; stdcall;
{$EXTERNALSYM IpRenewAddress}
function SendARP(const DestIP, SrcIP: IPAddr; pMacAddr: PULONG; var PhyAddrLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM SendARP}
function GetRTTAndHopCount(DestIpAddress: IPAddr; var HopCount: ULONG;
MaxHops: ULONG; var RTT: ULONG): BOOL; stdcall;
{$EXTERNALSYM GetRTTAndHopCount}
function GetFriendlyIfIndex(IfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM GetFriendlyIfIndex}
function EnableRouter(var pHandle: THandle; pOverlapped: POVERLAPPED): DWORD; stdcall;
{$EXTERNALSYM EnableRouter}
function UnenableRouter(pOverlapped: POVERLAPPED; lpdwEnableCount: LPDWORD): DWORD; stdcall;
{$EXTERNALSYM UnenableRouter}
{$ELSE}
var
GetBestRoute: function (dwDestAddr, dwSourceAddr: DWORD; pBestRoute: PMIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM GetBestRoute}
NotifyAddrChange: function (var Handle: THandle; overlapped: POVERLAPPED): DWORD; stdcall;
{$EXTERNALSYM NotifyAddrChange}
NotifyRouteChange: function (var Handle: THandle; overlapped: POVERLAPPED): DWORD; stdcall;
{$EXTERNALSYM NotifyRouteChange}
GetAdapterIndex: function (AdapterName: LPWSTR; var IfIndex: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetAdapterIndex}
AddIPAddress: function (Address: IPAddr; IpMask: IPMask; IfIndex: DWORD;
var NTEContext, NTEInstance: ULONG): DWORD; stdcall;
{$EXTERNALSYM AddIPAddress}
DeleteIPAddress: function (NTEContext: ULONG): DWORD; stdcall;
{$EXTERNALSYM DeleteIPAddress}
GetNetworkParams: function (pFixedInfo: PFIXED_INFO; var pOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetNetworkParams}
GetAdaptersInfo: function (pAdapterInfo: PIP_ADAPTER_INFO; var pOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetAdaptersInfo}
GetPerAdapterInfo: function (IfIndex: ULONG; pPerAdapterInfo: PIP_PER_ADAPTER_INFO;
var pOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetPerAdapterInfo}
IpReleaseAddress: function (const AdapterInfo: IP_ADAPTER_INDEX_MAP): DWORD; stdcall;
{$EXTERNALSYM IpReleaseAddress}
IpRenewAddress: function (const AdapterInfo: IP_ADAPTER_INDEX_MAP): DWORD; stdcall;
{$EXTERNALSYM IpRenewAddress}
SendARP: function (const DestIP, SrcIP: IPAddr; pMacAddr: PULONG; var PhyAddrLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM SendARP}
GetRTTAndHopCount: function (DestIpAddress: IPAddr; var HopCount: ULONG;
MaxHops: ULONG; var RTT: ULONG): BOOL; stdcall;
{$EXTERNALSYM GetRTTAndHopCount}
GetFriendlyIfIndex: function (IfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM GetFriendlyIfIndex}
EnableRouter: function (var pHandle: THandle; pOverlapped: POVERLAPPED): DWORD; stdcall;
{$EXTERNALSYM EnableRouter}
UnenableRouter: function (pOverlapped: POVERLAPPED; lpdwEnableCount: LPDWORD): DWORD; stdcall;
{$EXTERNALSYM UnenableRouter}
{$ENDIF}
{$IFDEF IPHLPAPI_LINKONREQUEST}
function IpHlpApiInitAPI: Boolean;
procedure IpHlpApiFreeAPI;
{$ENDIF}
function IpHlpApiCheckAPI: Boolean;
implementation
const
iphlpapilib = 'iphlpapi.dll';
{$IFNDEF IPHLPAPI_DYNLINK}
function GetNumberOfInterfaces; external iphlpapilib name 'GetNumberOfInterfaces';
function GetIfEntry; external iphlpapilib name 'GetIfEntry';
function GetIfTable; external iphlpapilib name 'GetIfTable';
function GetIpAddrTable; external iphlpapilib name 'GetIpAddrTable';
function GetIpNetTable; external iphlpapilib name 'GetIpNetTable';
function GetIpForwardTable; external iphlpapilib name 'GetIpForwardTable';
function GetTcpTable; external iphlpapilib name 'GetTcpTable';
function GetUdpTable; external iphlpapilib name 'GetUdpTable';
function GetIpStatistics; external iphlpapilib name 'GetIpStatistics';
function GetIcmpStatistics; external iphlpapilib name 'GetIcmpStatistics';
function GetTcpStatistics; external iphlpapilib name 'GetTcpStatistics';
function GetUdpStatistics; external iphlpapilib name 'GetUdpStatistics';
function SetIfEntry; external iphlpapilib name 'SetIfEntry';
function CreateIpForwardEntry; external iphlpapilib name 'CreateIpForwardEntry';
function SetIpForwardEntry; external iphlpapilib name 'SetIpForwardEntry';
function DeleteIpForwardEntry; external iphlpapilib name 'DeleteIpForwardEntry';
function SetIpStatistics; external iphlpapilib name 'SetIpStatistics';
function SetIpTTL; external iphlpapilib name 'SetIpTTL';
function CreateIpNetEntry; external iphlpapilib name 'CreateIpNetEntry';
function SetIpNetEntry; external iphlpapilib name 'SetIpNetEntry';
function DeleteIpNetEntry; external iphlpapilib name 'DeleteIpNetEntry';
function FlushIpNetTable; external iphlpapilib name 'FlushIpNetTable';
function CreateProxyArpEntry; external iphlpapilib name 'CreateProxyArpEntry';
function DeleteProxyArpEntry; external iphlpapilib name 'DeleteProxyArpEntry';
function SetTcpEntry; external iphlpapilib name 'SetTcpEntry';
function GetInterfaceInfo; external iphlpapilib name 'GetInterfaceInfo';
function GetUniDirectionalAdapterInfo; external iphlpapilib name 'GetUniDirectionalAdapterInfo';
function GetBestInterface; external iphlpapilib name 'GetBestInterface';
function GetBestRoute; external iphlpapilib name 'GetBestRoute';
function NotifyAddrChange; external iphlpapilib name 'NotifyAddrChange';
function NotifyRouteChange; external iphlpapilib name 'NotifyRouteChange';
function GetAdapterIndex; external iphlpapilib name 'GetAdapterIndex';
function AddIPAddress; external iphlpapilib name 'AddIPAddress';
function DeleteIPAddress; external iphlpapilib name 'DeleteIPAddress';
function GetNetworkParams; external iphlpapilib name 'GetNetworkParams';
function GetAdaptersInfo; external iphlpapilib name 'GetAdaptersInfo';
function GetPerAdapterInfo; external iphlpapilib name 'GetPerAdapterInfo';
function IpReleaseAddress; external iphlpapilib name 'IpReleaseAddress';
function IpRenewAddress; external iphlpapilib name 'IpRenewAddress';
function SendARP; external iphlpapilib name 'SendARP';
function GetRTTAndHopCount; external iphlpapilib name 'GetRTTAndHopCount';
function GetFriendlyIfIndex; external iphlpapilib name 'GetFriendlyIfIndex';
function EnableRouter; external iphlpapilib name 'EnableRouter';
function UnenableRouter; external iphlpapilib name 'UnenableRouter';
{$ELSE}
var
HIpHlpApi: THandle = 0;
function IpHlpApiInitAPI: Boolean;
begin
Result := False;
if HIphlpapi = 0 then HIpHlpApi := LoadLibrary(iphlpapilib);
if HIpHlpApi > HINSTANCE_ERROR then
begin
@GetNetworkParams := GetProcAddress(HIpHlpApi, 'GetNetworkParams');
@GetAdaptersInfo := GetProcAddress(HIpHlpApi, 'GetAdaptersInfo');
@GetPerAdapterInfo := GetProcAddress(HIpHlpApi, 'GetPerAdapterInfo');
@GetAdapterIndex := GetProcAddress(HIpHlpApi, 'GetAdapterIndex');
@GetUniDirectionalAdapterInfo := GetProcAddress(HIpHlpApi, 'GetUniDirectionalAdapterInfo');
@GetNumberOfInterfaces := GetProcAddress(HIpHlpApi, 'GetNumberOfInterfaces');
@GetInterfaceInfo := GetProcAddress(HIpHlpApi, 'GetInterfaceInfo');
@GetFriendlyIfIndex := GetProcAddress(HIpHlpApi, 'GetFriendlyIfIndex');
@GetIfTable := GetProcAddress(HIpHlpApi, 'GetIfTable');
@GetIfEntry := GetProcAddress(HIpHlpApi, 'GetIfEntry');
@SetIfEntry := GetProcAddress(HIpHlpApi, 'SetIfEntry');
@GetIpAddrTable := GetProcAddress(HIpHlpApi, 'GetIpAddrTable');
@AddIPAddress := GetProcAddress(HIpHlpApi, 'AddIPAddress');
@DeleteIPAddress := GetProcAddress(HIpHlpApi, 'DeleteIPAddress');
@IpReleaseAddress := GetProcAddress(HIpHlpApi, 'IpReleaseAddress');
@IpRenewAddress := GetProcAddress(HIpHlpApi, 'IpRenewAddress');
@GetIpNetTable := GetProcAddress(HIpHlpApi, 'GetIpNetTable');
@CreateIpNetEntry := GetProcAddress(HIpHlpApi, 'CreateIpNetEntry');
@DeleteIpNetEntry := GetProcAddress(HIpHlpApi, 'DeleteIpNetEntry');
@CreateProxyArpEntry := GetProcAddress(HIpHlpApi, 'CreateProxyArpEntry');
@DeleteProxyArpEntry := GetProcAddress(HIpHlpApi, 'DeleteProxyArpEntry');
@SendARP := GetProcAddress(HIpHlpApi, 'SendARP');
@GetIpStatistics := GetProcAddress(HIpHlpApi, 'GetIpStatistics');
@GetIcmpStatistics := GetProcAddress(HIpHlpApi, 'GetIcmpStatistics');
@SetIpStatistics := GetProcAddress(HIpHlpApi, 'SetIpStatistics');
@SetIpTTL := GetProcAddress(HIpHlpApi, 'SetIpTTL');
@GetIpForwardTable := GetProcAddress(HIpHlpApi,'GetIpForwardTable');
@CreateIpForwardEntry := GetProcAddress(HIpHlpApi, 'CreateIpForwardEntry');
@GetTcpTable := GetProcAddress(HIpHlpApi, 'GetTcpTable');
@GetUdpTable := GetProcAddress(HIpHlpApi, 'GetUdpTable');
@GetTcpStatistics := GetProcAddress(HIpHlpApi, 'GetTcpStatistics');
@GetUdpStatistics := GetProcAddress(HIpHlpApi, 'GetUdpStatistics');
@SetIpForwardEntry := GetProcAddress(HIpHlpApi, 'SetIpForwardEntry');
@DeleteIpForwardEntry := GetProcAddress(HIpHlpApi, 'DeleteIpForwardEntry');
@SetIpNetEntry := GetProcAddress(HIpHlpApi, 'SetIpNetEntry');
@SetTcpEntry := GetProcAddress(HIpHlpApi, 'SetTcpEntry');
@GetBestRoute := GetProcAddress(HIpHlpApi, 'GetBestRoute');
@NotifyAddrChange := GetProcAddress(HIpHlpApi, 'NotifyAddrChange');
@NotifyRouteChange := GetProcAddress(HIpHlpApi, 'NotifyRouteChange');
@GetBestInterface := GetProcAddress(HIpHlpApi, 'GetBestInterface');
@GetRTTAndHopCount := GetProcAddress(HIpHlpApi, 'GetRTTAndHopCount');
@EnableRouter := GetProcAddress(HIpHlpApi, 'EnableRouter');
@UnenableRouter := GetProcAddress(HIpHlpApi, 'UnenableRouter');
Result := True;
end;
end;
procedure IpHlpApiFreeAPI;
begin
if HIpHlpApi <> 0 then FreeLibrary(HIpHlpApi);
HIpHlpApi := 0;
end;
{$ENDIF}
function IpHlpApiCheckAPI: Boolean;
begin
{$IFDEF IPHLPAPI_DYNLINK}
Result := HIpHlpApi <> 0;
{$ELSE}
Result := True;
{$ENDIF}
end;
initialization
{$IFDEF IPHLPAPI_DYNLINK}
{$IFNDEF IPHLPAPI_LINKONREQUEST}
IpHlpApiInitAPI;
{$ENDIF}
{$ENDIF}
finalization
{$IFDEF IPHLPAPI_DYNLINK}
IpHlpApiFreeAPI;
{$ENDIF}
end.