X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/f3321a0eafbeda0e8ebfb420974d391d7904ed44..ed1d49cbe548d9fb26a50f1b2381b693c3c01790:/dnssync.pas diff --git a/dnssync.pas b/dnssync.pas index d037a68..f6b0281 100644 --- a/dnssync.pas +++ b/dnssync.pas @@ -71,6 +71,7 @@ implementation {$i unixstuff.inc} +type tdnsstatearr=array[0..numsock-1] of tdnsstate; {$ifdef syncdnscore} @@ -98,9 +99,6 @@ begin {$endif} end; - -type tdnsstatearr=array[0..numsock-1] of tdnsstate; - procedure resolveloop(timeout:integer;var state:tdnsstatearr;numsockused:integer); var selectresult : integer; @@ -134,7 +132,8 @@ procedure setupsocket; var inAddrtemp : TInetSockAddrV; biniptemp:tbinip; - a:integer; + a,retrycount,porttemp:integer; + bindresult:boolean; begin biniptemp := getcurrentsystemnameserverbin(id); //must get the DNS server here so we know to init v4 or v6 @@ -143,11 +142,22 @@ begin for a := 0 to numsockused-1 do begin - makeinaddrv(biniptemp,inttostr( 1024 + randominteger(65536 - 1024) ),inaddrtemp); + retrycount := 5; + repeat + if (retrycount <= 1) then begin + porttemp := 0; //for the last attempt let the OS decide + end else begin + porttemp := 1024 + randominteger(65536 - 1024); + end; + + makeinaddrv(biniptemp,inttostr( porttemp ),inaddrtemp); - fd[a] := Socket(biniptemp.family,SOCK_DGRAM,0); + fd[a] := Socket(biniptemp.family,SOCK_DGRAM,0); + bindresult := {$ifdef win32}Not{$endif} Bind(fd[a],inAddrtemp,inaddrsize(inaddrtemp)); + dec(retrycount); + until (retrycount <= 0) or (bindresult); - If {$ifndef win32}Not{$endif} Bind(fd[a],inAddrtemp,inaddrsize(inaddrtemp)) Then begin + If (not bindresult) Then begin {$ifdef win32} raise Exception.create('unable to bind '+inttostr(WSAGetLastError)); {$else}