vpn和路由表的问题[分不够再加] ( 积分: 300 )

  • 主题发起人 主题发起人 Miros
  • 开始时间 开始时间
M

Miros

Unregistered / Unconfirmed
GUEST, unregistred user!
2个问题
1.用win2003srv中的 “路由和远程访问”建立了vpn服务器,如何让客户端连接时可以指定ip 如分配的ip段是12.10.10.4 - 12.10.10.253 那么客户端可在其ip段内选择一个ip

2.如何或用哪些api向windows路由表添加/删除 路由信息(不用启动cmd.exe 并且传参的方法。也不用批处理) 被添加的路由信息最好是重新启动后不保存的。

提供有效思路或方案的额外再送分。急。
 
iphlp api 我到处说它 哈哈~
 
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.
 
unit IPHelper;



//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
// Delphi IPHelper functions //
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
// PLEASE NOTE: REQUIRES NT4/SP4 or higher, WIN98 or higher //
// Tested on : Delphi 4.03, Delphi 6.0 Enterprise, //
// WIN2K, WIN-NT4/SP6, WIN98se //
// //
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
// This software is FREEWARE //
// ------------------------- //
// If this software works, it was surely written by Dirk Claessens //
// <dirkCL@pandora.be> //
// (If it doesn't, I don't know anything about it.) //
// Version: 1.5 2002-08-21 //
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//


interface

uses
Windows, Messages, SysUtils, Classes, Dialogs, IpHlpApi,IpExport,IpIfConst,IpRtrMib,IPTypes;

const
NULL_IP = ' 0. 0. 0. 0';

//------conversion of well-known port numbers to service names----------------

type
TWellKnownPort = record
Prt: DWORD;
Srv: string[20];
end;

PTTcpConnStatus = ^TTcpConnStatus;
TTcpConnStatus = record
LocalIP : string;
LocalPort : string;
RemoteIP : string;
RemotePort : string;
Status : string;
end;


const
// only most &quot;popular&quot; services...
WellKnownPorts: array[1..29] of TWellKnownPort
= (
( Prt: 0; Srv: 'LOOPBACK'),
( Prt: 7; Srv: 'ECHO' ), {Ping }
( Prt: 9; Srv: 'DISCRD' ), { Discard}
( Prt: 13; Srv: 'DAYTIM' ), {DayTime}
( Prt: 17; Srv: 'QOTD' ), {Quote Of The Day}
( Prt: 19; Srv: 'CHARGEN' ), {CharGen}
( Prt: 20; Srv: 'FTP ' ), { File Transfer Protocol}
( Prt: 21; Srv: 'FTPC' ), { File Transfer Control Protocol}
( Prt: 23; Srv: 'TELNET' ), {TelNet}
( Prt: 25; Srv: 'SMTP' ), { Simple Mail Transfer Protocol}
( Prt: 37; Srv: 'TIME' ), { Time Protocol }
( Prt: 43; Srv: 'WHOIS'), { WHO IS service }
( Prt: 53; Srv: 'DNS ' ), { Domain Name Service }
( Prt: 67; Srv: 'BOOTPS' ), { BOOTP Server }
( Prt: 68; Srv: 'BOOTPC' ), { BOOTP Client }
( Prt: 69; Srv: 'TFTP' ), { Trivial FTP }
( Prt: 70; Srv: 'GOPHER' ), { Gopher }
( Prt: 79; Srv: 'FING' ), { Finger }
( Prt: 80; Srv: 'HTTP' ), { HTTP }
( Prt: 88; Srv: 'KERB' ), { Kerberos }
( Prt: 109; Srv: 'POP2' ), { Post Office Protocol Version 2 }
( Prt: 110; Srv: 'POP3' ), { Post Office Protocol Version 3 }
( Prt: 119; Srv: 'NNTP' ), { Network News Transfer Protocol }
( Prt: 123; Srv: 'NTP ' ), { Network Time protocol }
( Prt: 135; Srv: 'LOCSVC'), { Location Service }
( Prt: 137; Srv: 'NBNAME' ), { NETBIOS Name service }
( Prt: 138; Srv: 'NBDGRAM' ), { NETBIOS Datagram Service }
( Prt: 139; Srv: 'NBSESS' ), { NETBIOS Session Service }
( Prt: 161; Srv: 'SNMP' ) { Simple Netw. Management Protocol }
);


//-----------conversion of ICMP error codes to strings--------------------------
{taken from www.sockets.com/ms_icmp.c }

const
ICMP_ERROR_BASE = 11000;
IcmpErr : array[1..22] of string =
(
'IP_BUFFER_TOO_SMALL','IP_DEST_NET_UNREACHABLE', 'IP_DEST_HOST_UNREACHABLE',
'IP_PROTOCOL_UNREACHABLE', 'IP_DEST_PORT_UNREACHABLE', 'IP_NO_RESOURCES',
'IP_BAD_OPTION','IP_HARDWARE_ERROR', 'IP_PACKET_TOO_BIG', 'IP_REQUEST_TIMED_OUT',
'IP_BAD_REQUEST','IP_BAD_ROUTE', 'IP_TTL_EXPIRED_TRANSIT',
'IP_TTL_EXPIRED_REASSEM','IP_PARAMETER_PROBLEM', 'IP_SOURCE_QUENCH',
'IP_OPTION_TOO_BIG', 'IP_BAD_DESTINATION','IP_ADDRESS_DELETED',
'IP_SPEC_MTU_CHANGE', 'IP_MTU_CHANGE', 'IP_UNLOAD'
);


