var\r
inAddrtemp : TInetSockAddrV;\r
biniptemp:tbinip;\r
- a:integer;\r
+ a,retrycount,porttemp:integer;\r
+ bindresult:boolean;\r
begin\r
biniptemp := getcurrentsystemnameserverbin(id);\r
//must get the DNS server here so we know to init v4 or v6\r
\r
\r
for a := 0 to numsockused-1 do begin\r
- makeinaddrv(biniptemp,inttostr( 1024 + randominteger(65536 - 1024) ),inaddrtemp);\r
+ retrycount := 5;\r
+ repeat\r
+ if (retrycount <= 1) then begin\r
+ porttemp := 0; //for the last attempt let the OS decide\r
+ end else begin\r
+ porttemp := 1024 + randominteger(65536 - 1024);\r
+ end;\r
+\r
+ makeinaddrv(biniptemp,inttostr( porttemp ),inaddrtemp);\r
\r
- fd[a] := Socket(biniptemp.family,SOCK_DGRAM,0);\r
+ fd[a] := Socket(biniptemp.family,SOCK_DGRAM,0);\r
+ bindresult := {$ifdef win32}Not{$endif} Bind(fd[a],inAddrtemp,inaddrsize(inaddrtemp));\r
+ dec(retrycount);\r
+ until (retrycount <= 0) or (bindresult);\r
\r
- If {$ifndef win32}Not{$endif} Bind(fd[a],inAddrtemp,inaddrsize(inaddrtemp)) Then begin\r
+ If (not bindresult) Then begin\r
{$ifdef win32}\r
raise Exception.create('unable to bind '+inttostr(WSAGetLastError));\r
{$else}\r