X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/85ef2ce64f0cc31a063fccea69fdcc7281d51548..03b75b4c964d8b3ac97d4007f0e033549b01c92f:/dnsasync.pas?ds=sidebyside diff --git a/dnsasync.pas b/dnsasync.pas old mode 100755 new mode 100644 index 8c3ce3a..01bc2ff --- a/dnsasync.pas +++ b/dnsasync.pas @@ -11,7 +11,7 @@ unit dnsasync; interface uses - {$ifdef win32} + {$ifdef mswindows} dnswin, {$endif} lsocket,lcore, @@ -39,7 +39,7 @@ type dnsserverids : array[0..numsock-1] of integer; startts:double; - {$ifdef win32} + {$ifdef mswindows} dwas : tdnswinasync; {$endif} @@ -49,7 +49,7 @@ type procedure asyncprocess(socketno:integer); procedure receivehandler(sender:tobject;error:word); function sendquery(socketno:integer;const packet:tdnspacket;len:integer):boolean; - {$ifdef win32} + {$ifdef mswindows} procedure winrequestdone(sender:tobject;error:word); {$endif} @@ -60,18 +60,18 @@ type //for this dnsasync object. This is not a reccomended mode of operation //because it limits the app to one dns server but is kept for compatibility //and special uses. - addr,port:string; + addr,port:ansistring; overrideaf : integer; procedure cancel;//cancel an outstanding dns request - function dnsresult:string; //get result of dnslookup as a string + function dnsresult:ansistring; //get result of dnslookup as a string procedure dnsresultbin(var binip:tbinip); //get result of dnslookup as a tbinip property dnsresultlist : tbiniplist read fresultlist; - procedure forwardlookup(const name:string); //start forward lookup, + procedure forwardlookup(const name:ansistring); //start forward lookup, //preffering ipv4 procedure reverselookup(const binip:tbinip); //start reverse lookup - procedure customlookup(const name:string;querytype:integer); //start custom type lookup + procedure customlookup(const name:ansistring;querytype:integer); //start custom type lookup constructor create(aowner:tcomponent); override; destructor destroy; override; @@ -100,13 +100,23 @@ var socketno : integer; begin for socketno := 0 to numsock -1 do begin - if dnsserverids[socketno] >= 0 then begin - reportlag(dnsserverids[socketno],-1); - dnsserverids[socketno] := -1; + if assigned(sockets[socketno]) then begin + if dnsserverids[socketno] >= 0 then begin + reportlag(dnsserverids[socketno],-1); + dnsserverids[socketno] := -1; + end; + sockets[socketno].release; + setstate_request_init('',states[socketno]); end; - sockets[socketno].release; - setstate_request_init('',states[socketno]); end; + + {$ifdef mswindows} + if assigned(dwas) then begin + dwas.release; + dwas := nil; + end; + {$endif} + inherited destroy; end; @@ -116,7 +126,7 @@ var Src : TInetSockAddrV; SrcLen : Integer; fromip:tbinip; - fromport:string; + fromport:ansistring; begin socketno := tlsocket(sender).tag; //writeln('got a reply on socket number ',socketno); @@ -151,7 +161,7 @@ end; function tdnsasync.sendquery(socketno:integer;const packet:tdnspacket;len:integer):boolean; var - destination : string; + destination : tbinip; inaddr : tinetsockaddrv; trytolisten:integer; begin @@ -183,13 +193,13 @@ begin end; if addr <> '' then begin dnsserverids[socketno] := -1; - destination := addr + destination := ipstrtobinf(addr); end else begin - destination := getcurrentsystemnameserver(dnsserverids[socketno]); + destination := getcurrentsystemnameserverbin(dnsserverids[socketno]); end; - destinations[socketno] := ipstrtobinf(destination); + destinations[socketno] := destination; - {$ifdef ipv6}{$ifdef win32} + {$ifdef ipv6}{$ifdef mswindows} if destinations[socketno].family = AF_INET6 then if (requestaf = useaf_default) then requestaf := useaf_preferv6; {$endif}{$endif} @@ -253,11 +263,9 @@ begin exit; end; - if (overridednsserver <> '') and (addr = '') then addr := overridednsserver; - if overrideaf = useaf_default then begin {$ifdef ipv6} - {$ifdef win32}if not (usewindns and (addr = '')) then{$endif} + {$ifdef mswindows}if not (usewindns and (addr = '')) then{$endif} initpreferredmode; {$endif} requestaf := useaf; @@ -265,7 +273,7 @@ begin requestaf := overrideaf; end; - {$ifdef win32} + {$ifdef mswindows} if usewindns and (addr = '') then begin dwas := tdnswinasync.create; dwas.onrequestdone := winrequestdone; @@ -289,16 +297,15 @@ begin inc(numsockused); end; {$endif} + for i := 0 to numsockused-1 do begin asyncprocess(i); end; - end; procedure tdnsasync.reverselookup; begin - if (overridednsserver <> '') and (addr = '') then addr := overridednsserver; - {$ifdef win32} + {$ifdef mswindows} if usewindns and (addr = '') then begin dwas := tdnswinasync.create; dwas.onrequestdone := winrequestdone; @@ -314,7 +321,6 @@ end; procedure tdnsasync.customlookup; begin - if (overridednsserver <> '') and (addr = '') then addr := overridednsserver; setstate_custom(name,querytype,states[0]); numsockused := 1; asyncprocess(0); @@ -336,7 +342,7 @@ procedure tdnsasync.cancel; var socketno : integer; begin - {$ifdef win32} + {$ifdef mswindows} if assigned(dwas) then begin dwas.release; dwas := nil; @@ -359,7 +365,7 @@ begin onrequestdone(self,0); end; -{$ifdef win32} +{$ifdef mswindows} procedure tdnsasync.winrequestdone(sender:tobject;error:word); begin