//----------conversion of various enumerated values to strings----------------//

ARPEntryType : array[1..4] of string = ( 'Other', 'Invalid',
'Dynamic', 'Static'
);

TCPConnState : // TCP connection states
array[1..12] of string =
( 'closed', 'listening', 'syn_sent',
'syn_rcvd', 'established', 'fin_wait1',
'fin_wait2', 'close_wait', 'closing',
'last_ack', 'time_wait', 'delete_tcb'
);

TCPToAlgo : array[1..4] of string = // TCP time out algorithms
( 'Const.Timeout', 'MIL-STD-1778',
'Van Jacobson', 'Other' );

IPForwTypes : array[1..4] of string = // IP forwarding methods
( 'other', 'invalid', 'local', 'remote' );

IPForwProtos : array[1..18] of string = // IP forwarding protocols
( 'OTHER', 'LOCAL', 'NETMGMT', 'ICMP', 'EGP',
'GGP', 'HELO', 'RIP', 'IS_IS', 'ES_IS',
'CISCO', 'BBN', 'OSPF', 'BGP', 'BOOTP',
'AUTO_STAT', 'STATIC', 'NOT_DOD' );


//---------------exported stuff-----------------------------------------------

// data output to Tstrings for display purposes
procedure Get_AdaptersInfo( List: TStrings );
procedure Get_NetworkParams( List: TStrings );
procedure Get_ARPTable( List: TStrings );
procedure Get_TCPTable( List: TStrings );
procedure Get_TCPStatistics( List: TStrings );
procedure Get_UDPTable( List: TStrings );
procedure Get_UDPStatistics( List: TStrings );
procedure Get_IPAddrTable( List: TStrings );
procedure Get_IPForwardTable( List: TStrings );
procedure Get_IPStatistics( List: TStrings );
function Get_RTTAndHopCount( IPAddr: DWORD; MaxHops: Longint;
var RTT: longint; var HopCount: longint ): integer;
procedure Get_ICMPStats( ICMPIn, ICMPOut: TStrings );
procedure Get_IfTable( NameList, ItemList: TStrings );
procedure Get_IfTableMIB( var MIBIfArray: TMIBIfArray );
procedure Get_IPAddrTableMIB( var IPAddrTable:TMibIPAddrArray );



procedure Get_RecentDestIPs( List: TStrings );

// added functions
procedure Get_OpenConnections( List: TList );



// conversion utils
function MacAddr2Str( MacAddr: TMacAddress; size: integer ): string;
function IpAddr2Str( IPAddr: DWORD ): string;
function Str2IpAddr( IPStr: string ): DWORD;
function Port2Str( nwoPort: DWORD ): string;
function Port2Wrd( nwoPort: DWORD ): DWORD;
function Port2Svc( Port: DWORD ): string;
function ICMPErr2Str( ICMPErrCode: DWORD) : string;

implementation

var
RecentIPs : TStringList;

//--------------General utilities-----------------------------------------------

{ extracts next &quot;token&quot; from string, then eats string }
function NextToken( var s: string; Separator: char ): string;
var
Sep_Pos : byte;
begin
Result := '';
if length( s ) > 0 then begin
Sep_Pos := pos( Separator, s );
if Sep_Pos > 0 then begin
Result := copy( s, 1, Pred( Sep_Pos ) );
Delete( s, 1, Sep_Pos );
end
else begin
Result := s;
s := '';
end;
end;
end;

//------------------------------------------------------------------------------
{ converts numerical MAC-address to ww-xx-yy-zz string }
function MacAddr2Str( MacAddr: TMacAddress; size: integer ): string;
var
i : integer;
begin
if Size = 0 then
begin
Result := '00-00-00-00-00-00';
EXIT;
end
else Result := '';
//
for i := 1 to Size do
Result := Result + IntToHex( MacAddr, 2 ) + '-';
Delete( Result, Length( Result ), 1 );
end;

//------------------------------------------------------------------------------
{ converts IP-address in network byte order DWORD to dotted decimal string}
function IpAddr2Str( IPAddr: DWORD ): string;
var
i : integer;
begin
Result := '';
for i := 1 to 4 do
begin
Result := Result + Format( '%3d.', [IPAddr and $FF] );
IPAddr := IPAddr shr 8;
end;
Delete( Result, Length( Result ), 1 );
end;

//------------------------------------------------------------------------------
{ converts dotted decimal IP-address to network byte order DWORD}
function Str2IpAddr( IPStr: string ): DWORD;
var
i : integer;
Num : DWORD;
begin
Result := 0;
for i := 1 to 4 do
try
Num := ( StrToInt( NextToken( IPStr, '.' ) ) ) shl 24;
Result := ( Result shr 8 ) or Num;
except
Result := 0;
end;

end;

//------------------------------------------------------------------------------
{ converts port number in network byte order to DWORD }
function Port2Wrd( nwoPort: DWORD ): DWORD;
begin
Result := Swap( WORD( nwoPort ) );
end;

//------------------------------------------------------------------------------
{ converts port number in network byte order to string }
function Port2Str( nwoPort: DWORD ): string;
begin
Result := IntToStr( Port2Wrd( nwoPort ) );
end;

//------------------------------------------------------------------------------
{ converts well-known port numbers to service ID }
function Port2Svc( Port: DWORD ): string;
var
i : integer;
begin
Result := Format( '%4d', [Port] ); // in case port not found
for i := Low( WellKnownPorts ) to High( WellKnownPorts ) do
if Port = WellKnownPorts.Prt then
begin
Result := WellKnownPorts.Srv;
BREAK;
end;
end;

