X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/85ef2ce64f0cc31a063fccea69fdcc7281d51548..12873c59bfaeb05331a96c3611843aceedc899e0:/dnssync.pas diff --git a/dnssync.pas b/dnssync.pas old mode 100755 new mode 100644 index a7ba714..1a506d5 --- a/dnssync.pas +++ b/dnssync.pas @@ -26,24 +26,25 @@ interface fd_utils, {$endif} lcorernd, - sysutils; + sysutils, + ltimevalstuff; //convert a name to an IP //will return v4 or v6 depending on what seems favorable, or manual preference setting //on error the binip will have a family of 0 (other fiels are also currently //zeroed out but may be used for further error information in future) //timeout is in miliseconds, it is ignored when using windows dns -function forwardlookup(name:string;timeout:integer):tbinip; +function forwardlookup(name:ansistring;timeout:integer):tbinip; //convert a name to a list of all IP's returned //this returns both v4 and v6 IP's, or possibly only v4 or v6, depending on settings //on error, returns an empty list -function forwardlookuplist(name:string;timeout:integer):tbiniplist; +function forwardlookuplist(name:ansistring;timeout:integer):tbiniplist; //convert an IP to a name, on error a null string will be returned, other //details as above -function reverselookup(ip:tbinip;timeout:integer):string; +function reverselookup(ip:tbinip;timeout:integer):ansistring; @@ -73,16 +74,15 @@ implementation {$endif} {$i unixstuff.inc} -{$i ltimevalstuff.inc} + +{$ifdef syncdnscore} var numsockused:integer; fd:array[0..numsock-1] of integer; state:array[0..numsock-1] of tdnsstate; toaddr:array[0..numsock-1] of tbinip; -{$ifdef syncdnscore} - {$ifdef win32} const winsocket = 'wsock32.dll'; @@ -109,23 +109,22 @@ end; function sendquery(socknum:integer;const packet:tdnspacket;len:integer):boolean; var - a:integer; - addr : string; - port : string; + ip : tbinip; + port : ansistring; inaddr : TInetSockAddrV; begin { writeln('sendquery ',decodename(state.packet,state.packetlen,12,0,a),' ',state.requesttype);} result := false; if len = 0 then exit; {no packet} - if overridednsserver <> '' then addr := overridednsserver else addr := getcurrentsystemnameserver(id); + ip := getcurrentsystemnameserverbin(id); {$ifdef ipv6}{$ifdef win32} if toaddr[socknum].family = AF_INET6 then if (useaf = 0) then useaf := useaf_preferv6; {$endif}{$endif} port := toport; - toaddr[socknum] := ipstrtobinf(addr); + toaddr[socknum] := ip; makeinaddrv(toaddr[socknum],port,inaddr); sendto(fd[socknum],packet,len,0,inaddr,inaddrsize(inaddr)); @@ -138,16 +137,14 @@ var inAddrtemp : TInetSockAddrV; a:integer; biniptemp:tbinip; - addr:string; + begin //init both sockets smultaneously, always, so they get succesive fd's if fd[0] > 0 then exit; - if overridednsserver <> '' then addr := overridednsserver else addr := getcurrentsystemnameserver(id); + biniptemp := getcurrentsystemnameserverbin(id); //must get the DNS server here so we know to init v4 or v6 - ipstrtobin(addr,biniptemp); - if biniptemp.family = AF_INET6 then biniptemp := ipstrtobinf('::') else biniptemp := ipstrtobinf('0.0.0.0'); @@ -177,7 +174,6 @@ var currenttime : integer; lag : ttimeval; - currenttimeout : ttimeval; selecttimeout : ttimeval; socknum:integer; needprocessing:array[0..numsock-1] of boolean; @@ -188,7 +184,7 @@ var Srcx : {$ifdef win32}sockaddr_in{$else}TInetSockAddrV{$endif} absolute Src; SrcLen : Integer; fromip:tbinip; - fromport:string; + fromport:ansistring; begin if timeout < mintimeout then timeout := defaulttimeout; @@ -257,7 +253,7 @@ begin fillchar(state[socknum].recvpacket,sizeof(state[socknum].recvpacket),0); msectotimeval(lag,(currenttime-sendquerytime[socknum]) and tsmask); - if overridednsserver = '' then reportlag(id,(lag.tv_sec*1000000)+lag.tv_usec); + reportlag(id,(lag.tv_sec*1000000)+lag.tv_usec); SrcLen := SizeOf(Src); state[socknum].recvpacketlen := recvfrom(fd[socknum],state[socknum].recvpacket, SizeOf(state[socknum].recvpacket),0,Srcx,SrcLen); @@ -280,7 +276,7 @@ begin currenttime := getts; - if overridednsserver = '' then reportlag(id,-1); + reportlag(id,-1); if (currenttime >= endtime) and ((not wrapmode) or (currenttime < starttime)) then begin exit; end else begin @@ -296,10 +292,10 @@ end; -function forwardlookuplist(name:string;timeout:integer):tbiniplist; +function forwardlookuplist(name:ansistring;timeout:integer):tbiniplist; var dummy : integer; - a,b:integer; + a:integer; biniptemp:tbinip; l:tbiniplist; begin @@ -367,7 +363,7 @@ begin end; end; -function forwardlookup(name:string;timeout:integer):tbinip; +function forwardlookup(name:ansistring;timeout:integer):tbinip; var listtemp:tbiniplist; begin @@ -375,7 +371,7 @@ begin result := biniplist_get(listtemp,0); end; -function reverselookup(ip:tbinip;timeout:integer):string; +function reverselookup(ip:tbinip;timeout:integer):ansistring; var dummy : integer; begin