Autor Beitrag
|TF|Alucard
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 43

XP

BeitragVerfasst: Mi 14.04.04 09:02 
Hi,
also ich hab einen Quellcode, um die IP-Adresse herauszufinden. Aber warum läuft dieser Code in dem einen Programm einwandfrei und in dem anderen nicht?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
function GetIPAddress: string;
var phoste  : PHostEnt;       {hier kommt der Fehler bei einem Programm}
    Buffer  : array [0..100] of char;
    WSAData : TWSADATA;

begin
  result := '';
  if WSAStartup($0101, WSAData) <> 0 then exit;
  GetHostName(Buffer, SizeOf(Buffer));
  phoste :=GetHostByName(buffer);
  if phoste = nil then
    result := '127.0.0.1'
  else
    result := StrPas(inet_ntoa(PInAddr(phoste^.h_addr_list^)^));
  WSACleanup;
end;

Weiß jemand eine Lösung? :(

mfG |TF|Alucard

Moderiert von user profile iconDeCodeGuru: Code- durch Delphi-Tags ersetzt

_________________
Ich weiß nicht mit welchen Waffen der 3. Weltkrieg geführt wird, aber im 4. werden es Stöcke und Steine sein. [Albert Einstein]
DeCodeGuru
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1333
Erhaltene Danke: 1

Arch Linux
Eclipse
BeitragVerfasst: Mi 14.04.04 09:13 
Haste alle nötigen Units eingebunden? :?

Bzw. sag mal, was für eine Fehlermeldung kommt!

_________________
Viele Grüße
Jakob
|TF|Alucard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 43

XP

BeitragVerfasst: Mi 14.04.04 09:23 
Hier die Fehlermeldung:
Zitat:
[Fehler] Unit1.pas(84): Undefinierter Bezeichner: 'PHostEnt'


|TF|Alucard

_________________
Ich weiß nicht mit welchen Waffen der 3. Weltkrieg geführt wird, aber im 4. werden es Stöcke und Steine sein. [Albert Einstein]
ixtreme
Gast
Erhaltene Danke: 1



BeitragVerfasst: Mi 14.04.04 09:37 
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
uses
  WinSock;

...

function GetIP: string;
type PPInAddr = ^PInAddr;
var
  wsaData: TWSAData;
  HostInfo: PHostEnt;
  HostName: array[0..255] of Char;
  Addr: PPInAddr;
begin
  Result := '';
  if WSAStartup($0102, wsaData) <> 0 then exit;
  try
    if gethostname(HostName, SizeOf(HostName)) <> 0 then exit;
    HostInfo := gethostbyname(HostName);
    if HostInfo = nil then Exit;
    Addr := Pointer(HostInfo^.h_addr_list);
    if (Addr = nil) or (Addr^ = nil) then exit;
    Result := StrPas(inet_ntoa(Addr^^));
    inc(Addr);
    while Addr^ <> nil do  begin
      Result := Result + ^M^J+ StrPas(inet_ntoa(Addr^^));
      inc(Addr);
    end;
  finally
    WSACleanup;
  end;
end;




procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit1.Text := GetIP;
end;


gruß

ixtreme.de
|TF|Alucard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 43

XP

BeitragVerfasst: Mi 14.04.04 09:48 
:D Vielen Dank! :D
Jetzt läuft es! Thx


mfG |TF|Alucard

_________________
Ich weiß nicht mit welchen Waffen der 3. Weltkrieg geführt wird, aber im 4. werden es Stöcke und Steine sein. [Albert Einstein]