//-----------------------------------------------------------------------------
{ general, fixed network parameters }
procedure Get_NetworkParams( List: TStrings );
var
InfoSize : Longint;
ErrorCode : DWORD;
pBuf : PChar;
begin
if not Assigned( List ) then EXIT;
List.Clear;
InfoSize := 0;
ErrorCode := GetNetworkParams( PTFixedInfo(pBuf), @InfoSize );
GetMem( pBuf, InfoSize );
ErrorCode := GetNetworkParams( PTFixedInfo(pBuf), @InfoSize );
if ErrorCode = ERROR_SUCCESS then
with PTFixedinfo(pBuf)^ do
begin
List.Add( 'HOSTNAME : ' + string( HostName ) );
List.Add( 'DOMAIN : ' + string( DomainName ) );
List.Add( 'SCOPE : ' + string( ScopeID ) );
List.Add( 'NETBIOS NODE TYPE : ' + NETBIOSTypes[NodeType] );
List.Add( 'ROUTING ENABLED :' + IntToStr( EnableRouting ) );
List.Add( 'PROXY ENABLED :' + IntToStr( EnableProxy ) );
List.Add( 'DNS ENABLED :' + IntToHex( EnableDNS,8 ) );
end
else
List.Add( SysErrorMessage( ErrorCode ) );
FreeMem(pBuf);
end;

//------------------------------------------------------------------------------
function ICMPErr2Str( ICMPErrCode: DWORD) : string;
var
i : integer;
begin
Result := 'UnknownError : ' + IntToStr( ICMPErrCode );
dec( ICMPErrCode, ICMP_ERROR_BASE );
if ICMPErrCode in [Low(ICMpErr)..High(ICMPErr)] then
Result := ICMPErr[ ICMPErrCode];
end;




//------------------------------------------------------------------------------
procedure Get_IfTable( NameList, ItemList: TStrings );
var
IfRow : TMibIfRow;
i,
Error,
TableSize : integer;
pBuf : PChar;
NumEntries : DWORD;
sDescr,
Temp : string;
begin
if (not Assigned( NameList ))
or (not Assigned( ItemList )) then EXIT;
NameList.Clear;
ItemList.Clear;
TableSize := 0;
// first call: get memsize needed
Error := GetIfTable( PTMibIfTable( pBuf ), @TableSize, false );
if Error <> ERROR_INSUFFICIENT_BUFFER then
EXIT;
GetMem( pBuf, TableSize );

// get table pointer
Error := GetIfTable( PTMibIfTable( pBuf ), @TableSize, false );
if Error = NO_ERROR then
begin
NumEntries := PTMibIfTable( pBuf )^.dwNumEntries;
if NumEntries > 0 then
begin
inc( pBuf, SizeOf( NumEntries ) );
for i := 1 to NumEntries do
begin
IfRow := PTMibIfRow( pBuf )^;
with IfRow do
begin
SetLength( sDescr, dwDescrLen );
move( bDescr, sDescr[1], Length( sDescr ) );
sDescr := trim( sDescr );
NameList.Add( sDescr );
ItemList.Add( Format( '%0.8x|%2d| %16s| %4d| %8d| %8d| %8d',
[dwIndex, dwType,
MacAddr2Str( TMacAddress( bPhysAddr ), dwPhysAddrLen )
, dwMTU, dwSpeed,
dwInOctets, dwOutOctets,
dwOPerStatus] )
);
end;
inc( pBuf, SizeOf( IfRow ) );
end;
end
else begin
NameList.Add( 'no entries');
ItemList.Add( 'no data' );
end;
end
else begin
NameList.Add( 'Oops');
ItemList.Add( SysErrorMessage( GetLastError ) );
end;
dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( IfRow ) );
FreeMem( pBuf );
end;



//------------------------------------------------------------------------------
procedure Get_IfTableMIB( var MIBIfArray: TMIBIfArray );
var
i,
Error,
TableSize : integer;
pBuf : PChar;
NumEntries : DWORD;
sDescr,
Temp : string;
begin
TableSize := 0;
// first call: get memsize needed
Error := GetIfTable( PTMibIfTable( pBuf ), @TableSize, false );
if Error <> ERROR_INSUFFICIENT_BUFFER then
EXIT;
GetMem( pBuf, TableSize );

// get table pointer
Error := GetIfTable( PTMibIfTable( pBuf ), @TableSize, false );
if Error = NO_ERROR then
begin
NumEntries := PTMibIfTable( pBuf )^.dwNumEntries;
if NumEntries > 0 then
begin
SetLength( MIBIfArray, NumEntries );
inc( pBuf, SizeOf( NumEntries ) );
for i := 0 to pred(NumEntries) do
begin
MIBIfArray := PTMibIfRow( pBuf )^;
inc( pBuf, SizeOf( TMIBIfRow ) );
end;
end
end;
dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( TMIBIfRow ) );
FreeMem( pBuf );
end;



//------------------------------------------------------------------------------
procedure Get_IPAddrTableMIB( var IPAddrTable:TMibIPAddrArray );
var
IPAddrRow : TMibIPAddrRow;
TableSize : DWORD;
ErrorCode : DWORD;
i : integer;
pBuf : PChar;
NumEntries : DWORD;
begin
TableSize := 0; ;
// first call: get table length
ErrorCode := GetIpAddrTable( PTMibIPAddrTable( pBuf ), @TableSize, true );
if Errorcode <> ERROR_INSUFFICIENT_BUFFER then
EXIT;

