[BlueLeaf1336]> PROBLEMS> PingShooter>
| history | TOP |
2004/01/21:作成(icmp_dll.pasのコメントの超訳中...)
| icmp_dll.pas | TOP |
2004/01/21
How to Ping a machine using the ICMP.DLL APIをパクリます。ついでに必要そうな箇所を日本語に訳します。
//---------------------------------------------------------------------
// icmp_dll.pas part of Ping Demo
//-----------------------------------------------------------------
// DISCLAIMER:
// 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.
//-----------------------------------------------------------------
// DESCRIPTION:
// This is a basic representation of what is contained in
// the Win32 API file ICMP.DLL. This file is based on a
// USENET post by Mike Cariotoglou (full information follows).
//
// For my purposes, I extended Ticmp_echo_reply and called this
// extension TsmICMP_Echo_Reply. The reason for this is to allow
// a simple way of providing a reply buffer. While there are
// certainly more robust ways of accomplishing this, this does get
// the job done.
//---------------------------------------------------------------------
// REFERENCES:
// USENET Post By: Mike Cariotoglou (mike@REMOVETHIS.singular.gr)
// Subject: "Re: PING and DELPHI"
// Newsgroup: borland.public.delphi.internet
// Date: 1999/05/18 (May 18, 1999)
//---------------------------------------------------------------------
unit icmp_dll;
interface
uses windows;
Const
//
// IP API から戻される IP_STATUS コード
//
IP_STATUS_BASE = 11000;
IP_SUCCESS = 0;
IP_BUF_TOO_SMALL = (IP_STATUS_BASE + 1);
IP_DEST_NET_UNREACHABLE = (IP_STATUS_BASE + 2);
IP_DEST_HOST_UNREACHABLE = (IP_STATUS_BASE + 3);
IP_DEST_PROT_UNREACHABLE = (IP_STATUS_BASE + 4);
IP_DEST_PORT_UNREACHABLE = (IP_STATUS_BASE + 5);
IP_NO_RESOURCES = (IP_STATUS_BASE + 6);
IP_BAD_OPTION = (IP_STATUS_BASE + 7);
IP_HW_ERROR = (IP_STATUS_BASE + 8);
IP_PACKET_TOO_BIG = (IP_STATUS_BASE + 9);
IP_REQ_TIMED_OUT = (IP_STATUS_BASE + 10);
IP_BAD_REQ = (IP_STATUS_BASE + 11);
IP_BAD_ROUTE = (IP_STATUS_BASE + 12);
IP_TTL_EXPIRED_TRANSIT = (IP_STATUS_BASE + 13);
IP_TTL_EXPIRED_REASSEM = (IP_STATUS_BASE + 14);
IP_PARAM_PROBLEM = (IP_STATUS_BASE + 15);
IP_SOURCE_QUENCH = (IP_STATUS_BASE + 16);
IP_OPTION_TOO_BIG = (IP_STATUS_BASE + 17);
IP_BAD_DESTINATION = (IP_STATUS_BASE + 18);
//
// The next group are status codes passed up on status indications to
// transport layer protocols.
//
IP_ADDR_DELETED = (IP_STATUS_BASE + 19);
IP_SPEC_MTU_CHANGE = (IP_STATUS_BASE + 20);
IP_MTU_CHANGE = (IP_STATUS_BASE + 21);
IP_UNLOAD = (IP_STATUS_BASE + 22);
IP_GENERAL_FAILURE = (IP_STATUS_BASE + 50);
MAX_IP_STATUS = IP_GENERAL_FAILURE;
IP_PENDING = (IP_STATUS_BASE + 255);
//
// Values used in the IP header Flags field.
//
IP_FLAG_DF = $2; // このパケットを fragment しちゃ駄目
//
// Supported IP Option Types.
//
// ip_option_information 構造体の OptionsData フィールドで使用されるオプションの定義
// それぞれの完全な意味については RFC 791 を参照
//
IP_OPT_EOL = 0; // End of list option
IP_OPT_NOP = 1; // No operation
IP_OPT_SECURITY = $82; // Security option
IP_OPT_LSRR = $83; // Loose source route
IP_OPT_SSRR = $89; // Strict source route
IP_OPT_RR = $7; // Record route
IP_OPT_TS = $44; // Timestamp
IP_OPT_SID = $88; // Stream ID (廃止)
MAX_OPT_SIZE = 40; // IP オプションの最大バイト長
Type
TIPAddr=integer; // IPアドレス
TIPMask=integer; // サブネットマスク
TIP_STATUS=Integer; // IP API の戻り値の Status code
//
// ip_option_information構造体はIPパケットのヘッダに含まれるオプションを記述する。
// TTL, TOS, Flagsの値はヘッダの特別なフィールドを格納する。OptionsDataは標準の
// IPヘッダに続くオプション領域に格納される。
// 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.
//
POption_Information=^TOption_Information;
TOption_Information=record
Ttl:byte; // Time To Live
Tos:byte; // Type Of Service
Flags:byte; // IPヘッダフラグ
OptionsSize:byte; // オプションデータのバイトサイズ
OptionsData:pointer; // オプションデータのポインタ
end;
// The icmp_echo_reply structure describes the data returned in response
// to an echo request.
//
Picmp_echo_reply=^Ticmp_echo_reply;
Ticmp_echo_reply=record
Address:TipAddr; // 応答アドレス
Status:integer; // 応答IP_STATUS
RoundTripTime:integer; // RTT(ミリ秒)
DataSize:word; // 応答データバイトサイズ
Reserved:word; // システムが予約
Data:pointer; // 応答データへのポインタ
Options:Toption_Information; // 応答オプション
end;
TsmICMP_Echo_Reply=record
Address:TipAddr; // 応答アドレス
Status:integer; // 応答IP_STATUS
RoundTripTime:integer; // RTT(ミリ秒)
DataSize:word; // 応答データバイトサイズ
Reserved:word; // システムが予約
DataPtr:pointer; // 応答データへのポインタ
Options:Toption_Information; // 応答オプション
Data: array[0..255] of Char;
end;
//++
//
// 関数名:
// IcmpCreateFile
//
// 説明:
// ICMP Echo 要求を発行できるハンドルを開く
//
// 引数:
// なし
//
// 戻り値:
// ハンドルかINVALID_HANDLE_VALUEか。エラー情報はGetLastError()で。
//--
function IcmpCreateFile:Thandle; StdCall;
//
// 関数名:
// IcmpCloseHandle
// 説明:
// ICMPOpenFileで開いたハンドルを閉じる
//
// 引数:
// IcmpHandle - 閉じたいハンドル
//
// 戻り値:
// 成功したらTRUE失敗ならFALSE。エラー情報はGetLastError()で。
//--
function IcmpCloseHandle(H:Thandle):Bool; StdCall;
//
// 関数名:
// IcmpSendEcho
//
// 説明:
// ICMP Echo 要求を送り何らかの応答を戻す。タイムアウトが発生するか
// 応答バッファが埋められたら呼び出し元に処理を戻す
//
// 引数:
// IcmpHandle - ICMPCreateFileの戻り値のハンドル
// DestinationAddress - echo要求の送り先
// RequestData - 送信要求データバッファ
// RequestSize - 要求データバッファのバイト数
// RequestOptions - 要求IPヘッダオプションのポインタ(NULLかも)
// ReplyBuffer - 要求への何らかの応答を保持するバッファ
// On return, the buffer will contain an array of
// ICMP_ECHO_REPLY structures followed by the
// options and data for the replies. The buffer
// should be large enough to hold at least one
// ICMP_ECHO_REPLY structure plus
// MAX(RequestSize, 8) bytes of data since an ICMP
// error message contains 8 bytes of data.
// ReplySize - 応答バッファのバイトサイズ
// Timeout - 応答を待つ時間(ミリ秒)
//
// 戻り値:
// ReplyBufferに含まれるICMP_ECHO_REPLY構造体の数を戻す。
// それぞれの応答ステータスは構造体中に含まれる。zeroが戻された場合は
// GetLastError()で。
//--
Function IcmpSendEcho(IcmpHandle:Thandle;
DestinationAddress:TipAddr;
RequestData:pointer;
RequestSize:word;
RequestOptions:POption_Information;
ReplyBuffer:pointer;
ReplySize:integer;
Timeout:integer):Integer; stdcall;
Implementation
function IcmpCreateFile; external 'Icmp.Dll';
function IcmpCloseHandle; external 'Icmp.Dll';
Function IcmpSendEcho; external 'Icmp.Dll';
end.
| sample | TOP |
(まだです...)
| EOF | TOP |