+ adds ipv6 resolve functions (thanks to Montaro)

* cleans up some uglies

git-svn-id: trunk@5549 -
This commit is contained in:
Almindor 2006-12-06 22:25:03 +00:00
parent 262df1cbf7
commit 501f66e0ca

View File

@ -66,6 +66,14 @@ Type
PHostEntry = ^THostEntry; PHostEntry = ^THostEntry;
THostEntryArray = Array of THostEntry; THostEntryArray = Array of THostEntry;
THostEntry6 = record
Name : String;
Addr : THostAddr6;
Aliases : String;
end;
PHostEntry6 = ^THostEntry6;
THostEntry6Array = Array of THostEntry6;
TNetworkEntry = Record TNetworkEntry = Record
Name : String; Name : String;
Addr : TNetAddr; Addr : TNetAddr;
@ -109,6 +117,9 @@ function IN6_IS_ADDR_V4MAPPED(HostAddr: THostAddr6): boolean;
Function ResolveHostByName(HostName : String; Var H : THostEntry) : Boolean; Function ResolveHostByName(HostName : String; Var H : THostEntry) : Boolean;
Function ResolveHostByAddr(HostAddr : THostAddr; Var H : THostEntry) : Boolean; Function ResolveHostByAddr(HostAddr : THostAddr; Var H : THostEntry) : Boolean;
Function ResolveHostByName6(Hostname : String; Var H : THostEntry6) : Boolean;
Function ResolveHostByAddr6(HostAddr : THostAddr6; Var H : THostEntry6) : Boolean;
Function GetHostByName(HostName: String; Var H : THostEntry) : boolean; Function GetHostByName(HostName: String; Var H : THostEntry) : boolean;
Function GetHostByAddr(Addr: THostAddr; Var H : THostEntry) : boolean; Function GetHostByAddr(Addr: THostAddr; Var H : THostEntry) : boolean;
@ -248,7 +259,7 @@ Function GetAddr(Var L : String; Var Addr : THostAddr) : Boolean;
Var Var
S : String; S : String;
i,p,a : Integer; // i,p,a : Integer;
begin begin
Result:=True; Result:=True;
@ -265,17 +276,20 @@ Var
H : String; H : String;
begin begin
Result := False;
Repeat Repeat
H:=NextWord(L); H:=NextWord(L);
If (H<>'') then If (H<>'') then begin
if (Entry.Name='') then if (Entry.Name='') then
Entry.Name:=H Entry.Name:=H
else else
begin begin
If (Entry.Aliases<>'') then If (Entry.Aliases<>'') then
Entry.Aliases:=Entry.Aliases+','; Entry.Aliases:=Entry.Aliases+',';
Entry.Aliases:=Entry.Aliases+H; Entry.Aliases:=Entry.Aliases+H;
end; end;
Result := True;
end;
until (H=''); until (H='');
end; end;
@ -321,7 +335,7 @@ end;
Var Var
HostsList : PHostListEntry = Nil; HostsList : PHostListEntry = Nil;
HostsFileAge : Longint; HostsFileAge : Longint;
HostsFileName : String; // HostsFileName : String;
Function FreeHostsList(var List : PHostListEntry) : Integer; Function FreeHostsList(var List : PHostListEntry) : Integer;
@ -391,7 +405,7 @@ end;
Function FindHostEntryInHostsFile(N: String; Addr: THostAddr; Var H : THostEntry) : boolean; Function FindHostEntryInHostsFile(N: String; Addr: THostAddr; Var H : THostEntry) : boolean;
Var Var
F : Text; // F : Text;
HE : THostEntry; HE : THostEntry;
P : PHostListEntry; P : PHostListEntry;
@ -429,7 +443,7 @@ Function GetDNSServers(Fn : String) : Integer;
Var Var
R : Text; R : Text;
L : String; L : String;
I : Integer; // I : Integer;
H : THostAddr; H : THostAddr;
E : THostEntry; E : THostEntry;
@ -1004,7 +1018,6 @@ begin
(HostAddr.u6_addr16[5] = $FFFF); (HostAddr.u6_addr16[5] = $FFFF);
end; end;
Function ResolveHostByName(HostName : String; Var H : THostEntry) : Boolean; Function ResolveHostByName(HostName : String; Var H : THostEntry) : Boolean;
Var Var
@ -1023,6 +1036,25 @@ begin
end; end;
end; end;
Function ResolveHostByName6(HostName : String; Var H : THostEntry6) : Boolean;
Var
Address : Array[1..MaxResolveAddr] of THostAddr6;
L : Integer;
begin
L:=ResolveName6(HostName,Address);
Result:=(L>0);
If Result then
begin
// We could add a reverse call here to get the real name and aliases.
H.Name:=HostName;
H.Addr:=Address[1];
H.aliases:='';
end;
end;
Function ResolveHostByAddr(HostAddr : THostAddr; Var H : THostEntry) : Boolean; Function ResolveHostByAddr(HostAddr : THostAddr; Var H : THostEntry) : Boolean;
Var Var
@ -1046,6 +1078,31 @@ begin
end; end;
end; end;
Function ResolveHostByAddr6(HostAddr : THostAddr6; Var H : THostEntry6) : Boolean;
Var
Names : Array[1..MaxResolveAddr] of String;
I,L : Integer;
begin
L:=ResolveAddress6(HostAddr,Names);
Result:=(L>0);
If Result then
begin
H.Name:=Names[1];
H.Addr:=HostAddr;
H.Aliases:='';
If (L>1) then
For I:=2 to L do
If (I=2) then
H.Aliases:=Names[i]
else
H.Aliases:=H.Aliases+','+Names[i];
end;
end;
//const NoAddress : in_addr = (s_addr: 0); //const NoAddress : in_addr = (s_addr: 0);
@ -1158,7 +1215,7 @@ function StrTonetpartial( IP : AnsiString) : in_addr ;
Var Var
Dummy : AnsiString; Dummy : AnsiString;
I,j,k : Longint; I,j,k : Longint;
Temp : in_addr; // Temp : in_addr;
begin begin
strtonetpartial.s_addr:=0; //:=NoAddress; strtonetpartial.s_addr:=0; //:=NoAddress;
@ -1352,8 +1409,8 @@ end;
Procedure InitResolver; Procedure InitResolver;
Var //Var
I : Integer; // I : Integer;
begin begin
TimeOutS :=5; TimeOutS :=5;