GetMem( pBuf, TableSize );
// get table
ErrorCode := GetIpAddrTable( PTMibIPAddrTable( pBuf ), @TableSize, true );
if ErrorCode = NO_ERROR then
begin
NumEntries := PTMibIPAddrTable( pBuf )^.dwNumEntries;
if NumEntries > 0 then
begin
SetLength( IPAddrTable, NumEntries);
inc( pBuf, SizeOf( DWORD ) );
for i := 1 to NumEntries do
begin
IPAddrTable[ i-1 ] := PTMIBIPAddrRow( pBuf )^;
inc( pBuf, SizeOf( TMIBIPAddrRow ) );
end;
end;
end;

// we must restore pointer!
dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( IPAddrRow ) );
FreeMem( pBuf );
end;



//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
procedure Get_AdaptersInfo( List: TStrings );
var
Error,
BufLen : DWORD;
P : Pointer;
AdapterInfo : PTIP_ADAPTER_INFO;
Descr,
LocalIP,
GatewayIP,
DHCPIP : string;
begin
if not Assigned( List ) then EXIT;
List.Clear;
BufLen := SizeOf( AdapterInfo^ );
New( AdapterInfo );
Error := GetAdaptersInfo( AdapterInfo, @BufLen );
P := AdapterInfo;
if Error = NO_ERROR then
begin
while P <> nil do
with TIP_ADAPTER_INFO(P^) do
begin
SetLength( Descr, SizeOf( Description ) );
Descr := Trim( string( Description ) );
//
if IPAddressList.IpAddress[1] <> #0 then
LocalIP := IPAddressList.IpAddress
else
LocalIP := NULL_IP;
//
if GateWayList.IPAddress[1] <> #0 then
GateWayIP := GatewayList.IPAddress
else
GateWayIP := NULL_IP;
//
if DHCPServer.IPAddress[1] <> #0 then
DHCPIP := DHCPServer.IPAddress
else
DHCPIP := NULL_IP;

List.Add( Descr );
List.Add( Format(
'%8.8x|%6s|%16s|%2d|%16s|%16s|%16s',
[Index, AdaptTypes[aType],
MacAddr2Str( TMacAddress( Address ), AddressLength ),
DHCPEnabled, LocalIP, GatewayIP, DHCPIP] )
);
List.Add( ' ' );
P := Next; // TIP_ADAPTER_INFO(P^).Next points to next entry
end // with
end // while
else
List.Add( SysErrorMessage( Error ) );
Dispose( AdapterInfo );
end;




//-----------------------------------------------------------------------------
{ get round trip time and hopcount to indicated IP }
function Get_RTTAndHopCount( IPAddr: DWORD; MaxHops: Longint; var RTT: Longint;
var HopCount: Longint ): integer;
begin
if not GetRTTAndHopCount( IPAddr, @HopCount, MaxHops, @RTT ) then
begin
Result := GetLastError;
RTT := -1; // Destination unreachable, BAD_HOST_NAME,etc...
HopCount := -1;
end
else
Result := NO_ERROR;
end;

//-----------------------------------------------------------------------------
{ ARP-table lists relations between remote IP and remote MAC-address.
NOTE: these are cached entries ;when there is no more network traffic to a
node, entry is deleted after a few minutes.
}
procedure Get_ARPTable( List: TStrings );
var
IPNetRow : TMibIPNetRow;
TableSize : DWORD;
NumEntries : DWORD;
ErrorCode : DWORD;
i : integer;
pBuf : PChar;
begin
if not Assigned( List ) then EXIT;
List.Clear;
// first call: get table length
TableSize := 0;
ErrorCode := GetIPNetTable( PTMIBIpNetTable( pBuf ), @TableSize, false );
//
if ErrorCode = ERROR_NO_DATA then
begin
List.Add( ' ARP-cache empty.' );
EXIT;
end;
// get table
GetMem( pBuf, TableSize );
ErrorCode := GetIpNetTable( PTMIBIPNetTable( pBuf ), @TableSize, false );
if ErrorCode = NO_ERROR then
begin
NumEntries := PTMIBIPNetTable( pBuf )^.dwNumEntries;
if NumEntries > 0 then // paranoia striking, but you never know...
begin
inc( pBuf, SizeOf( DWORD ) ); // get past table size
for i := 1 to NumEntries do
begin
IPNetRow := PTMIBIPNetRow( PBuf )^;
with IPNetRow do
List.Add( Format( '%8x | %12s | %16s| %10s',
[dwIndex, MacAddr2Str( bPhysAddr, dwPhysAddrLen ),
IPAddr2Str( dwAddr ), ARPEntryType[dwType]
]));
inc( pBuf, SizeOf( IPNetRow ) );
end;
end
else
List.Add( ' ARP-cache empty.' );
end
else
List.Add( SysErrorMessage( ErrorCode ) );

// we _must_ restore pointer!
dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( IPNetRow ) );
FreeMem( pBuf );

end;


//------------------------------------------------------------------------------
procedure Get_TCPTable( List: TStrings );
var
TCPRow : TMIBTCPRow;
i,
NumEntries : integer;
TableSize : DWORD;
ErrorCode : DWORD;
DestIP : string;
pBuf : PChar;
begin
if not Assigned( List ) then EXIT;
List.Clear;
RecentIPs.Clear;
// first call : get size of table
TableSize := 0;
ErrorCode := GetTCPTable( PTMIBTCPTable( pBuf ), @TableSize, true );
if Errorcode <> ERROR_INSUFFICIENT_BUFFER then
EXIT;

