请问如何编程实现网卡号与IP地址绑定,即如何实现ARP命令的功能?(100分)

  • 主题发起人 主题发起人 Hexi
  • 开始时间 开始时间
网卡地址与IP地址绑定可以在路由器中设置,与ARP命令有关吗?
 
我知道arp -a .可以看物理地址和ip地址的对应。
 
mfc:
ARP命令可以静态绑定某个IP地址与某个MAC地址,使得非法IP地址不能访问本机。
例如
ARP -s 12-AC-32-32-DC-32 192.168.0.34
如果IP地址为192。168。0。34的网卡的MAC不是12-AC-32-32-DC-32,那么此网卡就无法
使用此IP地址访问本机。
 
》》Hexi
真能实现吗?那太好了!!!
 
hexi: 格式应该为 arp -s (ipaddress) (mcs address)
如果要通过编程实现可以用shellexecute函数。在unit 中添加shellapi单元。
shellexecute(handle,'open','c:/winnt/system32/arp.exe',' -s 192.168.0.34 12-AC-32-32-DC-32',nil,SW_SHOW);
如果是windows9x的路径为c:/windows/arp.exe。
绑定后重启后高速缓存的内容会消失,因此每次启动都要运行 一次。
 
gdd:目前我使用的和你所说的方法一样,但总觉得不好。希望能直接编程实现ARP -s的功能。
 
我也想知道!
 
对于这个问题用ARP当然可以,但要涉及到程序控制,内可能要用到数据链路层的
协议具体的我也不太清楚,希望讨论。

 
提问者:
如果你还要继续讨论请定期提前你的帖子,如果不想继续讨论请结束帖子。
请认真阅读大富翁论坛规则说明

http://www.delphibbs.com/delphibbs/rules.asp
 
现在可以轻轻松松修改网卡地址,绑定的意义不大啊!
 
可以不调用arp.exe来实现。
1、调用Iphlpapi.dll中的CreateIpNetEntry函数。
2、如查ARP表,则用GetIpNetTable函数。
3、注:部分函数如SendARP不受windows9x支持。
以下内容摘自msdn。

The CreateIpNetEntry function creates an Address Resolution Protocol (ARP) entry in the ARP table on the local computer.

DWORD CreateIpNetEntry(
PMIB_IPNETROW pArpEntry // pointer to info for new entry
);
Parameters
pArpEntry
[in] Pointer to a structure that specifies information for the new entry. The caller must specify values for all members of this structure.
Return Values
If the function succeeds, the return value is NO_ERROR.

If the function fails, use to obtain the message string for the returned error.

Requirements
Windows NT/2000 or later: Requires Windows NT 4.0 SP4 or later.
Windows 95/98/Me: Requires Windows 98 or later.
Header: Declared in Iphlpapi.h.
Library: Use Iphlpapi.lib.

See Also
DeleteIpNetEntry, , SetIpNetEntry
 
此问题本人已经解决了,程序付上,备后人使用。
此程序使用IP Help API, 而Delphi没有提供相应的函数声明单元,下面先列出几个单元

IpIfConst单元:

