From: beware Date: Sat, 25 Feb 2012 15:46:17 +0000 (+0000) Subject: for the last attempt of choosing a port, let the OS decide X-Git-Url: http://www.lcore.org/git/lcore.git/commitdiff_plain/9a8d70fc12f32787d6cdea912f84aca3d47326c4?hp=2579cad7a973072619a7fc17ff6af9cc75264972 for the last attempt of choosing a port, let the OS decide git-svn-id: file:///svnroot/lcore/trunk@114 b1de8a11-f9be-4011-bde0-cc7ace90066a --- diff --git a/dnssync.pas b/dnssync.pas index 79ace01..f6b0281 100644 --- a/dnssync.pas +++ b/dnssync.pas @@ -132,7 +132,7 @@ procedure setupsocket; var inAddrtemp : TInetSockAddrV; biniptemp:tbinip; - a,retrycount:integer; + a,retrycount,porttemp:integer; bindresult:boolean; begin biniptemp := getcurrentsystemnameserverbin(id); @@ -144,7 +144,13 @@ begin for a := 0 to numsockused-1 do begin retrycount := 5; repeat - makeinaddrv(biniptemp,inttostr( 1024 + randominteger(65536 - 1024) ),inaddrtemp); + 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); bindresult := {$ifdef win32}Not{$endif} Bind(fd[a],inAddrtemp,inaddrsize(inaddrtemp));