// get required memory, call again
GetMem( pBuf, TableSize );
// get table
ErrorCode := GetTCPTable( PTMIBTCPTable( pBuf ), @TableSize, true );
if ErrorCode = NO_ERROR then
begin

NumEntries := PTMIBTCPTable( pBuf )^.dwNumEntries;
if NumEntries > 0 then
begin
inc( pBuf, SizeOf( DWORD ) ); // get past table size
for i := 1 to NumEntries do
begin
TCPRow := PTMIBTCPRow( pBuf )^; // get next record
with TCPRow do
begin
if dwRemoteAddr = 0 then
dwRemotePort := 0;
DestIP := IPAddr2Str( dwRemoteAddr );
List.Add(
Format( '%15s : %-7s|%15s : %-7s| %-16s',
[IpAddr2Str( dwLocalAddr ),
Port2Svc( Port2Wrd( dwLocalPort ) ),
DestIP,
Port2Svc( Port2Wrd( dwRemotePort ) ),
TCPConnState[dwState]
] ) );
//
if (not ( dwRemoteAddr = 0 ))
and ( RecentIps.IndexOf(DestIP) = -1 ) then
RecentIPs.Add( DestIP );
end;
inc( pBuf, SizeOf( TMIBTCPRow ) );
end;
end;
end
else
List.Add( SyserrorMessage( ErrorCode ) );
dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( TMibTCPRow ) );
FreeMem( pBuf );
end;


//------------------------------------------------------------------------------
procedure Get_OpenConnections( List: TList );
var
TCPRow : TMIBTCPRow;
i,
NumEntries : integer;
TableSize : DWORD;
ErrorCode : DWORD;
DestIP : string;
pBuf : PChar;
CStat : PTTcpConnStatus;
begin
if not Assigned( List ) then EXIT;
List.Clear;
// first call : get size of table
TableSize := 0;
ErrorCode := GetTCPTable( PTMIBTCPTable( pBuf ), @TableSize, true );
if Errorcode <> ERROR_INSUFFICIENT_BUFFER then
EXIT;

// get required size of memory, call again
GetMem( pBuf, TableSize );
// get table
ErrorCode := GetTCPTable( PTMIBTCPTable( pBuf ), @TableSize, true );
if ErrorCode = NO_ERROR then
begin
NumEntries := PTMIBTCPTable( pBuf )^.dwNumEntries;
if NumEntries > 0 then
begin
inc( pBuf, SizeOf( DWORD ) ); // get past table size
for i := 1 to NumEntries do
begin
TCPRow := PTMIBTCPRow( pBuf )^; // get next record
with TCPRow do
if dwState in [2,5] then // only listening, established
begin
New( CStat );
CStat^.LocalIP := IPAddr2Str( dwLocalAddr );
CStat^.LocalPort := Port2Svc( Port2Wrd( dwLocalPort ));
if dwRemoteAddr <> 0 then
begin
CStat^.RemoteIP := IPAddr2Str( dwRemoteAddr );
CStat^.RemotePort := Port2Svc( Port2Wrd( dwRemotePort ));
end
else begin
CStat^.RemoteIP := '...';
CStat^.RemotePort := '...';
end;
CStat^.Status := TCPConnState[dwState];
List.Add( CStat );
end;
inc( pBuf, SizeOf( TMIBTCPRow ) );
end;
end;
end;
dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( TMibTCPRow ) );
FreeMem( pBuf );
end;



//------------------------------------------------------------------------------
procedure Get_TCPStatistics( List: TStrings );
var
TCPStats : TMibTCPStats;
ErrorCode : DWORD;
begin
if not Assigned( List ) then EXIT;
List.Clear;
ErrorCode := GetTCPStatistics( @TCPStats );
if ErrorCode = NO_ERROR then
with TCPStats do
begin
List.Add( 'Retransmission algorithm :' + TCPToAlgo[dwRTOAlgorithm] );
List.Add( 'Minimum Time-Out :' + IntToStr( dwRTOMin ) + ' ms' );
List.Add( 'Maximum Time-Out :' + IntToStr( dwRTOMax ) + ' ms' );
List.Add( 'Maximum Pend.Connections :' + IntToStr( dwRTOAlgorithm ) );
List.Add( 'Active Opens :' + IntToStr( dwActiveOpens ) );
List.Add( 'Passive Opens :' + IntToStr( dwPassiveOpens ) );
List.Add( 'Failed Open Attempts :' + IntToStr( dwAttemptFails ) );
List.Add( 'Established conn. Reset :' + IntToStr( dwEstabResets ) );
List.Add( 'Current Established Conn.:' + IntToStr( dwCurrEstab ) );
List.Add( 'Segments Received :' + IntToStr( dwInSegs ) );
List.Add( 'Segments Sent :' + IntToStr( dwOutSegs ) );
List.Add( 'Segments Retransmitted :' + IntToStr( dwReTransSegs ) );
List.Add( 'Incoming Errors :' + IntToStr( dwInErrs ) );
List.Add( 'Outgoing Resets :' + IntToStr( dwOutRsts ) );
List.Add( 'Cumulative Connections :' + IntToStr( dwNumConns ) );
end
else
List.Add( SyserrorMessage( ErrorCode ) );

end;

