X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/5ed1983da18c780d8252c2211f10fe58ae11ae93..87fed35010bb66b6183b06b01adb356dbefeefe6:/dnssync.pas?ds=inline diff --git a/dnssync.pas b/dnssync.pas index 60af580..f6b0281 100644 --- a/dnssync.pas +++ b/dnssync.pas @@ -132,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 @@ -141,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}