Unit icmp

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Author: François PIETTE Description: This unit encapsulate the ICMP.DLL into an object of type TICMP. Using this object, you can easily ping any host on your network. Works only in 32 bits mode (no Delphi 1) under NT or 95. TICMP is perfect for a console mode program, but if you build a GUI program, you could use the TPing object wich is a true VCL encapsulating the TICMP object. Then you can use object inspector to change properties or event handler. This is much simpler to use for a GUI program. EMail: francois.piette@ping.be http://www.rtfm.be/fpiette francois.piette@rtfm.be Creation: January 6, 1997 Version: 1.02 WebSite: http://www.rtfm.be/fpiette/indexuk.htm Support: Use the mailing list twsocket@rtfm.be See website for details. Legal issues: Copyright (C) 1997 by François PIETTE This software is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented, you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Updates: Dec 13, 1997 V1.01 Added OnEchoRequest and OnEchoReply events and removed the corresponding OnDisplay event. This require to modify existing programs. Mar 15, 1998 V1.02 Deplaced address resolution just before use * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Classes

TICMP - The object wich encapsulate the ICMP.

Functions

Types

PIcmpEchoReply
PIPOptionInformation
TIcmpCloseHandle
TIcmpCreateFile
TICMPDisplay
TIcmpEchoReply
TICMPReply
TIcmpSendEcho
TIPAddr
TIPMask
TIPOptionInformation
TIPStatus

Constants

IcmpDLL
IcmpVersion
IP_ADDR_DELETED
IP_BAD_DESTINATION
IP_BAD_OPTION
IP_BAD_REQ
IP_BAD_ROUTE
IP_BUF_TOO_SMALL
IP_DEST_HOST_UNREACHABLE
IP_DEST_NET_UNREACHABLE
IP_DEST_PORT_UNREACHABLE
IP_DEST_PROT_UNREACHABLE
IP_FLAG_DF
IP_GENERAL_FAILURE
IP_HW_ERROR
IP_MTU_CHANGE
IP_NO_RESOURCES
IP_OPTION_TOO_BIG
IP_OPT_EOL
IP_OPT_LSRR
IP_OPT_NOP
IP_OPT_RR
IP_OPT_SECURITY
IP_OPT_SID
IP_OPT_SSRR
IP_OPT_TS
IP_PACKET_TOO_BIG
IP_PARAM_PROBLEM
IP_PENDING
IP_REQ_TIMED_OUT
IP_SOURCE_QUENCH
IP_SPEC_MTU_CHANGE
IP_STATUS_BASE
IP_SUCCESS
IP_TTL_EXPIRED_REASSEM
IP_TTL_EXPIRED_TRANSIT
MAX_IP_STATUS
MAX_OPT_SIZE

Variables


Functions


Types


PIcmpEchoReply = ^TIcmpEchoReply
Options data buffer
PIPOptionInformation = ^TIPOptionInformation
Status code returned from IP APIs.
TIcmpCloseHandle = function(IcmpHandle: THandle): Boolean
IcmpCloseHandle: Closes a handle opened by ICMPOpenFile. Arguments: IcmpHandle - The handle to close. Return Value: TRUE if the handle was closed successfully, otherwise FALSE. Extended error information is available by calling GetLastError().
TIcmpCreateFile  = function: THandle
IcmpCreateFile: Opens a handle on which ICMP Echo Requests can be issued. Arguments: None. Return Value: An open file handle or INVALID_HANDLE_VALUE. Extended error information is available by calling GetLastError().
TICMPDisplay = procedure(Sender: TObject; Msg : String) of object
Event handler type declaration for TICMP.OnDisplay event.
TIcmpEchoReply = record
Address : TIPAddr;
Status : DWord;
RTT : DWord;
DataSize : Word;
Reserved : Word;
Data : Pointer;
Options : TIPOptionInformation;
end;

TICMPReply   = procedure(Sender: TObject; Error : Integer) of object

TIcmpSendEcho    = function(IcmpHandle:          THandle;
                              DestinationAddress:  TIPAddr;
                              RequestData:         Pointer;
                              RequestSize:         Word;
                              RequestOptions:      PIPOptionInformation;
                              ReplyBuffer:         Pointer;
                              ReplySize:           DWord;
                              Timeout:             DWord
                             ): DWord