//------------------------------------------------------------------------------
procedure Get_UDPTable( List: TStrings );
var
UDPRow : TMIBUDPRow;
i,
NumEntries : integer;
TableSize : DWORD;
ErrorCode : DWORD;
pBuf : PChar;
begin
if not Assigned( List ) then EXIT;
List.Clear;

// first call : get size of table
TableSize := 0;
ErrorCode := GetUDPTable( PTMIBUDPTable( pBuf ), @TableSize, true );
if Errorcode <> ERROR_INSUFFICIENT_BUFFER then
EXIT;

// get required size of memory, call again
GetMem( pBuf, TableSize );

// get table
ErrorCode := GetUDPTable( PTMIBUDPTable( pBuf ), @TableSize, true );
if ErrorCode = NO_ERROR then
begin
NumEntries := PTMIBUDPTable( pBuf )^.dwNumEntries;
if NumEntries > 0 then
begin
inc( pBuf, SizeOf( DWORD ) ); // get past table size
for i := 1 to NumEntries do
begin
UDPRow := PTMIBUDPRow( pBuf )^; // get next record
with UDPRow do
List.Add( Format( '%15s : %-6s',
[IpAddr2Str( dwLocalAddr ),
Port2Svc( Port2Wrd( dwLocalPort ) )
] ) );
inc( pBuf, SizeOf( TMIBUDPRow ) );
end;
end
else
List.Add( 'no entries.' );
end
else
List.Add( SyserrorMessage( ErrorCode ) );
dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( TMibUDPRow ) );
FreeMem( pBuf );
end;

//------------------------------------------------------------------------------
procedure Get_IPAddrTable( List: TStrings );
var
IPAddrRow : TMibIPAddrRow;
TableSize : DWORD;
ErrorCode : DWORD;
i : integer;
pBuf : PChar;
NumEntries : DWORD;
begin
if not Assigned( List ) then EXIT;
List.Clear;
TableSize := 0; ;
// first call: get table length
ErrorCode := GetIpAddrTable( PTMibIPAddrTable( pBuf ), @TableSize, true );
if Errorcode <> ERROR_INSUFFICIENT_BUFFER then
EXIT;

GetMem( pBuf, TableSize );
// get table
ErrorCode := GetIpAddrTable( PTMibIPAddrTable( pBuf ), @TableSize, true );
if ErrorCode = NO_ERROR then
begin
NumEntries := PTMibIPAddrTable( pBuf )^.dwNumEntries;
if NumEntries > 0 then
begin
inc( pBuf, SizeOf( DWORD ) );
for i := 1 to NumEntries do
begin
IPAddrRow := PTMIBIPAddrRow( pBuf )^;
with IPAddrRow do
List.Add( Format( '%8.8x|%15s|%15s|%15s|%8.8d',
[dwIndex,
IPAddr2Str( dwAddr ),
IPAddr2Str( dwMask ),
IPAddr2Str( dwBCastAddr ),
dwReasmSize
] ) );
inc( pBuf, SizeOf( TMIBIPAddrRow ) );
end;
end
else
List.Add( 'no entries.' );
end
else
List.Add( SysErrorMessage( ErrorCode ) );

// we must restore pointer!
dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( IPAddrRow ) );
FreeMem( pBuf );
end;


(*
//------------------------------------------------------------------------------
procedure Get_IPAddrTableMIB( var IPAddrTable:TMibIPAddrArray );
var
IPAddrRow : TMibIPAddrRow;
TableSize : DWORD;
ErrorCode : DWORD;
i : integer;
pBuf : PChar;
NumEntries : DWORD;
begin
TableSize := 0; ;
// first call: get table length
ErrorCode := GetIpAddrTable( PTMibIPAddrTable( pBuf ), @TableSize, true );
if Errorcode <> ERROR_INSUFFICIENT_BUFFER then
EXIT;

GetMem( pBuf, TableSize );
// get table
ErrorCode := GetIpAddrTable( PTMibIPAddrTable( pBuf ), @TableSize, true );
if ErrorCode = NO_ERROR then
begin
NumEntries := PTMibIPAddrTable( pBuf )^.dwNumEntries;
if NumEntries > 0 then
begin
SetLength( IPAddrTable, NumEntries);
inc( pBuf, SizeOf( DWORD ) );
for i := 1 to NumEntries do
begin
IPAddrTable[ i-1 ] := PTMIBIPAddrRow( pBuf )^;
inc( pBuf, SizeOf( TMIBIPAddrRow ) );
end;
end;
end;

// we must restore pointer!
dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( IPAddrRow ) );
FreeMem( pBuf );
end;
*)

//-----------------------------------------------------------------------------
{ gets entries in routing table; equivalent of &quot;route print&quot; }
procedure Get_IPForwardTable( List: TStrings );
var
IPForwRow : TMibIPForwardRow;
TableSize : DWORD;
ErrorCode : DWORD;
i : integer;
pBuf : PChar;
NumEntries : DWORD;
begin
if not Assigned( List ) then EXIT;
List.Clear;
TableSize := 0;

// first call: get table length
ErrorCode := GetIpForwardTable( PTMibIPForwardTable( pBuf ), @TableSize, true
);
if Errorcode <> ERROR_INSUFFICIENT_BUFFER then
EXIT;

