uses\r
dnscore,\r
binipstuff,\r
- {$ifdef win32}\r
+ {$ifdef mswindows}\r
winsock,\r
windows,\r
{$else}\r
\r
//convert a name to an IP\r
//will return v4 or v6 depending on what seems favorable, or manual preference setting\r
-//on error the binip will have a family of 0 (other fiels are also currently\r
+//on error the binip will have a family of 0 (other fields are also currently\r
//zeroed out but may be used for further error information in future)\r
-//timeout is in miliseconds, it is ignored when using windows dns\r
+//timeout is in milliseconds, it is ignored when using windows dns\r
function forwardlookup(name:ansistring;timeout:integer):tbinip;\r
\r
//convert a name to a list of all IP's returned\r
\r
implementation\r
\r
-{$ifdef win32}\r
+{$ifdef mswindows}\r
uses dnswin;\r
{$endif}\r
\r
\r
-{$ifndef win32}\r
+{$ifndef mswindows}\r
{$define syncdnscore}\r
{$endif}\r
\r
{$i unixstuff.inc}\r
\r
+type tdnsstatearr=array[0..numsock-1] of tdnsstate;\r
\r
{$ifdef syncdnscore}\r
\r
\r
-{$ifdef win32}\r
+{$ifdef mswindows}\r
const\r
winsocket = 'wsock32.dll';\r
function sendto(s: TSocket; const Buf; len, flags: Integer; var addrto: TinetSockAddrV; tolen: Integer): Integer; stdcall; external winsocket name 'sendto';\r
\r
\r
function getts:integer;\r
-{$ifdef win32}\r
+{$ifdef mswindows}\r
begin\r
result := GetTickCount and tsmask;\r
{$else}\r
var\r
temp:ttimeval;\r
begin\r
- gettimeofday(temp);\r
+ gettimemonotonic(temp);\r
result := ((temp.tv_usec div 1000) + (temp.tv_sec * 1000)) and tsmask;\r
{$endif}\r
end;\r
\r
-\r
-type tdnsstatearr=array[0..numsock-1] of tdnsstate;\r
-\r
procedure resolveloop(timeout:integer;var state:tdnsstatearr;numsockused:integer);\r
var\r
selectresult : integer;\r
a,b:integer;\r
\r
Src : TInetSockAddrV;\r
- Srcx : {$ifdef win32}sockaddr_in{$else}TInetSockAddrV{$endif} absolute Src;\r
+ Srcx : {$ifdef mswindows}sockaddr_in{$else}TInetSockAddrV{$endif} absolute Src;\r
SrcLen : Integer;\r
fromip:tbinip;\r
fromport:ansistring;\r
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 mswindows}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
- {$ifdef win32}\r
+ If (not bindresult) Then begin\r
+ {$ifdef mswindows}\r
raise Exception.create('unable to bind '+inttostr(WSAGetLastError));\r
{$else}\r
raise Exception.create('unable to bind '+inttostr(socketError));\r
\r
ip := getcurrentsystemnameserverbin(id);\r
\r
- {$ifdef ipv6}{$ifdef win32}\r
+ {$ifdef ipv6}{$ifdef mswindows}\r
if toaddr[socknum].family = AF_INET6 then if (useaf = 0) then useaf := useaf_preferv6;\r
{$endif}{$endif}\r
\r
selecttimeout.tv_sec := 0;\r
selecttimeout.tv_usec := retryafter;\r
end;\r
- //find the highest of the used fd's\r
+ //find the highest of the used fds\r
b := 0;\r
for socknum := numsockused-1 downto 0 do if fd[socknum] > b then b := fd[socknum];\r
selectresult := select(b+1,@fds,nil,nil,@selecttimeout);\r
exit; //it was an IP address, no need for dns\r
end;\r
\r
- {$ifdef win32}\r
+ {$ifdef mswindows}\r
if usewindns then begin\r
if (useaf = useaf_v4) then a := af_inet else if (useaf = useaf_v6) then a := af_inet6 else a := 0;\r
result := winforwardlookuplist(name,a,dummy);\r
numsockused:integer;\r
state:tdnsstatearr;\r
begin\r
- {$ifdef win32}\r
+ {$ifdef mswindows}\r
if usewindns then begin\r
result := winreverselookup(ip,dummy);\r
exit;\r
{$endif}\r
end;\r
\r
-{$ifdef win32}\r
+{$ifdef mswindows}\r
var\r
wsadata : twsadata;\r
\r