全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2353
推到 Plurk!
推到 Facebook!

不懂如下錯誤訊息是說什麼?

答題得分者是:dllee
ry_lee
高階會員


發表:368
回覆:251
積分:123
註冊:2002-03-19

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-11-17 17:27:34 IP:218.164.xxx.xxx 訂閱
1.底下程式碼是來大家討論時提出,有幾個錯誤訊息是說什麼(用紅色標示)?請了解的說明一下,謝謝
2.是否有更簡易方式以判斷是否已連線網路 ?

simple ping
added on: 10/09/2002 topic: Network Programming
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
winsock, StdCtrls;
type
IPINFO = record
Ttl :char;
Tos :char;
IPFlags :char;
OptSize :char;
Options :^char;
end;
type
ICMPECHO = record
Source :longint;
Status :longint;
RTTime :longint;
DataSize:Shortint;
Reserved:Shortint;
pData :^variant;
i_ipinfo:IPINFO;
end;
TIcmpCreateFile = function():integer; {$IFDEF WIN32} stdcall; {$ENDIF}
TIcmpCloseHandle = procedure(var handle:integer);{$IFDEF WIN32} stdcall; {$ENDIF}
TIcmpSendEcho = function(var handle:integer; endereco:DWORD; buffer:variant; tam:WORD; IP:IPINFO; ICMP:ICMPECHO; tamicmp:DWORD; tempo:DWORD):DWORD;{$IFDEF WIN32} stdcall; {$ENDIF}

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
wsadt : wsadata;
icmp :icmpecho;
HNDicmp : integer;
hndFile :integer;
Host :PHostEnt;
Destino :in_addr;
Endereco :^DWORD;
IP : ipinfo;
Retorno :integer;
dwRetorno :DWORD;
x :integer;
IcmpCreateFile : TIcmpCreateFile;
IcmpCloseHandle : TIcmpCloseHandle;
IcmpSendEcho : TIcmpSendEcho;
begin
if (edit1.Text = '') then begin
Application.MessageBox(Application.MessageBox('Erro pegando endere蔞s ICMP','Error', MB_OK);
FreeLibrary(HNDicmp);
end;
end;
Retorno := WSAStartup($0101,wsadt);
if (Retorno <> 0) then begin
Application.MessageBox('Host n緌 encontrado','Error', MB_OK);
WSACleanup();
FreeLibrary(HNDicmp);
exit;
end;
memo1.Lines.Add('Pinging ' Edit1.text);
Endereco := @Host.h_addr_list;
HNDFile := IcmpCreateFile();
for x:= 0 to 4 do begin
Ip.Ttl := char(255);
Ip.Tos := char(0);
Ip.IPFlags := char(0);
Ip.OptSize := char(0);
Ip.Options := nil;
dwRetorno := IcmpSendEcho(
HNDFile,
Endereco^,
null,
0,
Ip,
Icmp,
sizeof(Icmp),
DWORD(5000));
Destino.S_addr := icmp.source;
Memo1.Lines.Add('Pingou ' Edit1.text);
end;

IcmpCLoseHandle(HNDFile);
FreeLibrary(HNDicmp);
WSACleanup();
end;
end.
Jasonwong
版主


發表:49
回覆:931
積分:581
註冊:2006-10-27

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-11-17 18:10:07 IP:61.57.xxx.xxx 未訂閱
應該是沒有轉成 PChar
------
聰明的人,喜歡猜心;雖然每次都猜對了,卻失去了自己的心
傻氣的人,喜歡給心;雖然每次都被笑了,卻得到了別人的心
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-11-19 13:21:18 IP:220.134.xxx.xxx 訂閱
用 google 查一下,找到:
http://www.codenet.ru/progr/delphi/stat/ping.php

它有提供英文版:

[code delphi]
procedure TForm1.Button1Click(Sender: TObject);
var 
wsadt : wsadata; 
icmp :icmpecho; 
HNDicmp : integer; 
hndFile :integer; 
Host :PHostEnt; 
Destino :in_addr; 
Endereco :^DWORD; 
IP : ipinfo; 
Retorno :integer; 
dwRetorno :DWORD; 
x :integer; 

IcmpCreateFile : TIcmpCreateFile; 
IcmpCloseHandle : TIcmpCloseHandle; 
IcmpSendEcho : TIcmpSendEcho; 

begin 
if (edit1.Text = '') then begin 
Application.MessageBox('Enter a HostName ro a IP Adress', 
'Error', MB_OK); 
exit; 
end; 
HNDicmp := LoadLibrary('ICMP.DLL'); 
if (HNDicmp <> 0) then begin 
@IcmpCreateFile := GetProcAddress(HNDicmp,'IcmpCreateFile'); 
@IcmpCloseHandle := GetProcAddress(HNDicmp,'IcmpCloseHandle'); 
@IcmpSendEcho := GetProcAddress(HNDicmp,'IcmpSendEcho'); 
if (@IcmpCreateFile=nil) or (@IcmpCloseHandle=nil) or
   (@IcmpSendEcho=nil) then begin 
Application.MessageBox('Error getting ICMP Adress','Error', MB_OK); 
FreeLibrary(HNDicmp); 
end; 
end; 
Retorno := WSAStartup($0101,wsadt); 

if (Retorno <> 0) then begin 
Application.MessageBox('Can?t Load WinSockets','WSAStartup', MB_OK); 
WSACleanup(); 
FreeLibrary(HNDicmp); 
end; 

Destino.S_addr := inet_addr(Pchar(Edit1.text)); 
if (Destino.S_addr = 0) then begin 
Host := GetHostbyName(PChar(Edit1.text)); 
end 
else begin 
Host := GetHostbyAddr(@Destino,sizeof(in_addr), AF_INET); 
end; 

if (host = nil) then begin 
Application.MessageBox('Host not found','Error', MB_OK); 
WSACleanup(); 
FreeLibrary(HNDicmp); 
exit; 
end; 
memo1.Lines.Add('Pinging '   Edit1.text); 

Endereco := @Host.h_addr_list; 

HNDFile := IcmpCreateFile(); 
for x:= 0 to 4 do begin 
Ip.Ttl := char(255); 
Ip.Tos := char(0); 
Ip.IPFlags := char(0); 
Ip.OptSize := char(0); 
Ip.Options := nil; 

dwRetorno := IcmpSendEcho( 
HNDFile, 
Endereco^, 
null, 
0, 
Ip, 
Icmp, 
sizeof(Icmp), 
DWORD(5000)); 
Destino.S_addr := icmp.source; 
Memo1.Lines.Add('Ping '   Edit1.text); 
end; 

IcmpCLoseHandle(HNDFile); 
FreeLibrary(HNDicmp); 
WSACleanup(); 
end;
[/code]
這是一個 Ping 的程式,就 Ping 不到表示無法與對方連線,而那些錯誤訊息,如果有單步 Trace 一下,配合是否連上網路的測試(如拔下網路, 接上網路等),就可以明瞭那些訊息的意思。
或是,再去找其他 Ping 的程式範例也行。


VMASK - ViewMove Automation Software KernelVMIO-Server/SECS/GEMdllee's blogdllee's StatPlus
------
http://www.ViewMove.com
系統時間:2024-04-19 23:36:02
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!