// get table
GetMem( pBuf, TableSize );
ErrorCode := GetIpForwardTable( PTMibIPForwardTable( pBuf ), @TableSize, true
);
if ErrorCode = NO_ERROR then
begin
NumEntries := PTMibIPForwardTable( pBuf )^.dwNumEntries;
if NumEntries > 0 then
begin
inc( pBuf, SizeOf( DWORD ) );
for i := 1 to NumEntries do
begin
IPForwRow := PTMibIPForwardRow( pBuf )^;
with IPForwRow do
List.Add( Format(
'%15s|%15s|%15s|%8.8x|%7s| %5.5d| %7s| %2.2d',
[IPAddr2Str( dwForwardDest ),
IPAddr2Str( dwForwardMask ),
IPAddr2Str( dwForwardNextHop ),
dwForwardIFIndex,
IPForwTypes[dwForwardType],
dwForwardNextHopAS,
IPForwProtos[dwForwardProto],
dwForwardMetric1
] ) );
inc( pBuf, SizeOf( TMibIPForwardRow ) );
end;
end
else
List.Add( 'no entries.' );
end
else
List.Add( SysErrorMessage( ErrorCode ) );
dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( TMibIPForwardRow ) );
FreeMem( pBuf );
end;

//------------------------------------------------------------------------------
procedure Get_IPStatistics( List: TStrings );
var
IPStats : TMibIPStats;
ErrorCode : integer;
begin
if not Assigned( List ) then EXIT;
ErrorCode := GetIPStatistics( @IPStats );
if ErrorCode = NO_ERROR then
begin
List.Clear;
with IPStats do
begin
if dwForwarding = 1 then
List.add( 'Forwarding Enabled : ' + 'Yes' )
else
List.add( 'Forwarding Enabled : ' + 'No' );
List.add( 'Default TTL : ' + inttostr( dwDefaultTTL ) );
List.add( 'Datagrams Received : ' + inttostr( dwInReceives ) );
List.add( 'Header Errors (In) : ' + inttostr( dwInHdrErrors ) );
List.add( 'Address Errors (In) : ' + inttostr( dwInAddrErrors ) );
List.add( 'Unknown Protocols (In) : ' + inttostr( dwInUnknownProtos ) );
List.add( 'Datagrams Discarded : ' + inttostr( dwInDiscards ) );
List.add( 'Datagrams Delivered : ' + inttostr( dwInDelivers ) );
List.add( 'Requests Out : ' + inttostr( dwOutRequests ) );
List.add( 'Routings Discarded : ' + inttostr( dwRoutingDiscards ) );
List.add( 'No Routes (Out): ' + inttostr( dwOutNoRoutes ) );
List.add( 'Reassemble TimeOuts : ' + inttostr( dwReasmTimeOut ) );
List.add( 'Reassemble Requests : ' + inttostr( dwReasmReqds ) );
List.add( 'Succesfull Reassemblies : ' + inttostr( dwReasmOKs ) );
List.add( 'Failed Reassemblies : ' + inttostr( dwReasmFails ) );
List.add( 'Succesful Fragmentations: ' + inttostr( dwFragOKs ) );
List.add( 'Failed Fragmentations : ' + inttostr( dwFragFails ) );
List.add( 'Datagrams Fragmented : ' + inttostr( dwFRagCreates ) );
List.add( 'Number of Interfaces : ' + inttostr( dwNumIf ) );
List.add( 'Number of IP-addresses : ' + inttostr( dwNumAddr ) );
List.add( 'Routes in RoutingTable : ' + inttostr( dwNumRoutes ) );
end;
end
else
List.Add( SysErrorMessage( ErrorCode ) );
end;

//------------------------------------------------------------------------------
procedure Get_UdpStatistics( List: TStrings );
var
UdpStats : TMibUDPStats;
ErrorCode : integer;
begin
if not Assigned( List ) then EXIT;
ErrorCode := GetUDPStatistics( @UdpStats );
if ErrorCode = NO_ERROR then
begin
List.Clear;
with UDPStats do
begin
List.add( 'Datagrams (In) : ' + inttostr( dwInDatagrams ) );
List.add( 'Datagrams (Out) : ' + inttostr( dwOutDatagrams ) );
List.add( 'No Ports : ' + inttostr( dwNoPorts ) );
List.add( 'Errors (In) : ' + inttostr( dwInErrors ) );
List.add( 'UDP Listen Ports : ' + inttostr( dwNumAddrs ) );
end;
end
else
List.Add( SysErrorMessage( ErrorCode ) );
end;

//------------------------------------------------------------------------------
procedure Get_ICMPStats( ICMPIn, ICMPOut: TStrings );
var
ErrorCode : DWORD;
ICMPStats : PTMibICMPInfo;
begin
if ( ICMPIn = nil ) or ( ICMPOut = nil ) then EXIT;
ICMPIn.Clear;
ICMPOut.Clear;
New( ICMPStats );
ErrorCode := GetICMPStatistics( ICMPStats );
if ErrorCode = NO_ERROR then
begin
with ICMPStats.InStats do
begin
ICMPIn.Add( 'Messages received : ' + IntToStr( dwMsgs ) );
ICMPIn.Add( 'Errors : ' + IntToStr( dwErrors ) );
ICMPIn.Add( 'Dest. Unreachable : ' + IntToStr( dwDestUnreachs ) );
ICMPIn.Add( 'Time Exceeded : ' + IntToStr( dwTimeEcxcds ) );
ICMPIn.Add( 'Param. Problems : ' + IntToStr( dwParmProbs ) );
ICMPIn.Add( 'Source Quench : ' + IntToStr( dwSrcQuenchs ) );
ICMPIn.Add( 'Redirects : ' + IntToStr( dwRedirects ) );
ICMPIn.Add( 'Echo Requests : ' + IntToStr( dwEchos ) );
ICMPIn.Add( 'Echo Replies : ' + IntToStr( dwEchoReps ) );
ICMPIn.Add( 'Timestamp Requests : ' + IntToStr( dwTimeStamps ) );
ICMPIn.Add( 'Timestamp Replies : ' + IntToStr( dwTimeStampReps ) );