{******************************************************************************}
{ }
{ 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: ipifcons.h, released July 2000. The original Pascal }
{ code is: IpIfCons.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 IpIfConst;

{$WEAKPACKAGEUNIT}

{$HPPEMIT ''}
{$HPPEMIT '#include "ipifcons.h"'}
{$HPPEMIT ''}

//{$I WINDEFINES.INC}

interface

//////////////////////////////////////////////////////////////////////////////
// //
// Media types //
// //
//////////////////////////////////////////////////////////////////////////////

const
MIN_IF_TYPE = 1;
{$EXTERNALSYM MIN_IF_TYPE}

IF_TYPE_OTHER = 1; // None of the below
{$EXTERNALSYM IF_TYPE_OTHER}
IF_TYPE_REGULAR_1822 = 2;
{$EXTERNALSYM IF_TYPE_REGULAR_1822}
IF_TYPE_HDH_1822 = 3;
{$EXTERNALSYM IF_TYPE_HDH_1822}
IF_TYPE_DDN_X25 = 4;
{$EXTERNALSYM IF_TYPE_DDN_X25}
IF_TYPE_RFC877_X25 = 5;
{$EXTERNALSYM IF_TYPE_RFC877_X25}
IF_TYPE_ETHERNET_CSMACD = 6;
{$EXTERNALSYM IF_TYPE_ETHERNET_CSMACD}
IF_TYPE_IS088023_CSMACD = 7;
{$EXTERNALSYM IF_TYPE_IS088023_CSMACD}
IF_TYPE_ISO88024_TOKENBUS = 8;
{$EXTERNALSYM IF_TYPE_ISO88024_TOKENBUS}
IF_TYPE_ISO88025_TOKENRING = 9;
{$EXTERNALSYM IF_TYPE_ISO88025_TOKENRING}
IF_TYPE_ISO88026_MAN = 10;
{$EXTERNALSYM IF_TYPE_ISO88026_MAN}
IF_TYPE_STARLAN = 11;
{$EXTERNALSYM IF_TYPE_STARLAN}
IF_TYPE_PROTEON_10MBIT = 12;
{$EXTERNALSYM IF_TYPE_PROTEON_10MBIT}
IF_TYPE_PROTEON_80MBIT = 13;
{$EXTERNALSYM IF_TYPE_PROTEON_80MBIT}
IF_TYPE_HYPERCHANNEL = 14;
{$EXTERNALSYM IF_TYPE_HYPERCHANNEL}
IF_TYPE_FDDI = 15;
{$EXTERNALSYM IF_TYPE_FDDI}
IF_TYPE_LAP_B = 16;
{$EXTERNALSYM IF_TYPE_LAP_B}
IF_TYPE_SDLC = 17;
{$EXTERNALSYM IF_TYPE_SDLC}
IF_TYPE_DS1 = 18; // DS1-MIB
{$EXTERNALSYM IF_TYPE_DS1}
IF_TYPE_E1 = 19; // Obsolete; see DS1-MIB
{$EXTERNALSYM IF_TYPE_E1}
IF_TYPE_BASIC_ISDN = 20;
{$EXTERNALSYM IF_TYPE_BASIC_ISDN}
IF_TYPE_PRIMARY_ISDN = 21;
{$EXTERNALSYM IF_TYPE_PRIMARY_ISDN}
IF_TYPE_PROP_POINT2POINT_SERIAL = 22; // proprietary serial
{$EXTERNALSYM IF_TYPE_PROP_POINT2POINT_SERIAL}
IF_TYPE_PPP = 23;
{$EXTERNALSYM IF_TYPE_PPP}
IF_TYPE_SOFTWARE_LOOPBACK = 24;
{$EXTERNALSYM IF_TYPE_SOFTWARE_LOOPBACK}
IF_TYPE_EON = 25; // CLNP over IP
{$EXTERNALSYM IF_TYPE_EON}
IF_TYPE_ETHERNET_3MBIT = 26;
{$EXTERNALSYM IF_TYPE_ETHERNET_3MBIT}
IF_TYPE_NSIP = 27; // XNS over IP
{$EXTERNALSYM IF_TYPE_NSIP}
IF_TYPE_SLIP = 28; // Generic Slip
{$EXTERNALSYM IF_TYPE_SLIP}
IF_TYPE_ULTRA = 29; // ULTRA Technologies
{$EXTERNALSYM IF_TYPE_ULTRA}
IF_TYPE_DS3 = 30; // DS3-MIB
{$EXTERNALSYM IF_TYPE_DS3}
IF_TYPE_SIP = 31; // SMDS, coffee
{$EXTERNALSYM IF_TYPE_SIP}
IF_TYPE_FRAMERELAY = 32; // DTE only
{$EXTERNALSYM IF_TYPE_FRAMERELAY}
IF_TYPE_RS232 = 33;
{$EXTERNALSYM IF_TYPE_RS232}
IF_TYPE_PARA = 34; // Parallel port
{$EXTERNALSYM IF_TYPE_PARA}
IF_TYPE_ARCNET = 35;
{$EXTERNALSYM IF_TYPE_ARCNET}
IF_TYPE_ARCNET_PLUS = 36;
{$EXTERNALSYM IF_TYPE_ARCNET_PLUS}
IF_TYPE_ATM = 37; // ATM cells
{$EXTERNALSYM IF_TYPE_ATM}
IF_TYPE_MIO_X25 = 38;
{$EXTERNALSYM IF_TYPE_MIO_X25}
IF_TYPE_SONET = 39; // SONET or SDH
{$EXTERNALSYM IF_TYPE_SONET}
IF_TYPE_X25_PLE = 40;
{$EXTERNALSYM IF_TYPE_X25_PLE}
IF_TYPE_ISO88022_LLC = 41;
{$EXTERNALSYM IF_TYPE_ISO88022_LLC}
IF_TYPE_LOCALTALK = 42;
{$EXTERNALSYM IF_TYPE_LOCALTALK}
IF_TYPE_SMDS_DXI = 43;
{$EXTERNALSYM IF_TYPE_SMDS_DXI}
IF_TYPE_FRAMERELAY_SERVICE = 44; // FRNETSERV-MIB
{$EXTERNALSYM IF_TYPE_FRAMERELAY_SERVICE}
IF_TYPE_V35 = 45;
{$EXTERNALSYM IF_TYPE_V35}
IF_TYPE_HSSI = 46;
{$EXTERNALSYM IF_TYPE_HSSI}
IF_TYPE_HIPPI = 47;
{$EXTERNALSYM IF_TYPE_HIPPI}
IF_TYPE_MODEM = 48; // Generic Modem
{$EXTERNALSYM IF_TYPE_MODEM}
IF_TYPE_AAL5 = 49; // AAL5 over ATM
{$EXTERNALSYM IF_TYPE_AAL5}
IF_TYPE_SONET_PATH = 50;
{$EXTERNALSYM IF_TYPE_SONET_PATH}
IF_TYPE_SONET_VT = 51;
{$EXTERNALSYM IF_TYPE_SONET_VT}
IF_TYPE_SMDS_ICIP = 52; // SMDS InterCarrier Interface
{$EXTERNALSYM IF_TYPE_SMDS_ICIP}
IF_TYPE_PROP_VIRTUAL = 53; // Proprietary virtual/internal
{$EXTERNALSYM IF_TYPE_PROP_VIRTUAL}
IF_TYPE_PROP_MULTIPLEXOR = 54; // Proprietary multiplexing
{$EXTERNALSYM IF_TYPE_PROP_MULTIPLEXOR}
IF_TYPE_IEEE80212 = 55; // 100BaseVG
{$EXTERNALSYM IF_TYPE_IEEE80212}
IF_TYPE_FIBRECHANNEL = 56;
{$EXTERNALSYM IF_TYPE_FIBRECHANNEL}
IF_TYPE_HIPPIINTERFACE = 57;
{$EXTERNALSYM IF_TYPE_HIPPIINTERFACE}
IF_TYPE_FRAMERELAY_INTERCONNECT = 58; // Obsolete, use 32 or 44
{$EXTERNALSYM IF_TYPE_FRAMERELAY_INTERCONNECT}
IF_TYPE_AFLANE_8023 = 59; // ATM Emulated LAN for 802.3
{$EXTERNALSYM IF_TYPE_AFLANE_8023}
IF_TYPE_AFLANE_8025 = 60; // ATM Emulated LAN for 802.5
{$EXTERNALSYM IF_TYPE_AFLANE_8025}
IF_TYPE_CCTEMUL = 61; // ATM Emulated circuit
{$EXTERNALSYM IF_TYPE_CCTEMUL}
IF_TYPE_FASTETHER = 62; // Fast Ethernet (100BaseT)
{$EXTERNALSYM IF_TYPE_FASTETHER}
IF_TYPE_ISDN = 63; // ISDN and X.25
{$EXTERNALSYM IF_TYPE_ISDN}
IF_TYPE_V11 = 64; // CCITT V.11/X.21
{$EXTERNALSYM IF_TYPE_V11}
IF_TYPE_V36 = 65; // CCITT V.36
{$EXTERNALSYM IF_TYPE_V36}
IF_TYPE_G703_64K = 66; // CCITT G703 at 64Kbps
{$EXTERNALSYM IF_TYPE_G703_64K}
IF_TYPE_G703_2MB = 67; // Obsolete; see DS1-MIB
{$EXTERNALSYM IF_TYPE_G703_2MB}
IF_TYPE_QLLC = 68; // SNA QLLC
{$EXTERNALSYM IF_TYPE_QLLC}
IF_TYPE_FASTETHER_FX = 69; // Fast Ethernet (100BaseFX)
{$EXTERNALSYM IF_TYPE_FASTETHER_FX}
IF_TYPE_CHANNEL = 70;
{$EXTERNALSYM IF_TYPE_CHANNEL}
IF_TYPE_IEEE80211 = 71; // Radio spread spectrum
{$EXTERNALSYM IF_TYPE_IEEE80211}
IF_TYPE_IBM370PARCHAN = 72; // IBM System 360/370 OEMI Channel
{$EXTERNALSYM IF_TYPE_IBM370PARCHAN}
IF_TYPE_ESCON = 73; // IBM Enterprise Systems Connection
{$EXTERNALSYM IF_TYPE_ESCON}
IF_TYPE_DLSW = 74; // Data Link Switching
{$EXTERNALSYM IF_TYPE_DLSW}
IF_TYPE_ISDN_S = 75; // ISDN S/T interface
{$EXTERNALSYM IF_TYPE_ISDN_S}
IF_TYPE_ISDN_U = 76; // ISDN U interface
{$EXTERNALSYM IF_TYPE_ISDN_U}
IF_TYPE_LAP_D = 77; // Link Access Protocol D
{$EXTERNALSYM IF_TYPE_LAP_D}
IF_TYPE_IPSWITCH = 78; // IP Switching Objects
{$EXTERNALSYM IF_TYPE_IPSWITCH}
IF_TYPE_RSRB = 79; // Remote Source Route Bridging
{$EXTERNALSYM IF_TYPE_RSRB}
IF_TYPE_ATM_LOGICAL = 80; // ATM Logical Port
{$EXTERNALSYM IF_TYPE_ATM_LOGICAL}
IF_TYPE_DS0 = 81; // Digital Signal Level 0
{$EXTERNALSYM IF_TYPE_DS0}
IF_TYPE_DS0_BUNDLE = 82; // Group of ds0s on the same ds1
{$EXTERNALSYM IF_TYPE_DS0_BUNDLE}
IF_TYPE_BSC = 83; // Bisynchronous Protocol
{$EXTERNALSYM IF_TYPE_BSC}
IF_TYPE_ASYNC = 84; // Asynchronous Protocol
{$EXTERNALSYM IF_TYPE_ASYNC}
IF_TYPE_CNR = 85; // Combat Net Radio
{$EXTERNALSYM IF_TYPE_CNR}
IF_TYPE_ISO88025R_DTR = 86; // ISO 802.5r DTR
{$EXTERNALSYM IF_TYPE_ISO88025R_DTR}
IF_TYPE_EPLRS = 87; // Ext Pos Loc Report Sys
{$EXTERNALSYM IF_TYPE_EPLRS}
IF_TYPE_ARAP = 88; // Appletalk Remote Access Protocol
{$EXTERNALSYM IF_TYPE_ARAP}
IF_TYPE_PROP_CNLS = 89; // Proprietary Connectionless Proto
{$EXTERNALSYM IF_TYPE_PROP_CNLS}
IF_TYPE_HOSTPAD = 90; // CCITT-ITU X.29 PAD Protocol
{$EXTERNALSYM IF_TYPE_HOSTPAD}
IF_TYPE_TERMPAD = 91; // CCITT-ITU X.3 PAD Facility
{$EXTERNALSYM IF_TYPE_TERMPAD}
IF_TYPE_FRAMERELAY_MPI = 92; // Multiproto Interconnect over FR
{$EXTERNALSYM IF_TYPE_FRAMERELAY_MPI}
IF_TYPE_X213 = 93; // CCITT-ITU X213
{$EXTERNALSYM IF_TYPE_X213}
IF_TYPE_ADSL = 94; // Asymmetric Digital Subscrbr Loop
{$EXTERNALSYM IF_TYPE_ADSL}
IF_TYPE_RADSL = 95; // Rate-Adapt Digital Subscrbr Loop
{$EXTERNALSYM IF_TYPE_RADSL}
IF_TYPE_SDSL = 96; // Symmetric Digital Subscriber Loop
{$EXTERNALSYM IF_TYPE_SDSL}
IF_TYPE_VDSL = 97; // Very H-Speed Digital Subscrb Loop
{$EXTERNALSYM IF_TYPE_VDSL}
IF_TYPE_ISO88025_CRFPRINT = 98; // ISO 802.5 CRFP
{$EXTERNALSYM IF_TYPE_ISO88025_CRFPRINT}
IF_TYPE_MYRINET = 99; // Myricom Myrinet
{$EXTERNALSYM IF_TYPE_MYRINET}
IF_TYPE_VOICE_EM = 100; // Voice recEive and transMit
{$EXTERNALSYM IF_TYPE_VOICE_EM}
IF_TYPE_VOICE_FXO = 101; // Voice Foreign Exchange Office
{$EXTERNALSYM IF_TYPE_VOICE_FXO}
IF_TYPE_VOICE_FXS = 102; // Voice Foreign Exchange Station
{$EXTERNALSYM IF_TYPE_VOICE_FXS}
IF_TYPE_VOICE_ENCAP = 103; // Voice encapsulation
{$EXTERNALSYM IF_TYPE_VOICE_ENCAP}
IF_TYPE_VOICE_OVERIP = 104; // Voice over IP encapsulation
{$EXTERNALSYM IF_TYPE_VOICE_OVERIP}
IF_TYPE_ATM_DXI = 105; // ATM DXI
{$EXTERNALSYM IF_TYPE_ATM_DXI}
IF_TYPE_ATM_FUNI = 106; // ATM FUNI
{$EXTERNALSYM IF_TYPE_ATM_FUNI}
IF_TYPE_ATM_IMA = 107; // ATM IMA
{$EXTERNALSYM IF_TYPE_ATM_IMA}
IF_TYPE_PPPMULTILINKBUNDLE = 108; // PPP Multilink Bundle
{$EXTERNALSYM IF_TYPE_PPPMULTILINKBUNDLE}
IF_TYPE_IPOVER_CDLC = 109; // IBM ipOverCdlc
{$EXTERNALSYM IF_TYPE_IPOVER_CDLC}
IF_TYPE_IPOVER_CLAW = 110; // IBM Common Link Access to Workstn
{$EXTERNALSYM IF_TYPE_IPOVER_CLAW}
IF_TYPE_STACKTOSTACK = 111; // IBM stackToStack
{$EXTERNALSYM IF_TYPE_STACKTOSTACK}
IF_TYPE_VIRTUALIPADDRESS = 112; // IBM VIPA
{$EXTERNALSYM IF_TYPE_VIRTUALIPADDRESS}
IF_TYPE_MPC = 113; // IBM multi-proto channel support
{$EXTERNALSYM IF_TYPE_MPC}
IF_TYPE_IPOVER_ATM = 114; // IBM ipOverAtm
{$EXTERNALSYM IF_TYPE_IPOVER_ATM}
IF_TYPE_ISO88025_FIBER = 115; // ISO 802.5j Fiber Token Ring
{$EXTERNALSYM IF_TYPE_ISO88025_FIBER}
IF_TYPE_TDLC = 116; // IBM twinaxial data link control
{$EXTERNALSYM IF_TYPE_TDLC}
IF_TYPE_GIGABITETHERNET = 117;
{$EXTERNALSYM IF_TYPE_GIGABITETHERNET}
IF_TYPE_HDLC = 118;
{$EXTERNALSYM IF_TYPE_HDLC}
IF_TYPE_LAP_F = 119;
{$EXTERNALSYM IF_TYPE_LAP_F}
IF_TYPE_V37 = 120;
{$EXTERNALSYM IF_TYPE_V37}
IF_TYPE_X25_MLP = 121; // Multi-Link Protocol
{$EXTERNALSYM IF_TYPE_X25_MLP}
IF_TYPE_X25_HUNTGROUP = 122; // X.25 Hunt Group
{$EXTERNALSYM IF_TYPE_X25_HUNTGROUP}
IF_TYPE_TRANSPHDLC = 123;
{$EXTERNALSYM IF_TYPE_TRANSPHDLC}
IF_TYPE_INTERLEAVE = 124; // Interleave channel
{$EXTERNALSYM IF_TYPE_INTERLEAVE}
IF_TYPE_FAST = 125; // Fast channel
{$EXTERNALSYM IF_TYPE_FAST}
IF_TYPE_IP = 126; // IP (for APPN HPR in IP networks)
{$EXTERNALSYM IF_TYPE_IP}
IF_TYPE_DOCSCABLE_MACLAYER = 127; // CATV Mac Layer
{$EXTERNALSYM IF_TYPE_DOCSCABLE_MACLAYER}
IF_TYPE_DOCSCABLE_DOWNSTREAM = 128; // CATV Downstream interface
{$EXTERNALSYM IF_TYPE_DOCSCABLE_DOWNSTREAM}
IF_TYPE_DOCSCABLE_UPSTREAM = 129; // CATV Upstream interface
{$EXTERNALSYM IF_TYPE_DOCSCABLE_UPSTREAM}
IF_TYPE_A12MPPSWITCH = 130; // Avalon Parallel Processor
{$EXTERNALSYM IF_TYPE_A12MPPSWITCH}
IF_TYPE_TUNNEL = 131; // Encapsulation interface
{$EXTERNALSYM IF_TYPE_TUNNEL}
IF_TYPE_COFFEE = 132; // Coffee pot
{$EXTERNALSYM IF_TYPE_COFFEE}
IF_TYPE_CES = 133; // Circuit Emulation Service
{$EXTERNALSYM IF_TYPE_CES}
IF_TYPE_ATM_SUBINTERFACE = 134; // ATM Sub Interface
{$EXTERNALSYM IF_TYPE_ATM_SUBINTERFACE}
IF_TYPE_L2_VLAN = 135; // Layer 2 Virtual LAN using 802.1Q
{$EXTERNALSYM IF_TYPE_L2_VLAN}
IF_TYPE_L3_IPVLAN = 136; // Layer 3 Virtual LAN using IP
{$EXTERNALSYM IF_TYPE_L3_IPVLAN}
IF_TYPE_L3_IPXVLAN = 137; // Layer 3 Virtual LAN using IPX
{$EXTERNALSYM IF_TYPE_L3_IPXVLAN}
IF_TYPE_DIGITALPOWERLINE = 138; // IP over Power Lines
{$EXTERNALSYM IF_TYPE_DIGITALPOWERLINE}
IF_TYPE_MEDIAMAILOVERIP = 139; // Multimedia Mail over IP
{$EXTERNALSYM IF_TYPE_MEDIAMAILOVERIP}
IF_TYPE_DTM = 140; // Dynamic syncronous Transfer Mode
{$EXTERNALSYM IF_TYPE_DTM}
IF_TYPE_DCN = 141; // Data Communications Network
{$EXTERNALSYM IF_TYPE_DCN}
IF_TYPE_IPFORWARD = 142; // IP Forwarding Interface
{$EXTERNALSYM IF_TYPE_IPFORWARD}
IF_TYPE_MSDSL = 143; // Multi-rate Symmetric DSL
{$EXTERNALSYM IF_TYPE_MSDSL}
IF_TYPE_IEEE1394 = 144; // IEEE1394 High Perf Serial Bus
{$EXTERNALSYM IF_TYPE_IEEE1394}

MAX_IF_TYPE = 144;
{$EXTERNALSYM MAX_IF_TYPE}

//////////////////////////////////////////////////////////////////////////////
// //
// Access types //
// //
//////////////////////////////////////////////////////////////////////////////

IF_ACCESS_LOOPBACK = 1;
{$EXTERNALSYM IF_ACCESS_LOOPBACK}
IF_ACCESS_BROADCAST = 2;
{$EXTERNALSYM IF_ACCESS_BROADCAST}
IF_ACCESS_POINTTOPOINT = 3;
{$EXTERNALSYM IF_ACCESS_POINTTOPOINT}
IF_ACCESS_POINTTOMULTIPOINT = 4;
{$EXTERNALSYM IF_ACCESS_POINTTOMULTIPOINT}

//////////////////////////////////////////////////////////////////////////////
// //
// Connection Types //
// //
//////////////////////////////////////////////////////////////////////////////

IF_CONNECTION_DEDICATED = 1;
{$EXTERNALSYM IF_CONNECTION_DEDICATED}
IF_CONNECTION_PASSIVE = 2;
{$EXTERNALSYM IF_CONNECTION_PASSIVE}
IF_CONNECTION_DEMAND = 3;
{$EXTERNALSYM IF_CONNECTION_DEMAND}

IF_ADMIN_STATUS_UP = 1;
{$EXTERNALSYM IF_ADMIN_STATUS_UP}
IF_ADMIN_STATUS_DOWN = 2;
{$EXTERNALSYM IF_ADMIN_STATUS_DOWN}
IF_ADMIN_STATUS_TESTING = 3;
{$EXTERNALSYM IF_ADMIN_STATUS_TESTING}

//////////////////////////////////////////////////////////////////////////////
// //
// The following are the the operational states for WAN and LAN interfaces. //
// The order of the states seems weird, but is done for a purpose. All //
// states >= CONNECTED can transmit data right away. States >= DISCONNECTED //
// can tx data but some set up might be needed. States < DISCONNECTED can //
// not transmit data. //
// A card is marked UNREACHABLE if DIM calls InterfaceUnreachable for //
// reasons other than failure to connect. //
// //
// NON_OPERATIONAL -- Valid for LAN Interfaces. Means the card is not //
// working or not plugged in or has no address. //
// UNREACHABLE -- Valid for WAN Interfaces. Means the remote site is //
// not reachable at this time. //
// DISCONNECTED -- Valid for WAN Interfaces. Means the remote site is //
// not connected at this time. //
// CONNECTING -- Valid for WAN Interfaces. Means a connection attempt //
// has been initiated to the remote site. //
// CONNECTED -- Valid for WAN Interfaces. Means the remote site is //
// connected. //
// OPERATIONAL -- Valid for LAN Interfaces. Means the card is plugged //
// in and working. //
// //
// It is the users duty to convert these values to MIB-II values if they //
// are to be used by a subagent //
// //
//////////////////////////////////////////////////////////////////////////////

IF_OPER_STATUS_NON_OPERATIONAL = 0;
{$EXTERNALSYM IF_OPER_STATUS_NON_OPERATIONAL}
IF_OPER_STATUS_UNREACHABLE = 1;
{$EXTERNALSYM IF_OPER_STATUS_UNREACHABLE}
IF_OPER_STATUS_DISCONNECTED = 2;
{$EXTERNALSYM IF_OPER_STATUS_DISCONNECTED}
IF_OPER_STATUS_CONNECTING = 3;
{$EXTERNALSYM IF_OPER_STATUS_CONNECTING}
IF_OPER_STATUS_CONNECTED = 4;
{$EXTERNALSYM IF_OPER_STATUS_CONNECTED}
IF_OPER_STATUS_OPERATIONAL = 5;
{$EXTERNALSYM IF_OPER_STATUS_OPERATIONAL}

MIB_IF_TYPE_OTHER = 1;
{$EXTERNALSYM MIB_IF_TYPE_OTHER}
MIB_IF_TYPE_ETHERNET = 6;
{$EXTERNALSYM MIB_IF_TYPE_ETHERNET}
MIB_IF_TYPE_TOKENRING = 9;
{$EXTERNALSYM MIB_IF_TYPE_TOKENRING}
MIB_IF_TYPE_FDDI = 15;
{$EXTERNALSYM MIB_IF_TYPE_FDDI}
MIB_IF_TYPE_PPP = 23;
{$EXTERNALSYM MIB_IF_TYPE_PPP}
MIB_IF_TYPE_LOOPBACK = 24;
{$EXTERNALSYM MIB_IF_TYPE_LOOPBACK}
MIB_IF_TYPE_SLIP = 28;
{$EXTERNALSYM MIB_IF_TYPE_SLIP}

MIB_IF_ADMIN_STATUS_UP = 1;
{$EXTERNALSYM MIB_IF_ADMIN_STATUS_UP}
MIB_IF_ADMIN_STATUS_DOWN = 2;
{$EXTERNALSYM MIB_IF_ADMIN_STATUS_DOWN}
MIB_IF_ADMIN_STATUS_TESTING = 3;
{$EXTERNALSYM MIB_IF_ADMIN_STATUS_TESTING}

MIB_IF_OPER_STATUS_NON_OPERATIONAL = 0;
{$EXTERNALSYM MIB_IF_OPER_STATUS_NON_OPERATIONAL}
MIB_IF_OPER_STATUS_UNREACHABLE = 1;
{$EXTERNALSYM MIB_IF_OPER_STATUS_UNREACHABLE}
MIB_IF_OPER_STATUS_DISCONNECTED = 2;
{$EXTERNALSYM MIB_IF_OPER_STATUS_DISCONNECTED}
MIB_IF_OPER_STATUS_CONNECTING = 3;
{$EXTERNALSYM MIB_IF_OPER_STATUS_CONNECTING}
MIB_IF_OPER_STATUS_CONNECTED = 4;
{$EXTERNALSYM MIB_IF_OPER_STATUS_CONNECTED}
MIB_IF_OPER_STATUS_OPERATIONAL = 5;
{$EXTERNALSYM MIB_IF_OPER_STATUS_OPERATIONAL}

implementation

end.


IPTypes单元

{******************************************************************************}
{ }
{ 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: iptypes.h, released July 2000. The original Pascal }
{ code is: IpTypes.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 IpTypes;

{$WEAKPACKAGEUNIT}

{$HPPEMIT ''}
{$HPPEMIT '#include "iptypes.h"'}
{$HPPEMIT ''}

//{$I WINDEFINES.INC}

interface

uses
Windows;

type
// #include <time.h>
time_t = Longint;
{$EXTERNALSYM time_t}

// Definitions and structures used by getnetworkparams and getadaptersinfo apis

const
MAX_ADAPTER_DESCRIPTION_LENGTH = 128; // arb.
{$EXTERNALSYM MAX_ADAPTER_DESCRIPTION_LENGTH}
MAX_ADAPTER_NAME_LENGTH = 256; // arb.
{$EXTERNALSYM MAX_ADAPTER_NAME_LENGTH}
MAX_ADAPTER_ADDRESS_LENGTH = 8; // arb.
{$EXTERNALSYM MAX_ADAPTER_ADDRESS_LENGTH}
DEFAULT_MINIMUM_ENTITIES = 32; // arb.
{$EXTERNALSYM DEFAULT_MINIMUM_ENTITIES}
MAX_HOSTNAME_LEN = 128; // arb.
{$EXTERNALSYM MAX_HOSTNAME_LEN}
MAX_DOMAIN_NAME_LEN = 128; // arb.
{$EXTERNALSYM MAX_DOMAIN_NAME_LEN}
MAX_SCOPE_ID_LEN = 256; // arb.
{$EXTERNALSYM MAX_SCOPE_ID_LEN}

//
// types
//

// Node Type

BROADCAST_NODETYPE = 1;
{$EXTERNALSYM BROADCAST_NODETYPE}
PEER_TO_PEER_NODETYPE = 2;
{$EXTERNALSYM PEER_TO_PEER_NODETYPE}
MIXED_NODETYPE = 4;
{$EXTERNALSYM MIXED_NODETYPE}
HYBRID_NODETYPE = 8;
{$EXTERNALSYM HYBRID_NODETYPE}

// Adapter Type

IF_OTHER_ADAPTERTYPE = 0;
{$EXTERNALSYM IF_OTHER_ADAPTERTYPE}
IF_ETHERNET_ADAPTERTYPE = 1;
{$EXTERNALSYM IF_ETHERNET_ADAPTERTYPE}
IF_TOKEN_RING_ADAPTERTYPE = 2;
{$EXTERNALSYM IF_TOKEN_RING_ADAPTERTYPE}
IF_FDDI_ADAPTERTYPE = 3;
{$EXTERNALSYM IF_FDDI_ADAPTERTYPE}
IF_PPP_ADAPTERTYPE = 4;
{$EXTERNALSYM IF_PPP_ADAPTERTYPE}
IF_LOOPBACK_ADAPTERTYPE = 5;
{$EXTERNALSYM IF_LOOPBACK_ADAPTERTYPE}
IF_SLIP_ADAPTERTYPE = 6;
{$EXTERNALSYM IF_SLIP_ADAPTERTYPE}

//
// IP_ADDRESS_STRING - store an IP address as a dotted decimal string
//

type
PIP_MASK_STRING = ^IP_MASK_STRING;
{$EXTERNALSYM PIP_MASK_STRING}
IP_ADDRESS_STRING = record
S: array [0..15] of Char;
end;
{$EXTERNALSYM IP_ADDRESS_STRING}
PIP_ADDRESS_STRING = ^IP_ADDRESS_STRING;
{$EXTERNALSYM PIP_ADDRESS_STRING}
IP_MASK_STRING = IP_ADDRESS_STRING;
{$EXTERNALSYM IP_MASK_STRING}
TIpAddressString = IP_ADDRESS_STRING;
PIpAddressString = PIP_MASK_STRING;

//
// IP_ADDR_STRING - store an IP address with its corresponding subnet mask,
// both as dotted decimal strings
//

PIP_ADDR_STRING = ^IP_ADDR_STRING;
{$EXTERNALSYM PIP_ADDR_STRING}
_IP_ADDR_STRING = record
Next: PIP_ADDR_STRING;
IpAddress: IP_ADDRESS_STRING;
IpMask: IP_MASK_STRING;
Context: DWORD;
end;
{$EXTERNALSYM _IP_ADDR_STRING}
IP_ADDR_STRING = _IP_ADDR_STRING;
{$EXTERNALSYM IP_ADDR_STRING}
TIpAddrString = IP_ADDR_STRING;
PIpAddrString = PIP_ADDR_STRING;

//
// ADAPTER_INFO - per-adapter information. All IP addresses are stored as
// strings
//

PIP_ADAPTER_INFO = ^IP_ADAPTER_INFO;
{$EXTERNALSYM PIP_ADAPTER_INFO}
_IP_ADAPTER_INFO = record
Next: PIP_ADAPTER_INFO;
ComboIndex: DWORD;
AdapterName: array [0..MAX_ADAPTER_NAME_LENGTH + 3] of Char;
Description: array [0..MAX_ADAPTER_DESCRIPTION_LENGTH + 3] of Char;
AddressLength: UINT;
Address: array [0..MAX_ADAPTER_ADDRESS_LENGTH - 1] of BYTE;
Index: DWORD;
Type_: UINT;
DhcpEnabled: UINT;
CurrentIpAddress: PIP_ADDR_STRING;
IpAddressList: IP_ADDR_STRING;
GatewayList: IP_ADDR_STRING;
DhcpServer: IP_ADDR_STRING;
HaveWins: BOOL;
PrimaryWinsServer: IP_ADDR_STRING;
SecondaryWinsServer: IP_ADDR_STRING;
LeaseObtained: time_t;
LeaseExpires: time_t;
end;
{$EXTERNALSYM _IP_ADAPTER_INFO}
IP_ADAPTER_INFO = _IP_ADAPTER_INFO;
{$EXTERNALSYM IP_ADAPTER_INFO}
TIpAdapterInfo = IP_ADAPTER_INFO;
PIpAdapterInfo = PIP_ADAPTER_INFO;

//
// IP_PER_ADAPTER_INFO - per-adapter IP information such as DNS server list.
//

PIP_PER_ADAPTER_INFO = ^IP_PER_ADAPTER_INFO;
{$EXTERNALSYM PIP_PER_ADAPTER_INFO}
_IP_PER_ADAPTER_INFO = record
AutoconfigEnabled: UINT;
AutoconfigActive: UINT;
CurrentDnsServer: PIP_ADDR_STRING;
DnsServerList: IP_ADDR_STRING;
end;
{$EXTERNALSYM _IP_PER_ADAPTER_INFO}
IP_PER_ADAPTER_INFO = _IP_PER_ADAPTER_INFO;
{$EXTERNALSYM IP_PER_ADAPTER_INFO}
TIpPerAdapterInfo = IP_PER_ADAPTER_INFO;
PIpPerAdapterInfo = PIP_PER_ADAPTER_INFO;

//
// FIXED_INFO - the set of IP-related information which does not depend on DHCP
//

PFIXED_INFO = ^FIXED_INFO;
{$EXTERNALSYM PFIXED_INFO}
FIXED_INFO = record
HostName: array [0..MAX_HOSTNAME_LEN + 3] of Char;
DomainName: array[0..MAX_DOMAIN_NAME_LEN + 3] of Char;
CurrentDnsServer: PIP_ADDR_STRING;
DnsServerList: IP_ADDR_STRING;
NodeType: UINT;
ScopeId: array [0..MAX_SCOPE_ID_LEN + 3] of Char;
EnableRouting: UINT;
EnableProxy: UINT;
EnableDns: UINT;
end;
{$EXTERNALSYM FIXED_INFO}
TFixedInfo = FIXED_INFO;
PFixedInfo = PFIXED_INFO;

implementation

end.

接下:
 
[red]IpHlpApi[/red]
{******************************************************************************}
{ }
{ 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.
 
[red]IPExport单元[/red]

{******************************************************************************}
{ }
{ 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: ipexport.h, released July 2000. The original Pascal }
{ code is: IpExport.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 IpExport;

{$WEAKPACKAGEUNIT}

{$HPPEMIT ''}
{$HPPEMIT '#include "ipexport.h"'}
{$HPPEMIT ''}

//{$I WINDEFINES.INC}

interface

uses
Windows;

//
// IP type definitions.
//

type
IPAddr = Cardinal; // An IP address.
{$EXTERNALSYM IPAddr}
IPMask = Cardinal; // An IP subnet mask.
{$EXTERNALSYM IPMask}
IP_STATUS = Cardinal; // Status code returned from IP APIs.
{$EXTERNALSYM IP_STATUS}

//
// The ip_option_information structure describes the options to be
// included in the header of an IP packet. The TTL, TOS, and Flags
// values are carried in specific fields in the header. The OptionsData
// bytes are carried in the options area following the standard IP header.
// With the exception of source route options, this data must be in the
// format to be transmitted on the wire as specified in RFC 791. A source
// route option should contain the full route - first hop thru final
// destination - in the route data. The first hop will be pulled out of the
// data and the option will be reformatted accordingly. Otherwise, the route
// option should be formatted as specified in RFC 791.
//

type
ip_option_information = record
Ttl: Byte; // Time To Live
Tos: Byte; // Type Of Service
Flags: Byte; // IP header flags
OptionsSize: Byte; // Size in bytes of options data
OptionsData: PByte; // Pointer to options data
end;
{$EXTERNALSYM ip_option_information}
TIpOptionInformation = ip_option_information;
PIpOptionInformation = ^ip_option_information;

//
// The icmp_echo_reply structure describes the data returned in response
// to an echo request.
//

icmp_echo_reply = record
Address: IPAddr; // Replying address
Status: Cardinal; // Reply IP_STATUS
RoundTripTime: Cardinal; // RTT in milliseconds
DataSize: Word; // Reply data size in bytes
Reserved: Word; // Reserved for system use
Data: Pointer; // Pointer to the reply data
Options: ip_option_information; // Reply options
end;
{$EXTERNALSYM icmp_echo_reply}
PIP_OPTION_INFORMATION = ^IP_OPTION_INFORMATION;
{$EXTERNALSYM PIP_OPTION_INFORMATION}
PICMP_ECHO_REPLY = ^ICMP_ECHO_REPLY;
{$EXTERNALSYM PICMP_ECHO_REPLY}
TIcmpEchoReply = icmp_echo_reply;
PIcmpEchoReply = PICMP_ECHO_REPLY;

PARP_SEND_REPLY = ^ARP_SEND_REPLY;
{$EXTERNALSYM PARP_SEND_REPLY}
ArpRequestBuffer = record
DestAddress: IPAddr;
SrcAddress: IPAddr;
end;
{$EXTERNALSYM ArpRequestBuffer}
ARP_SEND_REPLY = ArpRequestBuffer;
{$EXTERNALSYM ARP_SEND_REPLY}
TArpRequestBuffer = ARP_SEND_REPLY;
PArpRequestBuffer = PARP_SEND_REPLY;

_TCP_RESERVE_PORT_RANGE = record
UpperRange: Word;
LowerRange: Word;
end;
{$EXTERNALSYM _TCP_RESERVE_PORT_RANGE}
TCP_RESERVE_PORT_RANGE = _TCP_RESERVE_PORT_RANGE;
{$EXTERNALSYM TCP_RESERVE_PORT_RANGE}
TTcpReservePortRange = _TCP_RESERVE_PORT_RANGE;
PTcpReservePortRange = ^TCP_RESERVE_PORT_RANGE;

const
MAX_ADAPTER_NAME = 128;
{$EXTERNALSYM MAX_ADAPTER_NAME}

type
PIP_ADAPTER_INDEX_MAP = ^IP_ADAPTER_INDEX_MAP;
{$EXTERNALSYM PIP_ADAPTER_INDEX_MAP}
_IP_ADAPTER_INDEX_MAP = record
Index: ULONG;
Name: array [0..MAX_ADAPTER_NAME - 1] of WCHAR;
end;
{$EXTERNALSYM _IP_ADAPTER_INDEX_MAP}
IP_ADAPTER_INDEX_MAP = _IP_ADAPTER_INDEX_MAP;
{$EXTERNALSYM IP_ADAPTER_INDEX_MAP}
TIpAdapterIndexMap = IP_ADAPTER_INDEX_MAP;
PIpAdapterIndexMap = PIP_ADAPTER_INDEX_MAP;

PIP_INTERFACE_INFO = ^IP_INTERFACE_INFO;
{$EXTERNALSYM PIP_INTERFACE_INFO}
_IP_INTERFACE_INFO = record
NumAdapters: Longint;
Adapter: array [0..0] of IP_ADAPTER_INDEX_MAP;
end;
{$EXTERNALSYM _IP_INTERFACE_INFO}
IP_INTERFACE_INFO = _IP_INTERFACE_INFO;
{$EXTERNALSYM IP_INTERFACE_INFO}
TIpInterfaceInfo = IP_INTERFACE_INFO;
PIpInterfaceInfo = PIP_INTERFACE_INFO;

PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS = ^IP_UNIDIRECTIONAL_ADAPTER_ADDRESS;
{$EXTERNALSYM PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS}
_IP_UNIDIRECTIONAL_ADAPTER_ADDRESS = record
NumAdapters: ULONG;
Address: array [0..0] of IPAddr;
end;
{$EXTERNALSYM _IP_UNIDIRECTIONAL_ADAPTER_ADDRESS}
IP_UNIDIRECTIONAL_ADAPTER_ADDRESS = _IP_UNIDIRECTIONAL_ADAPTER_ADDRESS;
{$EXTERNALSYM IP_UNIDIRECTIONAL_ADAPTER_ADDRESS}
TIpUnidirectionalAdapterAddress = IP_UNIDIRECTIONAL_ADAPTER_ADDRESS;
PIpUnidirectionalAdapterAddress = PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS;

PIP_ADAPTER_ORDER_MAP = ^IP_ADAPTER_ORDER_MAP;
{$EXTERNALSYM PIP_ADAPTER_ORDER_MAP}
_IP_ADAPTER_ORDER_MAP = record
NumAdapters: ULONG;
AdapterOrder: array [0..0] of ULONG;
end;
{$EXTERNALSYM _IP_ADAPTER_ORDER_MAP}
IP_ADAPTER_ORDER_MAP = _IP_ADAPTER_ORDER_MAP;
{$EXTERNALSYM IP_ADAPTER_ORDER_MAP}
TIpAdapterOrderMap = IP_ADAPTER_ORDER_MAP;
PIpAdapterOrderMap = PIP_ADAPTER_ORDER_MAP;

//
// IP_STATUS codes returned from IP APIs
//

const
IP_STATUS_BASE = 11000;
{$EXTERNALSYM IP_STATUS_BASE}

IP_SUCCESS = 0;
{$EXTERNALSYM IP_SUCCESS}
IP_BUF_TOO_SMALL = IP_STATUS_BASE + 1;
{$EXTERNALSYM IP_BUF_TOO_SMALL}
IP_DEST_NET_UNREACHABLE = IP_STATUS_BASE + 2;
{$EXTERNALSYM IP_DEST_NET_UNREACHABLE}
IP_DEST_HOST_UNREACHABLE = IP_STATUS_BASE + 3;
{$EXTERNALSYM IP_DEST_HOST_UNREACHABLE}
IP_DEST_PROT_UNREACHABLE = IP_STATUS_BASE + 4;
{$EXTERNALSYM IP_DEST_PROT_UNREACHABLE}
IP_DEST_PORT_UNREACHABLE = IP_STATUS_BASE + 5;
{$EXTERNALSYM IP_DEST_PORT_UNREACHABLE}
IP_NO_RESOURCES = IP_STATUS_BASE + 6;
{$EXTERNALSYM IP_NO_RESOURCES}
IP_BAD_OPTION = IP_STATUS_BASE + 7;
{$EXTERNALSYM IP_BAD_OPTION}
IP_HW_ERROR = IP_STATUS_BASE + 8;
{$EXTERNALSYM IP_HW_ERROR}
IP_PACKET_TOO_BIG = IP_STATUS_BASE + 9;
{$EXTERNALSYM IP_PACKET_TOO_BIG}
IP_REQ_TIMED_OUT = IP_STATUS_BASE + 10;
{$EXTERNALSYM IP_REQ_TIMED_OUT}
IP_BAD_REQ = IP_STATUS_BASE + 11;
{$EXTERNALSYM IP_BAD_REQ}
IP_BAD_ROUTE = IP_STATUS_BASE + 12;
{$EXTERNALSYM IP_BAD_ROUTE}
IP_TTL_EXPIRED_TRANSIT = IP_STATUS_BASE + 13;
{$EXTERNALSYM IP_TTL_EXPIRED_TRANSIT}
IP_TTL_EXPIRED_REASSEM = IP_STATUS_BASE + 14;
{$EXTERNALSYM IP_TTL_EXPIRED_REASSEM}
IP_PARAM_PROBLEM = IP_STATUS_BASE + 15;
{$EXTERNALSYM IP_PARAM_PROBLEM}
IP_SOURCE_QUENCH = IP_STATUS_BASE + 16;
{$EXTERNALSYM IP_SOURCE_QUENCH}
IP_OPTION_TOO_BIG = IP_STATUS_BASE + 17;
{$EXTERNALSYM IP_OPTION_TOO_BIG}
IP_BAD_DESTINATION = IP_STATUS_BASE + 18;
{$EXTERNALSYM IP_BAD_DESTINATION}

//
// The next group are status codes passed up on status indications to
// transport layer protocols.
//

IP_ADDR_DELETED = IP_STATUS_BASE + 19;
{$EXTERNALSYM IP_ADDR_DELETED}
IP_SPEC_MTU_CHANGE = IP_STATUS_BASE + 20;
{$EXTERNALSYM IP_SPEC_MTU_CHANGE}
IP_MTU_CHANGE = IP_STATUS_BASE + 21;
{$EXTERNALSYM IP_MTU_CHANGE}
IP_UNLOAD = IP_STATUS_BASE + 22;
{$EXTERNALSYM IP_UNLOAD}
IP_ADDR_ADDED = IP_STATUS_BASE + 23;
{$EXTERNALSYM IP_ADDR_ADDED}
IP_MEDIA_CONNECT = IP_STATUS_BASE + 24;
{$EXTERNALSYM IP_MEDIA_CONNECT}
IP_MEDIA_DISCONNECT = IP_STATUS_BASE + 25;
{$EXTERNALSYM IP_MEDIA_DISCONNECT}
IP_BIND_ADAPTER = IP_STATUS_BASE + 26;
{$EXTERNALSYM IP_BIND_ADAPTER}
IP_UNBIND_ADAPTER = IP_STATUS_BASE + 27;
{$EXTERNALSYM IP_UNBIND_ADAPTER}
IP_DEVICE_DOES_NOT_EXIST = IP_STATUS_BASE + 28;
{$EXTERNALSYM IP_DEVICE_DOES_NOT_EXIST}
IP_DUPLICATE_ADDRESS = IP_STATUS_BASE + 29;
{$EXTERNALSYM IP_DUPLICATE_ADDRESS}
IP_INTERFACE_METRIC_CHANGE = IP_STATUS_BASE + 30;
{$EXTERNALSYM IP_INTERFACE_METRIC_CHANGE}
IP_RECONFIG_SECFLTR = IP_STATUS_BASE + 31;
{$EXTERNALSYM IP_RECONFIG_SECFLTR}
IP_NEGOTIATING_IPSEC = IP_STATUS_BASE + 32;
{$EXTERNALSYM IP_NEGOTIATING_IPSEC}
IP_INTERFACE_WOL_CAPABILITY_CHANGE = IP_STATUS_BASE + 33;
{$EXTERNALSYM IP_INTERFACE_WOL_CAPABILITY_CHANGE}
IP_DUPLICATE_IPADD = IP_STATUS_BASE + 34;
{$EXTERNALSYM IP_DUPLICATE_IPADD}

IP_GENERAL_FAILURE = IP_STATUS_BASE + 50;
{$EXTERNALSYM IP_GENERAL_FAILURE}
MAX_IP_STATUS = IP_GENERAL_FAILURE;
{$EXTERNALSYM MAX_IP_STATUS}
IP_PENDING = IP_STATUS_BASE + 255;
{$EXTERNALSYM IP_PENDING}

//
// Values used in the IP header Flags field.
//

IP_FLAG_DF = $2; // Don't fragment this packet.
{$EXTERNALSYM IP_FLAG_DF}

//
// Supported IP Option Types.
//
// These types define the options which may be used in the OptionsData field
// of the ip_option_information structure. See RFC 791 for a complete
// description of each.
//

IP_OPT_EOL = 0; // End of list option
{$EXTERNALSYM IP_OPT_EOL}
IP_OPT_NOP = 1; // No operation
{$EXTERNALSYM IP_OPT_NOP}
IP_OPT_SECURITY = $82; // Security option
{$EXTERNALSYM IP_OPT_SECURITY}
IP_OPT_LSRR = $83; // Loose source route
{$EXTERNALSYM IP_OPT_LSRR}
IP_OPT_SSRR = $89; // Strict source route
{$EXTERNALSYM IP_OPT_SSRR}
IP_OPT_RR = $7; // Record route
{$EXTERNALSYM IP_OPT_RR}
IP_OPT_TS = $44; // Timestamp
{$EXTERNALSYM IP_OPT_TS}
IP_OPT_SID = $88; // Stream ID (obsolete)
{$EXTERNALSYM IP_OPT_SID}
IP_OPT_ROUTER_ALERT = $94; // Router Alert Option
{$EXTERNALSYM IP_OPT_ROUTER_ALERT}

MAX_OPT_SIZE = 40; // Maximum length of IP options in bytes
{$EXTERNALSYM MAX_OPT_SIZE}

// Ioctls code exposed by Memphis tcpip stack.
// For NT these ioctls are define in ntddip.h (private/inc)

IOCTL_IP_RTCHANGE_NOTIFY_REQUEST = 101;
{$EXTERNALSYM IOCTL_IP_RTCHANGE_NOTIFY_REQUEST}
IOCTL_IP_ADDCHANGE_NOTIFY_REQUEST = 102;
{$EXTERNALSYM IOCTL_IP_ADDCHANGE_NOTIFY_REQUEST}
IOCTL_ARP_SEND_REQUEST = 103;
{$EXTERNALSYM IOCTL_ARP_SEND_REQUEST}
IOCTL_IP_INTERFACE_INFO = 104;
{$EXTERNALSYM IOCTL_IP_INTERFACE_INFO}
IOCTL_IP_GET_BEST_INTERFACE = 105;
{$EXTERNALSYM IOCTL_IP_GET_BEST_INTERFACE}
IOCTL_IP_UNIDIRECTIONAL_ADAPTER_ADDRESS = 106;
{$EXTERNALSYM IOCTL_IP_UNIDIRECTIONAL_ADAPTER_ADDRESS}

implementation

end.

[red]IpRtrMid单元[/red]
{******************************************************************************}
{ }
{ Management Information Base API interface Unit for Object Pascal }
{ }
{ Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
{ Corporation. All Rights Reserved. }
{ }
{ The original file is: iprtrmib.h, released July 2000. The original Pascal }
{ code is: IpRtrMib.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 IpRtrMib;

{$WEAKPACKAGEUNIT}

{$HPPEMIT ''}
{$HPPEMIT '#include "iprtrmib.h"'}
{$HPPEMIT ''}

//{$I WINDEFINES.INC}

interface

uses
Windows;

//////////////////////////////////////////////////////////////////////////////
// //
// Included to get the value of MAX_INTERFACE_NAME_LEN //
// //
//////////////////////////////////////////////////////////////////////////////

// #include <mprapi.h>

//////////////////////////////////////////////////////////////////////////////
// //
// Included to get the necessary constants //
// //
//////////////////////////////////////////////////////////////////////////////

// #include <ipifcons.h>

//////////////////////////////////////////////////////////////////////////////
// //
// This is the Id for IP Router Manager. The Router Manager handles //
// MIB-II, Forwarding MIB and some enterprise specific information. //
// Calls made with any other ID are passed on to the corresponding protocol //
// For example, an MprAdminMIBXXX call with a protocol ID of PID_IP and //
// a routing Id of 0xD will be sent to the IP Router Manager and then //
// forwarded to OSPF //
// This lives in the same number space as the protocol Ids of RIP, OSPF //
// etc, so any change made to it should be done keeping this in mind //
// //
//////////////////////////////////////////////////////////////////////////////

const
MAX_INTERFACE_NAME_LEN = 256; // MPRAPI.H
{$EXTERNALSYM MAX_INTERFACE_NAME_LEN}

IPRTRMGR_PID = 10000;
{$EXTERNALSYM IPRTRMGR_PID}

ANY_SIZE = 1;
{$EXTERNALSYM ANY_SIZE}

//////////////////////////////////////////////////////////////////////////////
// //
// The following #defines are the Ids of the MIB variables made accessible //
// to the user via MprAdminMIBXXX Apis. It will be noticed that these are //
// not the same as RFC 1213, since the MprAdminMIBXXX APIs work on rows and //
// groups instead of scalar variables //
// //
//////////////////////////////////////////////////////////////////////////////

IF_NUMBER = 0;
{$EXTERNALSYM IF_NUMBER}
IF_TABLE = IF_NUMBER + 1;
{$EXTERNALSYM IF_TABLE}
IF_ROW = IF_TABLE + 1;
{$EXTERNALSYM IF_ROW}
IP_STATS = IF_ROW + 1;
{$EXTERNALSYM IP_STATS}
IP_ADDRTABLE = IP_STATS + 1;
{$EXTERNALSYM IP_ADDRTABLE}
IP_ADDRROW = IP_ADDRTABLE + 1;
{$EXTERNALSYM IP_ADDRROW}
IP_FORWARDNUMBER = IP_ADDRROW + 1;
{$EXTERNALSYM IP_FORWARDNUMBER}
IP_FORWARDTABLE = IP_FORWARDNUMBER + 1;
{$EXTERNALSYM IP_FORWARDTABLE}
IP_FORWARDROW = IP_FORWARDTABLE + 1;
{$EXTERNALSYM IP_FORWARDROW}
IP_NETTABLE = IP_FORWARDROW + 1;
{$EXTERNALSYM IP_NETTABLE}
IP_NETROW = IP_NETTABLE + 1;
{$EXTERNALSYM IP_NETROW}
ICMP_STATS = IP_NETROW + 1;
{$EXTERNALSYM ICMP_STATS}
TCP_STATS = ICMP_STATS + 1;
{$EXTERNALSYM TCP_STATS}
TCP_TABLE = TCP_STATS + 1;
{$EXTERNALSYM TCP_TABLE}
TCP_ROW = TCP_TABLE + 1;
{$EXTERNALSYM TCP_ROW}
UDP_STATS = TCP_ROW + 1;
{$EXTERNALSYM UDP_STATS}
UDP_TABLE = UDP_STATS + 1;
{$EXTERNALSYM UDP_TABLE}
UDP_ROW = UDP_TABLE + 1;
{$EXTERNALSYM UDP_ROW}
MCAST_MFE = UDP_ROW + 1;
{$EXTERNALSYM MCAST_MFE}
MCAST_MFE_STATS = MCAST_MFE + 1;
{$EXTERNALSYM MCAST_MFE_STATS}
BEST_IF = MCAST_MFE_STATS + 1;
{$EXTERNALSYM BEST_IF}
BEST_ROUTE = BEST_IF + 1;
{$EXTERNALSYM BEST_ROUTE}
PROXY_ARP = BEST_ROUTE + 1;
{$EXTERNALSYM PROXY_ARP}
MCAST_IF_ENTRY = PROXY_ARP + 1;
{$EXTERNALSYM MCAST_IF_ENTRY}
MCAST_GLOBAL = MCAST_IF_ENTRY + 1;
{$EXTERNALSYM MCAST_GLOBAL}
IF_STATUS = MCAST_GLOBAL + 1;
{$EXTERNALSYM IF_STATUS}
MCAST_BOUNDARY = IF_STATUS + 1;
{$EXTERNALSYM MCAST_BOUNDARY}
MCAST_SCOPE = MCAST_BOUNDARY + 1;
{$EXTERNALSYM MCAST_SCOPE}
DEST_MATCHING = MCAST_SCOPE + 1;
{$EXTERNALSYM DEST_MATCHING}
DEST_LONGER = DEST_MATCHING + 1;
{$EXTERNALSYM DEST_LONGER}
DEST_SHORTER = DEST_LONGER + 1;
{$EXTERNALSYM DEST_SHORTER}
ROUTE_MATCHING = DEST_SHORTER + 1;
{$EXTERNALSYM ROUTE_MATCHING}
ROUTE_LONGER = ROUTE_MATCHING + 1;
{$EXTERNALSYM ROUTE_LONGER}
ROUTE_SHORTER = ROUTE_LONGER + 1;
{$EXTERNALSYM ROUTE_SHORTER}
ROUTE_STATE = ROUTE_SHORTER + 1;
{$EXTERNALSYM ROUTE_STATE}

NUMBER_OF_EXPORTED_VARIABLES = ROUTE_STATE + 1;
{$EXTERNALSYM NUMBER_OF_EXPORTED_VARIABLES}

//////////////////////////////////////////////////////////////////////////////
// //
// MIB_OPAQUE_QUERY is the structure filled in by the user to identify a //
// MIB variable //
// //
// dwVarId ID of MIB Variable (One of the Ids #defined above) //
// dwVarIndex Variable sized array containing the indices needed to //
// identify a variable. NOTE: Unlike SNMP we dont require that //
// a scalar variable be indexed by 0 //
// //
//////////////////////////////////////////////////////////////////////////////

type
PMIB_OPAQUE_QUERY = ^MIB_OPAQUE_QUERY;
{$EXTERNALSYM PMIB_OPAQUE_QUERY}
_MIB_OPAQUE_QUERY = record
dwVarId: DWORD;
rgdwVarIndex: array [0..ANY_SIZE - 1] of DWORD;
end;
{$EXTERNALSYM _MIB_OPAQUE_QUERY}
MIB_OPAQUE_QUERY = _MIB_OPAQUE_QUERY;
{$EXTERNALSYM MIB_OPAQUE_QUERY}
TMibOpaqueQuery = MIB_OPAQUE_QUERY;
PMibOpaqueQuery = PMIB_OPAQUE_QUERY;

//////////////////////////////////////////////////////////////////////////////
// //
// The following are the structures which are filled in and returned to the //
// user when a query is made, OR are filled in BY THE USER when a set is //
// done //
// //
//////////////////////////////////////////////////////////////////////////////

type
PMIB_IFNUMBER = ^MIB_IFNUMBER;
{$EXTERNALSYM PMIB_IFNUMBER}
_MIB_IFNUMBER = record
dwValue: DWORD;
end;
{$EXTERNALSYM _MIB_IFNUMBER}
MIB_IFNUMBER = _MIB_IFNUMBER;
{$EXTERNALSYM MIB_IFNUMBER}
TMibIfnumber = MIB_IFNUMBER;
PMibIfnumber = PMIB_IFNUMBER;

const
MAXLEN_IFDESCR = 256;
{$EXTERNALSYM MAXLEN_IFDESCR}
MAXLEN_PHYSADDR = 8;
{$EXTERNALSYM MAXLEN_PHYSADDR}

type
PMIB_IFROW = ^MIB_IFROW;
{$EXTERNALSYM PMIB_IFROW}
_MIB_IFROW = record
wszName: array [0..MAX_INTERFACE_NAME_LEN - 1] of WCHAR;
dwIndex: DWORD;
dwType: DWORD;
dwMtu: DWORD;
dwSpeed: DWORD;
dwPhysAddrLen: DWORD;
bPhysAddr: array [0..MAXLEN_PHYSADDR - 1] of BYTE;
dwAdminStatus: DWORD;
dwOperStatus: DWORD;
dwLastChange: DWORD;
dwInOctets: DWORD;
dwInUcastPkts: DWORD;
dwInNUcastPkts: DWORD;
dwInDiscards: DWORD;
dwInErrors: DWORD;
dwInUnknownProtos: DWORD;
dwOutOctets: DWORD;
dwOutUcastPkts: DWORD;
dwOutNUcastPkts: DWORD;
dwOutDiscards: DWORD;
dwOutErrors: DWORD;
dwOutQLen: DWORD;
dwDescrLen: DWORD;
bDescr: array[0..MAXLEN_IFDESCR - 1] of BYTE;
end;
{$EXTERNALSYM _MIB_IFROW}
MIB_IFROW = _MIB_IFROW;
{$EXTERNALSYM MIB_IFROW}
TMibIfRow = MIB_IFROW;
PMibIfRow = PMIB_IFROW;

PMIB_IFTABLE = ^MIB_IFTABLE;
{$EXTERNALSYM PMIB_IFTABLE}
_MIB_IFTABLE = record
dwNumEntries: DWORD;
table: array [0..ANY_SIZE - 1] of MIB_IFROW;
end;
{$EXTERNALSYM _MIB_IFTABLE}
MIB_IFTABLE = _MIB_IFTABLE;
{$EXTERNALSYM MIB_IFTABLE}
TMibIftable = MIB_IFTABLE;
PMibIftable = PMIB_IFTABLE;

// #define SIZEOF_IFTABLE(X) (FIELD_OFFSET(MIB_IFTABLE,table[0]) + ((X) * sizeof(MIB_IFROW)) + ALIGN_SIZE)

type
PMibIcmpStats = ^TMibIcmpStats;
_MIBICMPSTATS = record
dwMsgs: DWORD;
dwErrors: DWORD;
dwDestUnreachs: DWORD;
dwTimeExcds: DWORD;
dwParmProbs: DWORD;
dwSrcQuenchs: DWORD;
dwRedirects: DWORD;
dwEchos: DWORD;
dwEchoReps: DWORD;
dwTimestamps: DWORD;
dwTimestampReps: DWORD;
dwAddrMasks: DWORD;
dwAddrMaskReps: DWORD;
end;
{$EXTERNALSYM _MIBICMPSTATS}
MIBICMPSTATS = _MIBICMPSTATS;
{$EXTERNALSYM MIBICMPSTATS}
TMibIcmpStats = _MIBICMPSTATS;

PMibIcmpInfo = ^TMibIcmpInfo;
_MIBICMPINFO = record
icmpInStats: MIBICMPSTATS;
icmpOutStats: MIBICMPSTATS;
end;
{$EXTERNALSYM _MIBICMPINFO}
MIBICMPINFO = _MIBICMPINFO;
{$EXTERNALSYM MIBICMPINFO}
TMibIcmpInfo = MIBICMPINFO;

PMIB_ICMP = ^MIB_ICMP;
{$EXTERNALSYM PMIB_ICMP}
_MIB_ICMP = record
stats: MIBICMPINFO;
end;
{$EXTERNALSYM _MIB_ICMP}
MIB_ICMP = _MIB_ICMP;
{$EXTERNALSYM MIB_ICMP}
TMibIcmp = MIB_ICMP;
PMibIcmp = PMIB_ICMP;

PMIB_UDPSTATS = ^MIB_UDPSTATS;
{$EXTERNALSYM PMIB_UDPSTATS}
_MIB_UDPSTATS = record
dwInDatagrams: DWORD;
dwNoPorts: DWORD;
dwInErrors: DWORD;
dwOutDatagrams: DWORD;
dwNumAddrs: DWORD;
end;
{$EXTERNALSYM _MIB_UDPSTATS}
MIB_UDPSTATS = _MIB_UDPSTATS;
{$EXTERNALSYM MIB_UDPSTATS}
TMibUdpStats = MIB_UDPSTATS;
PMibUdpStats = PMIB_UDPSTATS;

PMIB_UDPROW = ^MIB_UDPROW;
{$EXTERNALSYM PMIB_UDPROW}
_MIB_UDPROW = record
dwLocalAddr: DWORD;
dwLocalPort: DWORD;
end;
{$EXTERNALSYM _MIB_UDPROW}
MIB_UDPROW = _MIB_UDPROW;
{$EXTERNALSYM MIB_UDPROW}
TMibUdpRow = MIB_UDPROW;
PMibUdpRow = PMIB_UDPROW;

PMIB_UDPTABLE = ^MIB_UDPTABLE;
{$EXTERNALSYM PMIB_UDPTABLE}
_MIB_UDPTABLE = record
dwNumEntries: DWORD;
table: array [0..ANY_SIZE - 1] of MIB_UDPROW;
end;
{$EXTERNALSYM _MIB_UDPTABLE}
MIB_UDPTABLE = _MIB_UDPTABLE;
{$EXTERNALSYM MIB_UDPTABLE}
TMibUdpTable = MIB_UDPTABLE;
PMibUdpTable = PMIB_UDPTABLE;

// #define SIZEOF_UDPTABLE(X) (FIELD_OFFSET(MIB_UDPTABLE, table[0]) + ((X) * sizeof(MIB_UDPROW)) + ALIGN_SIZE)

PMIB_TCPSTATS = ^MIB_TCPSTATS;
{$EXTERNALSYM PMIB_TCPSTATS}
_MIB_TCPSTATS = record
dwRtoAlgorithm: DWORD;
dwRtoMin: DWORD;
dwRtoMax: DWORD;
dwMaxConn: DWORD;
dwActiveOpens: DWORD;
dwPassiveOpens: DWORD;
dwAttemptFails: DWORD;
dwEstabResets: DWORD;
dwCurrEstab: DWORD;
dwInSegs: DWORD;
dwOutSegs: DWORD;
dwRetransSegs: DWORD;
dwInErrs: DWORD;
dwOutRsts: DWORD;
dwNumConns: DWORD;
end;
{$EXTERNALSYM _MIB_TCPSTATS}
MIB_TCPSTATS = _MIB_TCPSTATS;
{$EXTERNALSYM MIB_TCPSTATS}
TMibTcpStats = MIB_TCPSTATS;
PMibTcpStats = PMIB_TCPSTATS;

const
MIB_TCP_RTO_OTHER = 1;
{$EXTERNALSYM MIB_TCP_RTO_OTHER}
MIB_TCP_RTO_CONSTANT = 2;
{$EXTERNALSYM MIB_TCP_RTO_CONSTANT}
MIB_TCP_RTO_RSRE = 3;
{$EXTERNALSYM MIB_TCP_RTO_RSRE}
MIB_TCP_RTO_VANJ = 4;
{$EXTERNALSYM MIB_TCP_RTO_VANJ}

MIB_TCP_MAXCONN_DYNAMIC = DWORD(-1);
{$EXTERNALSYM MIB_TCP_MAXCONN_DYNAMIC}

type
PMIB_TCPROW = ^MIB_TCPROW;
{$EXTERNALSYM PMIB_TCPROW}
_MIB_TCPROW = record
dwState: DWORD;
dwLocalAddr: DWORD;
dwLocalPort: DWORD;
dwRemoteAddr: DWORD;
dwRemotePort: DWORD;
end;
{$EXTERNALSYM _MIB_TCPROW}
MIB_TCPROW = _MIB_TCPROW;
{$EXTERNALSYM MIB_TCPROW}
TMibTcpRow = MIB_TCPROW;
PMibTcpRow = PMIB_TCPROW;

const
MIB_TCP_STATE_CLOSED = 1;
{$EXTERNALSYM MIB_TCP_STATE_CLOSED}
MIB_TCP_STATE_LISTEN = 2;
{$EXTERNALSYM MIB_TCP_STATE_LISTEN}
MIB_TCP_STATE_SYN_SENT = 3;
{$EXTERNALSYM MIB_TCP_STATE_SYN_SENT}
MIB_TCP_STATE_SYN_RCVD = 4;
{$EXTERNALSYM MIB_TCP_STATE_SYN_RCVD}
MIB_TCP_STATE_ESTAB = 5;
{$EXTERNALSYM MIB_TCP_STATE_ESTAB}
MIB_TCP_STATE_FIN_WAIT1 = 6;
{$EXTERNALSYM MIB_TCP_STATE_FIN_WAIT1}
MIB_TCP_STATE_FIN_WAIT2 = 7;
{$EXTERNALSYM MIB_TCP_STATE_FIN_WAIT2}
MIB_TCP_STATE_CLOSE_WAIT = 8;
{$EXTERNALSYM MIB_TCP_STATE_CLOSE_WAIT}
MIB_TCP_STATE_CLOSING = 9;
{$EXTERNALSYM MIB_TCP_STATE_CLOSING}
MIB_TCP_STATE_LAST_ACK = 10;
{$EXTERNALSYM MIB_TCP_STATE_LAST_ACK}
MIB_TCP_STATE_TIME_WAIT = 11;
{$EXTERNALSYM MIB_TCP_STATE_TIME_WAIT}
MIB_TCP_STATE_DELETE_TCB = 12;
{$EXTERNALSYM MIB_TCP_STATE_DELETE_TCB}

type
PMIB_TCPTABLE = ^MIB_TCPTABLE;
{$EXTERNALSYM PMIB_TCPTABLE}
_MIB_TCPTABLE = record
dwNumEntries: DWORD;
table: array [0..ANY_SIZE - 1] of MIB_TCPROW;
end;
{$EXTERNALSYM _MIB_TCPTABLE}
MIB_TCPTABLE = _MIB_TCPTABLE;
{$EXTERNALSYM MIB_TCPTABLE}
TMibTcpTable = MIB_TCPTABLE;
PMibTcpTable = PMIB_TCPTABLE;

// #define SIZEOF_TCPTABLE(X) (FIELD_OFFSET(MIB_TCPTABLE,table[0]) + ((X) * sizeof(MIB_TCPROW)) + ALIGN_SIZE)

const
MIB_USE_CURRENT_TTL = DWORD(-1);
{$EXTERNALSYM MIB_USE_CURRENT_TTL}
MIB_USE_CURRENT_FORWARDING = DWORD(-1);
{$EXTERNALSYM MIB_USE_CURRENT_FORWARDING}

type
PMIB_IPSTATS = ^MIB_IPSTATS;
{$EXTERNALSYM PMIB_IPSTATS}
_MIB_IPSTATS = record
dwForwarding: DWORD;
dwDefaultTTL: DWORD;
dwInReceives: DWORD;
dwInHdrErrors: DWORD;
dwInAddrErrors: DWORD;
dwForwDatagrams: DWORD;
dwInUnknownProtos: DWORD;
dwInDiscards: DWORD;
dwInDelivers: DWORD;
dwOutRequests: DWORD;
dwRoutingDiscards: DWORD;
dwOutDiscards: DWORD;
dwOutNoRoutes: DWORD;
dwReasmTimeout: DWORD;
dwReasmReqds: DWORD;
dwReasmOks: DWORD;
dwReasmFails: DWORD;
dwFragOks: DWORD;
dwFragFails: DWORD;
dwFragCreates: DWORD;
dwNumIf: DWORD;
dwNumAddr: DWORD;
dwNumRoutes: DWORD;
end;
{$EXTERNALSYM _MIB_IPSTATS}
MIB_IPSTATS = _MIB_IPSTATS;
{$EXTERNALSYM MIB_IPSTATS}
TMibIpStats = MIB_IPSTATS;
PMibIpStats = PMIB_IPSTATS;

const
MIB_IP_FORWARDING = 1;
{$EXTERNALSYM MIB_IP_FORWARDING}
MIB_IP_NOT_FORWARDING = 2;
{$EXTERNALSYM MIB_IP_NOT_FORWARDING}

type
PMIB_IPADDRROW = ^MIB_IPADDRROW;
{$EXTERNALSYM PMIB_IPADDRROW}
_MIB_IPADDRROW = record
dwAddr: DWORD;
dwIndex: DWORD;
dwMask: DWORD;
dwBCastAddr: DWORD;
dwReasmSize: DWORD;
unused1: Word;
unused2: Word;
end;
{$EXTERNALSYM _MIB_IPADDRROW}
MIB_IPADDRROW = _MIB_IPADDRROW;
{$EXTERNALSYM MIB_IPADDRROW}
TMibIpAddrRow = MIB_IPADDRROW;
PMibIpAddrRow = PMIB_IPADDRROW;

PMIB_IPADDRTABLE = ^MIB_IPADDRTABLE;
{$EXTERNALSYM PMIB_IPADDRTABLE}
_MIB_IPADDRTABLE = record
dwNumEntries: DWORD;
table: array [0..ANY_SIZE - 1] of MIB_IPADDRROW;
end;
{$EXTERNALSYM _MIB_IPADDRTABLE}
MIB_IPADDRTABLE = _MIB_IPADDRTABLE;
{$EXTERNALSYM MIB_IPADDRTABLE}
TMibIpAddrTable = _MIB_IPADDRTABLE;
PMibIpAddrTable = PMIB_IPADDRTABLE;

// #define SIZEOF_IPADDRTABLE(X) (FIELD_OFFSET(MIB_IPADDRTABLE,table[0]) + ((X) * sizeof(MIB_IPADDRROW)) + ALIGN_SIZE)

type
PMIB_IPFORWARDNUMBER = ^MIB_IPFORWARDNUMBER;
{$EXTERNALSYM PMIB_IPFORWARDNUMBER}
_MIB_IPFORWARDNUMBER = record
dwValue: DWORD;
end;
{$EXTERNALSYM _MIB_IPFORWARDNUMBER}
MIB_IPFORWARDNUMBER = _MIB_IPFORWARDNUMBER;
{$EXTERNALSYM MIB_IPFORWARDNUMBER}
TMibIpForwardNumber = MIB_IPFORWARDNUMBER;
PMibIpForwardNumber = PMIB_IPFORWARDNUMBER;

PMIB_IPFORWARDROW = ^MIB_IPFORWARDROW;
{$EXTERNALSYM PMIB_IPFORWARDROW}
_MIB_IPFORWARDROW = record
dwForwardDest: DWORD;
dwForwardMask: DWORD;
dwForwardPolicy: DWORD;
dwForwardNextHop: DWORD;
dwForwardIfIndex: DWORD;
dwForwardType: DWORD;
dwForwardProto: DWORD;
dwForwardAge: DWORD;
dwForwardNextHopAS: DWORD;
dwForwardMetric1: DWORD;
dwForwardMetric2: DWORD;
dwForwardMetric3: DWORD;
dwForwardMetric4: DWORD;
dwForwardMetric5: DWORD;
end;
{$EXTERNALSYM _MIB_IPFORWARDROW}
MIB_IPFORWARDROW = _MIB_IPFORWARDROW;
{$EXTERNALSYM MIB_IPFORWARDROW}
TMibIpForwardRow = MIB_IPFORWARDROW;
PMibIpForwardRow = PMIB_IPFORWARDROW;

const
MIB_IPROUTE_TYPE_OTHER = 1;
{$EXTERNALSYM MIB_IPROUTE_TYPE_OTHER}
MIB_IPROUTE_TYPE_INVALID = 2;
{$EXTERNALSYM MIB_IPROUTE_TYPE_INVALID}
MIB_IPROUTE_TYPE_DIRECT = 3;
{$EXTERNALSYM MIB_IPROUTE_TYPE_DIRECT}
MIB_IPROUTE_TYPE_INDIRECT = 4;
{$EXTERNALSYM MIB_IPROUTE_TYPE_INDIRECT}

MIB_IPROUTE_METRIC_UNUSED = DWORD(-1);
{$EXTERNALSYM MIB_IPROUTE_METRIC_UNUSED}

//
// THESE MUST MATCH the ids in routprot.h
//

const
MIB_IPPROTO_OTHER = 1;
{$EXTERNALSYM MIB_IPPROTO_OTHER}
MIB_IPPROTO_LOCAL = 2;
{$EXTERNALSYM MIB_IPPROTO_LOCAL}
MIB_IPPROTO_NETMGMT = 3;
{$EXTERNALSYM MIB_IPPROTO_NETMGMT}
MIB_IPPROTO_ICMP = 4;
{$EXTERNALSYM MIB_IPPROTO_ICMP}
MIB_IPPROTO_EGP = 5;
{$EXTERNALSYM MIB_IPPROTO_EGP}
MIB_IPPROTO_GGP = 6;
{$EXTERNALSYM MIB_IPPROTO_GGP}
MIB_IPPROTO_HELLO = 7;
{$EXTERNALSYM MIB_IPPROTO_HELLO}
MIB_IPPROTO_RIP = 8;
{$EXTERNALSYM MIB_IPPROTO_RIP}
MIB_IPPROTO_IS_IS = 9;
{$EXTERNALSYM MIB_IPPROTO_IS_IS}
MIB_IPPROTO_ES_IS = 10;
{$EXTERNALSYM MIB_IPPROTO_ES_IS}
MIB_IPPROTO_CISCO = 11;
{$EXTERNALSYM MIB_IPPROTO_CISCO}
MIB_IPPROTO_BBN = 12;
{$EXTERNALSYM MIB_IPPROTO_BBN}
MIB_IPPROTO_OSPF = 13;
{$EXTERNALSYM MIB_IPPROTO_OSPF}
MIB_IPPROTO_BGP = 14;
{$EXTERNALSYM MIB_IPPROTO_BGP}

MIB_IPPROTO_NT_AUTOSTATIC = 10002;
{$EXTERNALSYM MIB_IPPROTO_NT_AUTOSTATIC}
MIB_IPPROTO_NT_STATIC = 10006;
{$EXTERNALSYM MIB_IPPROTO_NT_STATIC}
MIB_IPPROTO_NT_STATIC_NON_DOD = 10007;
{$EXTERNALSYM MIB_IPPROTO_NT_STATIC_NON_DOD}

type
PMIB_IPFORWARDTABLE = ^MIB_IPFORWARDTABLE;
{$EXTERNALSYM PMIB_IPFORWARDTABLE}
_MIB_IPFORWARDTABLE = record
dwNumEntries: DWORD;
table: array [0..ANY_SIZE - 1] of MIB_IPFORWARDROW;
end;
{$EXTERNALSYM _MIB_IPFORWARDTABLE}
MIB_IPFORWARDTABLE = _MIB_IPFORWARDTABLE;
{$EXTERNALSYM MIB_IPFORWARDTABLE}
TMibIpForwardTable = MIB_IPFORWARDTABLE;
PMibIpForwardTable = PMIB_IPFORWARDTABLE;

// #define SIZEOF_IPFORWARDTABLE(X) (FIELD_OFFSET(MIB_IPFORWARDTABLE,table[0]) + ((X) * sizeof(MIB_IPFORWARDROW)) + ALIGN_SIZE)

type
PMIB_IPNETROW = ^MIB_IPNETROW;
{$EXTERNALSYM PMIB_IPNETROW}
_MIB_IPNETROW = record
dwIndex: DWORD;
dwPhysAddrLen: DWORD;
bPhysAddr: array [0..MAXLEN_PHYSADDR - 1] of BYTE;
dwAddr: DWORD;
dwType: DWORD;
end;
{$EXTERNALSYM _MIB_IPNETROW}
MIB_IPNETROW = _MIB_IPNETROW;
{$EXTERNALSYM MIB_IPNETROW}
TMibIpNetRow = MIB_IPNETROW;
PMibIpNetRow = PMIB_IPNETROW;

const
MIB_IPNET_TYPE_OTHER = 1;
{$EXTERNALSYM MIB_IPNET_TYPE_OTHER}
MIB_IPNET_TYPE_INVALID = 2;
{$EXTERNALSYM MIB_IPNET_TYPE_INVALID}
MIB_IPNET_TYPE_DYNAMIC = 3;
{$EXTERNALSYM MIB_IPNET_TYPE_DYNAMIC}
MIB_IPNET_TYPE_STATIC = 4;
{$EXTERNALSYM MIB_IPNET_TYPE_STATIC}

type
PMIB_IPNETTABLE = ^MIB_IPNETTABLE;
{$EXTERNALSYM PMIB_IPNETTABLE}
_MIB_IPNETTABLE = record
dwNumEntries: DWORD;
table: array [0..ANY_SIZE - 1] of MIB_IPNETROW;
end;
{$EXTERNALSYM _MIB_IPNETTABLE}
MIB_IPNETTABLE = _MIB_IPNETTABLE;
{$EXTERNALSYM MIB_IPNETTABLE}
TMibIpNetTable = MIB_IPNETTABLE;
PMibIpNetTable = PMIB_IPNETTABLE;

// #define SIZEOF_IPNETTABLE(X) (FIELD_OFFSET(MIB_IPNETTABLE, table[0]) + ((X) * sizeof(MIB_IPNETROW)) + ALIGN_SIZE)

type
PMIB_IPMCAST_OIF = ^MIB_IPMCAST_OIF;
{$EXTERNALSYM PMIB_IPMCAST_OIF}
_MIB_IPMCAST_OIF = record
dwOutIfIndex: DWORD;
dwNextHopAddr: DWORD;
pvReserved: Pointer;
dwReserved: DWORD;
end;
{$EXTERNALSYM _MIB_IPMCAST_OIF}
MIB_IPMCAST_OIF = _MIB_IPMCAST_OIF;
{$EXTERNALSYM MIB_IPMCAST_OIF}
TMibIpmCastOif = MIB_IPMCAST_OIF;
PMibIpmCastOif = PMIB_IPMCAST_OIF;

PMIB_IPMCAST_MFE = ^MIB_IPMCAST_MFE;
{$EXTERNALSYM PMIB_IPMCAST_MFE}
_MIB_IPMCAST_MFE = record
dwGroup: DWORD;
dwSource: DWORD;
dwSrcMask: DWORD;
dwUpStrmNgbr: DWORD;
dwInIfIndex: DWORD;
dwInIfProtocol: DWORD;
dwRouteProtocol: DWORD;
dwRouteNetwork: DWORD;
dwRouteMask: DWORD;
ulUpTime: ULONG;
ulExpiryTime: ULONG;
ulTimeOut: ULONG;
ulNumOutIf: ULONG;
fFlags: DWORD;
dwReserved: DWORD;
rgmioOutInfo: array [0..ANY_SIZE - 1] of MIB_IPMCAST_OIF;
end;
{$EXTERNALSYM _MIB_IPMCAST_MFE}
MIB_IPMCAST_MFE = _MIB_IPMCAST_MFE;
{$EXTERNALSYM MIB_IPMCAST_MFE}
TMibIpmCastMfe = MIB_IPMCAST_MFE;
PMibIpmCastMfe = PMIB_IPMCAST_MFE;

PMIB_MFE_TABLE = ^MIB_MFE_TABLE;
{$EXTERNALSYM PMIB_MFE_TABLE}
_MIB_MFE_TABLE = record
dwNumEntries: DWORD;
table: array [0..ANY_SIZE - 1] of MIB_IPMCAST_MFE;
end;
{$EXTERNALSYM _MIB_MFE_TABLE}
MIB_MFE_TABLE = _MIB_MFE_TABLE;
{$EXTERNALSYM MIB_MFE_TABLE}
TMibMfeTable = MIB_MFE_TABLE;
PMibMfeTable = PMIB_MFE_TABLE;


// #define SIZEOF_BASIC_MIB_MFE /
// (ULONG)(FIELD_OFFSET(MIB_IPMCAST_MFE, rgmioOutInfo[0]))

// #define SIZEOF_MIB_MFE(X) /
// (SIZEOF_BASIC_MIB_MFE + ((X) * sizeof(MIB_IPMCAST_OIF)))

type
PMIB_IPMCAST_OIF_STATS = ^MIB_IPMCAST_OIF_STATS;
{$EXTERNALSYM PMIB_IPMCAST_OIF_STATS}
_MIB_IPMCAST_OIF_STATS = record
dwOutIfIndex: DWORD;
dwNextHopAddr: DWORD;
pvDialContext: Pointer;
ulTtlTooLow: ULONG;
ulFragNeeded: ULONG;
ulOutPackets: ULONG;
ulOutDiscards: ULONG;
end;
{$EXTERNALSYM _MIB_IPMCAST_OIF_STATS}
MIB_IPMCAST_OIF_STATS = _MIB_IPMCAST_OIF_STATS;
{$EXTERNALSYM MIB_IPMCAST_OIF_STATS}
TMibIpmCastOifStats = MIB_IPMCAST_OIF_STATS;
PMibIpmCastOifStats = PMIB_IPMCAST_OIF_STATS;

PMIB_IPMCAST_MFE_STATS = ^MIB_IPMCAST_MFE_STATS;
{$EXTERNALSYM PMIB_IPMCAST_MFE_STATS}
_MIB_IPMCAST_MFE_STATS = record
dwGroup: DWORD;
dwSource: DWORD;
dwSrcMask: DWORD;
dwUpStrmNgbr: DWORD;
dwInIfIndex: DWORD;
dwInIfProtocol: DWORD;
dwRouteProtocol: DWORD;
dwRouteNetwork: DWORD;
dwRouteMask: DWORD;
ulUpTime: ULONG;
ulExpiryTime: ULONG;
ulNumOutIf: ULONG;
ulInPkts: ULONG;
ulInOctets: ULONG;
ulPktsDifferentIf: ULONG;
ulQueueOverflow: ULONG;
rgmiosOutStats: array [0..ANY_SIZE - 1] of MIB_IPMCAST_OIF_STATS;
end;
{$EXTERNALSYM _MIB_IPMCAST_MFE_STATS}
MIB_IPMCAST_MFE_STATS = _MIB_IPMCAST_MFE_STATS;
{$EXTERNALSYM MIB_IPMCAST_MFE_STATS}
TMibIpmCastMfeStats = MIB_IPMCAST_MFE_STATS;
PMibIpmCastMfeStats = PMIB_IPMCAST_MFE_STATS;

PMIB_MFE_STATS_TABLE = ^MIB_MFE_STATS_TABLE;
{$EXTERNALSYM PMIB_MFE_STATS_TABLE}
_MIB_MFE_STATS_TABLE = record
dwNumEntries: DWORD;
table: array [0..ANY_SIZE - 1] of MIB_IPMCAST_MFE_STATS;
end;
{$EXTERNALSYM _MIB_MFE_STATS_TABLE}
MIB_MFE_STATS_TABLE = _MIB_MFE_STATS_TABLE;
{$EXTERNALSYM MIB_MFE_STATS_TABLE}
TMibMfeStatsTable = MIB_MFE_STATS_TABLE;
PMibMfeStatsTable = PMIB_MFE_STATS_TABLE;

// #define SIZEOF_BASIC_MIB_MFE_STATS /
// (ULONG)(FIELD_OFFSET(MIB_IPMCAST_MFE_STATS, rgmiosOutStats[0]))

// #define SIZEOF_MIB_MFE_STATS(X) /
// (SIZEOF_BASIC_MIB_MFE_STATS + ((X) * sizeof(MIB_IPMCAST_OIF_STATS)))

type
PMIB_IPMCAST_GLOBAL = ^MIB_IPMCAST_GLOBAL;
{$EXTERNALSYM PMIB_IPMCAST_GLOBAL}
_MIB_IPMCAST_GLOBAL = record
dwEnable: DWORD;
end;
{$EXTERNALSYM _MIB_IPMCAST_GLOBAL}
MIB_IPMCAST_GLOBAL = _MIB_IPMCAST_GLOBAL;
{$EXTERNALSYM MIB_IPMCAST_GLOBAL}
TMibIpmCastGlobal = MIB_IPMCAST_GLOBAL;
PMibIpmCastGlobal = PMIB_IPMCAST_GLOBAL;

PMIB_IPMCAST_IF_ENTRY = ^MIB_IPMCAST_IF_ENTRY;
{$EXTERNALSYM PMIB_IPMCAST_IF_ENTRY}
_MIB_IPMCAST_IF_ENTRY = record
dwIfIndex: DWORD;
dwTtl: DWORD;
dwProtocol: DWORD;
dwRateLimit: DWORD;
ulInMcastOctets: ULONG;
ulOutMcastOctets: ULONG;
end;
{$EXTERNALSYM _MIB_IPMCAST_IF_ENTRY}
MIB_IPMCAST_IF_ENTRY = _MIB_IPMCAST_IF_ENTRY;
{$EXTERNALSYM MIB_IPMCAST_IF_ENTRY}
TMibIpmCastIfEntry = MIB_IPMCAST_IF_ENTRY;
PMibIpmCastIfEntry = PMIB_IPMCAST_IF_ENTRY;

PMIB_IPMCAST_IF_TABLE = ^MIB_IPMCAST_IF_TABLE;
{$EXTERNALSYM PMIB_IPMCAST_IF_TABLE}
_MIB_IPMCAST_IF_TABLE = record
dwNumEntries: DWORD;
table: array [0..ANY_SIZE - 1] of MIB_IPMCAST_IF_ENTRY;
end;
{$EXTERNALSYM _MIB_IPMCAST_IF_TABLE}
MIB_IPMCAST_IF_TABLE = _MIB_IPMCAST_IF_TABLE;
{$EXTERNALSYM MIB_IPMCAST_IF_TABLE}
TMibIpmCastIfTable = MIB_IPMCAST_IF_TABLE;
PMibIpmCastIfTable = PMIB_IPMCAST_IF_TABLE;

// #define SIZEOF_MCAST_IF_TABLE(X) (FIELD_OFFSET(MIB_IPMCAST_IF_TABLE,table[0]) + ((X) * sizeof(MIB_IPMCAST_IF_ENTRY)) + ALIGN_SIZE)

type
PMIB_IPMCAST_BOUNDARY = ^MIB_IPMCAST_BOUNDARY;
{$EXTERNALSYM PMIB_IPMCAST_BOUNDARY}
_MIB_IPMCAST_BOUNDARY = record
dwIfIndex: DWORD;
dwGroupAddress: DWORD;
dwGroupMask: DWORD;
dwStatus: DWORD;
end;
{$EXTERNALSYM _MIB_IPMCAST_BOUNDARY}
MIB_IPMCAST_BOUNDARY = _MIB_IPMCAST_BOUNDARY;
{$EXTERNALSYM MIB_IPMCAST_BOUNDARY}
TMibIpmCastBoundary = MIB_IPMCAST_BOUNDARY;
PMibIpmCastBoundary = PMIB_IPMCAST_BOUNDARY;

PMIB_IPMCAST_BOUNDARY_TABLE = ^MIB_IPMCAST_BOUNDARY_TABLE;
{$EXTERNALSYM PMIB_IPMCAST_BOUNDARY_TABLE}
_MIB_IPMCAST_BOUNDARY_TABLE = record
dwNumEntries: DWORD;
table: array [0..ANY_SIZE - 1] of MIB_IPMCAST_BOUNDARY;
end;
{$EXTERNALSYM _MIB_IPMCAST_BOUNDARY_TABLE}
MIB_IPMCAST_BOUNDARY_TABLE = _MIB_IPMCAST_BOUNDARY_TABLE;
{$EXTERNALSYM MIB_IPMCAST_BOUNDARY_TABLE}
TMibIpmCastBoundaryTable = MIB_IPMCAST_BOUNDARY_TABLE;
PMibIpmCastBoundaryTable = PMIB_IPMCAST_BOUNDARY_TABLE;

// #define SIZEOF_BOUNDARY_TABLE(X) (FIELD_OFFSET(MIB_IPMCAST_BOUNDARY_TABLE,table[0]) + ((X) * sizeof(MIB_IPMCAST_BOUNDARY)) + ALIGN_SIZE)

type
PMIB_BOUNDARYROW = ^MIB_BOUNDARYROW;
{$EXTERNALSYM PMIB_BOUNDARYROW}
MIB_BOUNDARYROW = record
dwGroupAddress: DWORD;
dwGroupMask: DWORD;
end;
{$EXTERNALSYM MIB_BOUNDARYROW}
TMibBoundaryRow = MIB_BOUNDARYROW;
PMibBoundaryRow = PMIB_BOUNDARYROW;

// Structure matching what goes in the registry in a block of type
// IP_MCAST_LIMIT_INFO. This contains the fields of
// MIB_IPMCAST_IF_ENTRY which are configurable.

PMIB_MCAST_LIMIT_ROW = ^MIB_MCAST_LIMIT_ROW;
{$EXTERNALSYM PMIB_MCAST_LIMIT_ROW}
MIB_MCAST_LIMIT_ROW = record
dwTtl: DWORD;
dwRateLimit: DWORD;
end;
{$EXTERNALSYM MIB_MCAST_LIMIT_ROW}
TMibMcastLimitRow = MIB_MCAST_LIMIT_ROW;
PMibMcastLimitRow = PMIB_MCAST_LIMIT_ROW;

const
MAX_SCOPE_NAME_LEN = 255;
{$EXTERNALSYM MAX_SCOPE_NAME_LEN}

//
// Scope names are unicode. SNMP and MZAP use UTF-8 encoding.
//

type
SN_CHAR = WCHAR;
{$EXTERNALSYM SN_CHAR}
SCOPE_NAME_BUFFER = array [0..MAX_SCOPE_NAME_LEN] of SN_CHAR;
{$EXTERNALSYM SCOPE_NAME_BUFFER}
SCOPE_NAME = ^SN_CHAR;
{$EXTERNALSYM SCOPE_NAME}

PMIB_IPMCAST_SCOPE = ^MIB_IPMCAST_SCOPE;
{$EXTERNALSYM PMIB_IPMCAST_SCOPE}
_MIB_IPMCAST_SCOPE = record
dwGroupAddress: DWORD;
dwGroupMask: DWORD;
snNameBuffer: SCOPE_NAME_BUFFER;
dwStatus: DWORD;
end;
{$EXTERNALSYM _MIB_IPMCAST_SCOPE}
MIB_IPMCAST_SCOPE = _MIB_IPMCAST_SCOPE;
{$EXTERNALSYM MIB_IPMCAST_SCOPE}
TMibIpmCastScope = MIB_IPMCAST_SCOPE;
PMibIpmCastScope = PMIB_IPMCAST_SCOPE;

PMIB_IPDESTROW = ^MIB_IPDESTROW;
{$EXTERNALSYM PMIB_IPDESTROW}
_MIB_IPDESTROW = record
ForwardRow: MIB_IPFORWARDROW;
dwForwardPreference: DWORD;
dwForwardViewSet: DWORD;
end;
{$EXTERNALSYM _MIB_IPDESTROW}
MIB_IPDESTROW = _MIB_IPDESTROW;
{$EXTERNALSYM MIB_IPDESTROW}
TMibIpDestRow = MIB_IPDESTROW;
PMibIpDestRow = PMIB_IPDESTROW;

PMIB_IPDESTTABLE = ^MIB_IPDESTTABLE;
{$EXTERNALSYM PMIB_IPDESTTABLE}
_MIB_IPDESTTABLE = record
dwNumEntries: DWORD;
table: array [0..ANY_SIZE - 1] of MIB_IPDESTROW;
end;
{$EXTERNALSYM _MIB_IPDESTTABLE}
MIB_IPDESTTABLE = _MIB_IPDESTTABLE;
{$EXTERNALSYM MIB_IPDESTTABLE}
TMibIpDestTable = MIB_IPDESTTABLE;
PMibIpDestTable = PMIB_IPDESTTABLE;

PMIB_BEST_IF = ^MIB_BEST_IF;
{$EXTERNALSYM PMIB_BEST_IF}
_MIB_BEST_IF = record
dwDestAddr: DWORD;
dwIfIndex: DWORD;
end;
{$EXTERNALSYM _MIB_BEST_IF}
MIB_BEST_IF = _MIB_BEST_IF;
{$EXTERNALSYM MIB_BEST_IF}
TMibBestIf = MIB_BEST_IF;
PMibBestIf = PMIB_BEST_IF;

PMIB_PROXYARP = ^MIB_PROXYARP;
{$EXTERNALSYM PMIB_PROXYARP}
_MIB_PROXYARP = record
dwAddress: DWORD;
dwMask: DWORD;
dwIfIndex: DWORD;
end;
{$EXTERNALSYM _MIB_PROXYARP}
MIB_PROXYARP = _MIB_PROXYARP;
{$EXTERNALSYM MIB_PROXYARP}
TMibProxyArp = MIB_PROXYARP;
PMibProxyArp = PMIB_PROXYARP;

PMIB_IFSTATUS = ^MIB_IFSTATUS;
{$EXTERNALSYM PMIB_IFSTATUS}
_MIB_IFSTATUS = record
dwIfIndex: DWORD;
dwAdminStatus: DWORD;
dwOperationalStatus: DWORD;
bMHbeatActive: BOOL;
bMHbeatAlive: BOOL;
end;
{$EXTERNALSYM _MIB_IFSTATUS}
MIB_IFSTATUS = _MIB_IFSTATUS;
{$EXTERNALSYM MIB_IFSTATUS}
TMibIfStatus = MIB_IFSTATUS;
PMibIfStatus = PMIB_IFSTATUS;

PMIB_ROUTESTATE = ^MIB_ROUTESTATE;
{$EXTERNALSYM PMIB_ROUTESTATE}
_MIB_ROUTESTATE = record
bRoutesSetToStack: BOOL;
end;
{$EXTERNALSYM _MIB_ROUTESTATE}
MIB_ROUTESTATE = _MIB_ROUTESTATE;
{$EXTERNALSYM MIB_ROUTESTATE}
TMibRouteState = MIB_ROUTESTATE;
PMibRouteState = PMIB_ROUTESTATE;

//////////////////////////////////////////////////////////////////////////////
// //
// All the info passed to (SET/CREATE) and from (GET/GETNEXT/GETFIRST) //
// IP Router Manager is encapsulated in the following "discriminated" //
// union. To pass, say MIB_IFROW, use the following code //
// //
// PMIB_OPAQUE_INFO pInfo; //
// PMIB_IFROW pIfRow; //
// DWORD rgdwBuff[(MAX_MIB_OFFSET + sizeof(MIB_IFROW))/sizeof(DWORD) + 1]; //
// //
// pInfo = (PMIB_OPAQUE_INFO)rgdwBuffer; //
// pIfRow = (MIB_IFROW *)(pInfo->rgbyData); //
// //
// This can also be accomplished by using the following macro //
// //
// DEFINE_MIB_BUFFER(pInfo,MIB_IFROW, pIfRow); //
// //
//////////////////////////////////////////////////////////////////////////////

type
PMibOpaqueInfo = ^TMibOpaqueInfo;
_MIB_OPAQUE_INFO = record
dwId: DWORD;
case Integer of
0: (ullAlign: Int64); // ULONGLONG (unsigned!)
1: (rgbyData: array [0..0] of BYTE);
end;
{$EXTERNALSYM _MIB_OPAQUE_INFO}
MIB_OPAQUE_INFO = _MIB_OPAQUE_INFO;
{$EXTERNALSYM MIB_OPAQUE_INFO}
TMibOpaqueInfo = MIB_OPAQUE_INFO;

const
MAX_MIB_OFFSET = 8;
{$EXTERNALSYM MAX_MIB_OFFSET}

// #define MIB_INFO_SIZE(S) (MAX_MIB_OFFSET + sizeof(S))

// #define MIB_INFO_SIZE_IN_DWORDS(S) /
// ((MIB_INFO_SIZE(S))/sizeof(DWORD) + 1)

// #define DEFINE_MIB_BUFFER(X,Y,Z) /
// DWORD __rgdwBuff[MIB_INFO_SIZE_IN_DWORDS(Y)]; /
// PMIB_OPAQUE_INFO X = (PMIB_OPAQUE_INFO)__rgdwBuff; /
// Y * Z = (Y *)(X->rgbyData)

// #define CAST_MIB_INFO(X,Y,Z) Z = (Y)(X->rgbyData)

implementation

end.
 
主程序:arp.dpr


{******************************************************************}
{ }
{ Arp.dpr - IP Helper API Demonstration project }
{ }
{ Portions created by Marcel van Brakel are }
{ Copyright (C) 2000 Marcel van Brakel. }
{ All Rights Reserved. }
{ }
{ The original file is: Arp.dpr, released December 2000. }
{ The initial developer of the Pascal code is Marcel van Brakel }
{ (brakelm@chello.nl). }
{ }
{ Contributor(s): Vladimir Vassiliev (voldemarv@hotpop.com) }
{ John Penman (jcp@craiglockhart.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. }
{ }
{ 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/NPL/NPL-1_1Final.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. }
{ }
{******************************************************************}

program Arp;

{$APPTYPE CONSOLE}

uses
Windows, SysUtils, Winsock,
IpExport, IpHlpApi, IpTypes, IpIfConst, IpRtrMib;

//------------------------------------------------------------------------------

// Convert IP address to dotted decimal

function IpAddrToString(Addr: DWORD): string;
var
inad: in_addr;
begin
inad.s_addr := Addr;
Result := inet_ntoa(inad);
end;

//------------------------------------------------------------------------------

function StringToIpAddr(const Addr: string): DWORD;
begin
Result := inet_addr(PChar(Addr));
end;

//------------------------------------------------------------------------------

// Converts a physical address to a string. Length is the number of entries in
// the PhysAddr array and PhysAddr itself is the array which contains the
// "encoded" physical address

type
TPhysAddrByteArray = array [0..MAXLEN_PHYSADDR - 1] of BYTE;

function PhysAddrToString(Length: DWORD; PhysAddr: TPhysAddrByteArray): string;
var
I: Integer;
begin
Result := '';
if Length = 0 then Exit;
for I := 0 to Length - 1 do
if I = Integer(Length - 1) then
Result := Result + Format('%.2x', [PhysAddr])
else
Result := Result + (Format('%.2x-', [PhysAddr]));
end;

//------------------------------------------------------------------------------

function CharHex(const C: AnsiChar): Byte;
const
AnsiDecDigits = ['0'..'9'];
AnsiHexDigits = ['0'..'9', 'A'..'F', 'a'..'f'];
begin
Result := $FF;
if C in AnsiDecDigits then
Result := Ord(C) - 48
else if C in AnsiHexDigits then
Result := Ord(C) - 55;
end;

procedure StringToPhysAddr(PhysAddrString: string; var PhysAddr: TPhysAddrByteArray);
var
C: Char;
I, V: Integer;
begin
Assert(Length(PhysAddrString) = 17);
Assert(
(PhysAddrString[3] = '-') and
(PhysAddrString[6] = '-') and
(PhysAddrString[9] = '-') and
(PhysAddrString[12] = '-') and
(PhysAddrString[15] = '-'));
PhysAddrString := UpperCase(PhysAddrString);
for I := 0 to 5 do
begin
C := PhysAddrString[I * 3];
V := CharHex(C) shl 4;
C := PhysAddrString[(I * 3) + 1];
V := V + CharHex(C);
PhysAddr := V;
end;
end;

//------------------------------------------------------------------------------

// Returns the IP address table. The caller must free the memory.

function GetIpAddrTableWithAlloc: PMibIpAddrTable;
var
Size: ULONG;
begin
Size := 0;
GetIpAddrTable(nil, Size, True);
Result := AllocMem(Size);
if GetIpAddrTable(Result, Size, True) <> NO_ERROR then
begin
FreeMem(Result);
Result := nil;
end;
end;

//------------------------------------------------------------------------------

// Returns the IP address (dotted decimal string representation) of the interface
// with the specified index. IpAddrTable is used for the lookup and must be
// sorted. If IpAddrTable is nil, the returned string is '<unknown>'

function IntfIndexToIpAddress(IpAddrTable: PMibIpAddrTable; Index: DWORD): string;
var
I: Integer;
begin
if IpAddrTable = nil then
Result := '<unknown>'
else
begin
for I := 0 to IpAddrTable^.dwNumEntries - 1 do
begin
{$R-}
if IpAddrTable^.table.dwIndex = Index then
begin
Result := IpAddrToString(IpAddrTable^.table.dwAddr);
Break;
end;
{$R+}
end;
end;
end;

//------------------------------------------------------------------------------

// Returns a string representing the ARP entry type

function ArpTypeToString(dwType: DWORD): string;
begin
case dwType of
MIB_IPNET_TYPE_OTHER: Result := 'Other';
MIB_IPNET_TYPE_INVALID: Result := 'Invalid';
MIB_IPNET_TYPE_DYNAMIC: Result := 'Dynamic';
MIB_IPNET_TYPE_STATIC: Result := 'Static';
end;
end;

//------------------------------------------------------------------------------

// Displays the ARP table. Filter specifies an IP address for which to display
// ARP entries. If filter is an empty string, all ARP entries are displayed.

procedure DisplayArpTable(const Filter: string);
var
Size: ULONG;
I: Integer;
NetTable: PMibIpNetTable; // ARP table
NetRow: TMibIpNetRow; // ARP entry from ARP table
CurrentIndex: DWORD; // Used for displaying a header in case of multiple interfaces
IpAddrTable: PMibIpAddrTable; // Address table used for interface index to IP address mapping
begin
Size := 0;
GetIpNetTable(nil, Size, True);
NetTable := AllocMem(Size);
try
if GetIpNetTable(NetTable, Size, True) = NO_ERROR then
begin
// Get the IP address table
IpAddrTable := GetIpAddrTableWithAlloc;
try
// Remember the first interface index and display header
CurrentIndex := NetTable^.table[0].dwIndex;
WriteLn(Format('Interface: %s on Interface 0x%u', [IntfIndexToIpAddress(IpAddrTable, CurrentIndex), CurrentIndex]));
WriteLn(' Internet address Physical address Type');
// For each ARP entry
for I := 0 to NetTable^.dwNumEntries - 1 do
begin
{$R-}NetRow := NetTable^.table;{$R+}
if CurrentIndex <> NetRow.dwIndex then
begin
// We're changing interfaces, display a new header
CurrentIndex := NetRow.dwIndex;
WriteLn;
WriteLn(Format('Interface: %s on Interface 0x%u',
[IntfIndexToIpAddress(IpAddrTable, CurrentIndex), CurrentIndex]));
WriteLn(' Internet address Physical address Type');
end;
// Only display the entry if it matches the filter
if (Filter = '') or (Filter = IpAddrToString(NetRow.dwAddr)) then
WriteLn(Format(' %-20s %-20s %s', [
IpAddrToString(NetRow.dwAddr),
PhysAddrToString(NetRow.dwPhysAddrLen, TPhysAddrByteArray(NetRow.bPhysAddr)),
ArpTypeToString(NetRow.dwType)]));
end;
finally
FreeMem(IpAddrTable);
end;
end
else
begin
// Assume failure of GetIpNetTable means there are no ARP entries. This is
// usually the case but it could fail for other reasons.
WriteLn('No ARP entries found.');
end;
finally
FreeMem(NetTable);
end;
end;

//------------------------------------------------------------------------------

// Deletes Host from the ARP table. Host is either an IP address or '*'. In the
// latter case all hosts are deleted from the ARP table. Intf is the internet
// address (IP address) of the interface for which to delete the applicable
// ARP entries. If empty, Host is deleted from each interface ARP table.

function IpAddressToAdapterIndex(const Intf: string): Integer; overload;
var
Adapters, Adapter: PIpAdapterInfo;
Size: ULONG;
IpAddrString: PIpAddrString;
begin
Result := -1;
Size := 0;
if GetAdaptersInfo(nil, Size) <> ERROR_BUFFER_OVERFLOW then Exit;
Adapters := AllocMem(Size);
try
if GetAdaptersInfo(Adapters, Size) = NO_ERROR then
begin
Adapter := Adapters;
while Adapter <> nil do
begin
IpAddrString := @Adapter^.IpAddressList;
while IpAddrString <> nil do
begin
if CompareText(IpAddrString^.IpAddress.S, Intf) = 0 then
begin
Result := Adapter^.Index;
Exit;
end;
IpAddrString := IpAddrString^.Next;
end;
Adapter := Adapter^.Next;
end;
end;
finally
FreeMem(Adapters);
end;
end;

function IpAddressToAdapterIndex(const Intf: DWORD): Integer; overload;
var
Size: ULONG;
AddrTable: PMibIpAddrTable;
AddrRow: TMibIpAddrRow;
I: Integer;
begin
Result := -1;
Size := 0;
if GetIpAddrTable(nil, Size, True) <> ERROR_INSUFFICIENT_BUFFER then Exit;
AddrTable := AllocMem(Size);
try
if GetIpAddrTable(AddrTable, Size, True) = NO_ERROR then
begin
for I := 0 to AddrTable^.dwNumEntries - 1 do
begin
{$R-}AddrRow := AddrTable^.Table;{$R+}
if AddrRow.dwAddr = Intf then
begin
Result := AddrRow.dwIndex;
Break;
end;
end;
end;
finally
FreeMem(AddrTable);
end;
end;

procedure DeleteArpEntry(const Host, Intf: string);
var
Entry: TMibIpNetRow;
HostAddr, IntfAddr: DWORD;
Size: ULONG;
Adapters, Adapter: PIpAdapterInfo;
begin
FillChar(Entry, SizeOf(Entry), 0);

HostAddr := 0; // shuts up the compiler
if Host <> '*' then
begin
HostAddr := inet_addr(PChar(Host));
if HostAddr = DWORD(INADDR_NONE) then Exit;
end;
if Intf <> '' then
begin
IntfAddr := inet_addr(PChar(Intf));
if IntfAddr = DWORD(INADDR_NONE) then Exit;
end;

{ delete address from interface }

if (Host <> '*') and (Intf <> '') then
begin
Entry.dwIndex := IpAddressToAdapterIndex(Intf);
Entry.dwAddr := HostAddr;
if DeleteIpNetEntry(Entry) = NO_ERROR then
WriteLn('Deleted')
else
WriteLn('Failed');
Exit;
end;

{ delete all addresses from an interface }

if (Host = '*') and (Intf <> '') then
begin
FlushIpNetTable(IpAddressToAdapterIndex(Intf));
Exit;
end;


Size := 0;
if GetAdaptersInfo(nil, Size) <> ERROR_BUFFER_OVERFLOW then Exit;
Adapters := AllocMem(Size);
try
if GetAdaptersInfo(Adapters, Size) = NO_ERROR then
begin
Adapter := Adapters;
while Adapter <> nil do
begin

{ delete all addresses from each interface }

if (Host = '*') and (Intf = '') then
begin
FlushIpNetTable(Adapter.Index);
end;

{ delete address from each interface }

if (Host <> '*') and (Intf = '') then
begin
FillChar(Entry, SizeOf(Entry), 0);
Entry.dwIndex := Adapter.Index;
Entry.dwAddr := HostAddr;
DeleteIpNetEntry(Entry);
end;

Adapter := Adapter^.Next;
end;
end;
finally
FreeMem(Adapters);
end;

end;

//------------------------------------------------------------------------------

// Returns the interface index of the first ...

function FirstNetworkAdapter(IpAddrTable: PMibIpAddrTable): Integer;
var
I: Integer;
IfInfo: TMibIfRow;
begin
// TODO this is a "stupid" implementation, can be done much easier by using
// enumerating the interface table directly
Result := -1;
for I := 0 to IpAddrTable^.dwNumEntries - 1 do
begin
{$R-}IfInfo.dwIndex := IpAddrTable^.table.dwIndex;{$R+}
if GetIfEntry(@IfInfo) = NO_ERROR then
begin
if IfInfo.dwType in [MIB_IF_TYPE_ETHERNET, MIB_IF_TYPE_TOKENRING] then
begin
Result := IfInfo.dwIndex;
Break;
end;
end;
end;
end;

//------------------------------------------------------------------------------

// Adds an entry to the ARP table. InetAddr is the IP address to add, EtherAddr
// is the ethernet address to associate with the InetAddr and IntfAddr is the
// index of the adapter to add this ARP entry to. If IntfAddr is an empty string
// the function uses the first network adapter (tokenring or ethernet) it can
// find.

procedure SetArpEntry(const InetAddr, EtherAddr, IntfAddr: string);
var
Entry: TMibIpNetRow;
IpAddrTable: PMibIpAddrTable;
begin
FillChar(Entry, SizeOf(Entry), 0);
Entry.dwAddr := StringToIpAddr(InetAddr);
Assert(Entry.dwAddr <> DWORD(INADDR_NONE));
Entry.dwPhysAddrLen := 6;
StringToPhysAddr(EtherAddr, TPhysAddrByteArray(Entry.bPhysAddr));
Entry.dwType := MIB_IPNET_TYPE_STATIC;
if IntfAddr <> '' then
Entry.dwIndex := StrToInt(IntfAddr)
else
begin
IpAddrTable := GetIpAddrTableWithAlloc;
Assert(IpAddrTable <> nil);
Entry.dwIndex := FirstNetworkAdapter(IpAddrTable);
FreeMem(IpAddrTable);
end;
WriteLn(SysErrorMessage(SetIpNetEntry(Entry)));
end;

//------------------------------------------------------------------------------

// How is this program to be used by the end user?

procedure Usage;
begin
WriteLn('Displays and modifies the IP-to-Physical address translation table used by');
WriteLn('the address resolution protocol (ARP).');
WriteLn;
WriteLn('ARP -s inet_addr eth_addr [if_addr]');
WriteLn('ARP -d inet_addr [if_addr]');
WriteLn('ARP -a inet_addr [-N if_addr]');
WriteLn;
WriteLn(' -a Displays current ARP entries by interrogating the current protocol');
WriteLn(' data. If inet_addr is specified, the IP and physical addresses for');
WriteLn(' only the specified computer are displayed. If more than one network');
WriteLn(' interface uses ARP, entries for each for each ARP table are displayed.');
WriteLn(' -g Same as -a');
WriteLn(' inet_addr Specifies an internet address.');
WriteLn(' -N if_addr Displays the ARP entries for the network interface specified by if_addr.');
WriteLn(' -d Deletes the host specified by inet_addr. inet_addr may be wildcarded');
WriteLn(' with * to delete all hosts.');
WriteLn(' -s Adds the host and associates the internet address inet_addr with the');
WriteLn(' physical address eth_addr. The physical address is given as 6');
WriteLn(' hexadecimal bytes separated by hyphens. The entry is permanent.');
WriteLn(' eth_addr Specifies a physical address.');
WriteLn(' if_addr If present, this specifies the index of the interface whose address');
WriteLn(' translation tables should be modified. If not present the first found');
WriteLn(' applicable interface will be used.');
WriteLn('Example:');
WriteLn(' > arp -s 157.55.85.212 00-aa-00-62-c6-09 .... Adds a static entry');
WriteLn(' > arp -a .... Displays the ARP table');
WriteLn(' > arp -d * .... Flushes the ARP table');
end;

begin

WriteLn('');
WriteLn('Windows 2000 Arp');
WriteLn('Copyright (C) 2000 Marcel van Brakel');
WriteLn('');

if (ParamCount = 0) or FindCmdLineSwitch('?', ['/', '-'], True) then
begin
Usage;
Exit;
end;

// Case statement (in disquise) on the command line switches which dispatches
// to the appropriate subroutine for further processing.

if FindCmdLineSwitch('a', ['/', '-'], True) or FindCmdLineSwitch('g', ['/', '-'], True) then
DisplayArpTable(ParamStr(2))
else if FindCmdLineSwitch('d', ['/', '-'], True) then
DeleteArpEntry(ParamStr(2), ParamStr(3))
else if FindCmdLineSwitch('s', ['/', '-'], True) then
SetArpEntry(ParamStr(2), ParamStr(3), ParamStr(4))
else
Usage;

end.
 
多人接受答案了。
 
后退
顶部