X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/27e903c56380abcb11b5a0b8d7ccab88a14b5cde..096e05689a95dc55ef9f554978c5ea3f263bc919:/dnssync.pas?ds=sidebyside diff --git a/dnssync.pas b/dnssync.pas index c603b92..9a0c2c1 100644 --- a/dnssync.pas +++ b/dnssync.pas @@ -109,7 +109,7 @@ end; function sendquery(socknum:integer;const packet:tdnspacket;len:integer):boolean; var - addr : ansistring; + ip : tbinip; port : ansistring; inaddr : TInetSockAddrV; begin @@ -117,14 +117,14 @@ begin 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)); @@ -137,15 +137,17 @@ var inAddrtemp : TInetSockAddrV; a:integer; biniptemp:tbinip; - addr:ansistring; + 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); - //must get the DNS server here so we know to init v4 or v6 + {recreate sockets every time, reusing them will fail (hang) if the nameserver is changed + also changing the nameserver can't possibly work} + {if fd[0] > 0 then exit;} + for a := 0 to numsock-1 do if (fd[a] > 0) then closesocket(fd[a]); - ipstrtobin(addr,biniptemp); + biniptemp := getcurrentsystemnameserverbin(id); + //must get the DNS server here so we know to init v4 or v6 if biniptemp.family = AF_INET6 then biniptemp := ipstrtobinf('::') else biniptemp := ipstrtobinf('0.0.0.0'); @@ -255,7 +257,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); @@ -278,7 +280,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