ICMPIn.Add( 'Addr. Masks Requests : ' + IntToStr( dwAddrMasks ) );
ICMPIn.Add( 'Addr. Mask Replies : ' + IntToStr( dwAddrReps ) );
end;
//
with ICMPStats^.OutStats do
begin
ICMPOut.Add( 'Messages sent : ' + IntToStr( dwMsgs ) );
ICMPOut.Add( 'Errors : ' + IntToStr( dwErrors ) );
ICMPOut.Add( 'Dest. Unreachable : ' + IntToStr( dwDestUnreachs ) );
ICMPOut.Add( 'Time Exceeded : ' + IntToStr( dwTimeEcxcds ) );
ICMPOut.Add( 'Param. Problems : ' + IntToStr( dwParmProbs ) );
ICMPOut.Add( 'Source Quench : ' + IntToStr( dwSrcQuenchs ) );
ICMPOut.Add( 'Redirects : ' + IntToStr( dwRedirects ) );
ICMPOut.Add( 'Echo Requests : ' + IntToStr( dwEchos ) );
ICMPOut.Add( 'Echo Replies : ' + IntToStr( dwEchoReps ) );
ICMPOut.Add( 'Timestamp Requests : ' + IntToStr( dwTimeStamps ) );
ICMPOut.Add( 'Timestamp Replies : ' + IntToStr( dwTimeStampReps ) );
ICMPOut.Add( 'Addr. Masks Requests : ' + IntToStr( dwAddrMasks ) );
ICMPOut.Add( 'Addr. Mask Replies : ' + IntToStr( dwAddrReps ) );
end;
end
else
IcmpIn.Add( SysErrorMessage( ErrorCode ) );
Dispose( ICMPStats );
end;

//------------------------------------------------------------------------------
procedure Get_RecentDestIPs( List: TStrings );
begin
if Assigned( List ) then
List.Assign( RecentIPs )
end;

initialization

RecentIPs := TStringList.Create;

finalization

RecentIPs.Free;

end.

{ List of Fixes &amp; Additions

v1.1
-----
Fix : wrong errorcode reported in GetNetworkParams()
Fix : RTTI MaxHops 20 > 128
Add : ICMP -statistics
Add : Well-Known port numbers
Add : RecentIP list
Add : Timer update

v1.2
----
Fix : Recent IP's correct update
ADD : ICMP-error codes translated

v1.3
----
chg : left out adapter &quot;admin status&quot; and &quot;oper. status&quot;
add : adapter bytes in/out


v1.4
----
Fix : GetadaptersInfo()
Last iteration nills pointer => memory leak on Dispose()!
(reported by David Sarasinni)

}
 
unit IpIfConst;

{$WEAKPACKAGEUNIT}

{$HPPEMIT ''}
{$HPPEMIT '#include &quot;ipifcons.h&quot;'}
{$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.
 
unit IpRtrMib;

{$WEAKPACKAGEUNIT }

{$HPPEMIT ''}
{$HPPEMIT '#include &quot;iprtrmib.h&quot;'}
{$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; //interface序号
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 &quot;discriminated&quot; //
// 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.
 
unit IPTypes;
{$WEAKPACKAGEUNIT}

{$HPPEMIT ''}
{$HPPEMIT '#include &quot;iptypes.h&quot;'}
{$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.
 
unit IpHlpApi;

{$WEAKPACKAGEUNIT }

{$HPPEMIT ''}
{$HPPEMIT '#include &quot;iphlpapi.h&quot;'}
{$HPPEMIT ''}

//{$I WINDEFINES.INC}

{.$DEFINE IPHLPAPI_LINKONREQUEST}
{$IFDEF IPHLPAPI_LINKONREQUEST}
{$DEFINE IPHLPAPI_DYNLINK}
{$ENDIF}
{.$DEFINE IPHLPAPI_DYNLINK}

interface

uses
Windows, IpExport, IpTypes,IpRtrMib;

//////////////////////////////////////////////////////////////////////////////
// //
// 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 &quot;best&quot; 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 &quot;best&quot; 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;

//function GetNetworkParams( FixedInfo: PFixedInfo; pOutPutLen: PULONG ): DWORD;
// external iphlpapilib;stdcall;

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.
 
linuxping 辛苦了。您的回答不明确啊!
 
1.
wstart:=ntohl(inet_addr(PAnsiChar(FStartIP))); //起始IP
wend:=ntohl(inet_addr(PAnsiChar(FEndIP)));//终止IP
wChoose:=ntohl(inet_addr(PAnsiChar(FChooseIP)));//用户选择的IP
if wChoose in [wstart..wend] then //设置IP
begin

end

2. 每个函数前面不是有说明吗? 你要用的API:

// //
// 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}
 
WINDOW 的标准VPN服务器,接入用程序的方法实现,用RAS API实现拨号,可以完成IP地址的设定,客户端路由的建立!
QQ:4274612
 
建立连接和拨号都完成了 不过具体不知道怎么设定IP地址,我自己设定IP连接后总是说服务器拒绝接受请求地址。请问楼上如何解决。是要在服务器上配置吗?
 
给分。 呵呵 ,不好意思 最近没来。
 
多人接受答案了。
 
后退
顶部