IcmpSendEcho: Sends an ICMP Echo request and returns one or more replies. The call returns when the timeout has expired or the reply buffer is filled. Arguments: IcmpHandle - An open handle returned by ICMPCreateFile. DestinationAddress - The destination of the echo request. RequestData - A buffer containing the data to send in the request. RequestSize - The number of bytes in the request data buffer. RequestOptions - Pointer to the IP header options for the request. May be NULL. ReplyBuffer - A buffer to hold any replies to the request. On return, the buffer will contain an array of ICMP_ECHO_REPLY structures followed by options and data. The buffer should be large enough to hold at least one ICMP_ECHO_REPLY structure and 8 bytes of data - this is the size of an ICMP error message. ReplySize - The size in bytes of the reply buffer. Timeout - The time in milliseconds to wait for replies. Return Value: Returns the number of replies received and stored in ReplyBuffer. If the return value is zero, extended error information is available via GetLastError().
TIPAddr   = DWORD
IP types
TIPMask   = DWORD
An IP address.
TIPOptionInformation = record
TTL : Byte;
TOS : Byte;
Flags : Byte;
OptionsSize : Byte;
OptionsData : PChar;
end;

TIPStatus = DWORD
An IP subnet mask.

Constants

IcmpDLL = 'icmp.dll'

IcmpVersion = 102

IP_ADDR_DELETED = (IP_STATUS_BASE + 19)

status codes passed up on status indications.

IP_BAD_DESTINATION = (IP_STATUS_BASE + 18)

IP_BAD_OPTION = (IP_STATUS_BASE + 7)

IP_BAD_REQ = (IP_STATUS_BASE + 11)

IP_BAD_ROUTE = (IP_STATUS_BASE + 12)

IP_BUF_TOO_SMALL = (IP_STATUS_BASE + 1)

IP_DEST_HOST_UNREACHABLE = (IP_STATUS_BASE + 3)

IP_DEST_NET_UNREACHABLE = (IP_STATUS_BASE + 2)

IP_DEST_PORT_UNREACHABLE = (IP_STATUS_BASE + 5)

IP_DEST_PROT_UNREACHABLE = (IP_STATUS_BASE + 4)

IP_FLAG_DF = $02

IP header flags

IP_GENERAL_FAILURE = (IP_STATUS_BASE + 50)

IP_HW_ERROR = (IP_STATUS_BASE + 8)

IP_MTU_CHANGE = (IP_STATUS_BASE + 21)

IP_NO_RESOURCES = (IP_STATUS_BASE + 6)

IP_OPTION_TOO_BIG = (IP_STATUS_BASE + 17)

IP_OPT_EOL = $00

Don't fragment this packet. IP Option Types

IP_OPT_LSRR = $83

Security option.

IP_OPT_NOP = $01

End of list option

IP_OPT_RR = $07

Strict source route.

IP_OPT_SECURITY = $82

No operation

IP_OPT_SID = $88

Timestamp.

IP_OPT_SSRR = $89

Loose source route.

IP_OPT_TS = $44

Record route.

IP_PACKET_TOO_BIG = (IP_STATUS_BASE + 9)

IP_PARAM_PROBLEM = (IP_STATUS_BASE + 15)

IP_PENDING = (IP_STATUS_BASE + 255)

IP_REQ_TIMED_OUT = (IP_STATUS_BASE + 10)

IP_SOURCE_QUENCH = (IP_STATUS_BASE + 16)

IP_SPEC_MTU_CHANGE = (IP_STATUS_BASE + 20)

IP_STATUS_BASE = 11000

IP_SUCCESS = 0

IP status codes returned to transports and user IOCTLs.

IP_TTL_EXPIRED_REASSEM = (IP_STATUS_BASE + 14)

IP_TTL_EXPIRED_TRANSIT = (IP_STATUS_BASE + 13)

MAX_IP_STATUS = IP_GENERAL_FAILURE

MAX_OPT_SIZE = $40

Stream ID (obsolete

Variables