+\r
+{the following code's purpose is to determine what IP windows would come from, to reach an IP\r
+it can be abused to find if there's any global v6 IPs, getaddrinfo seems unreliable (not working on XP atleast)\r
+}\r
+const\r
+ SIO_ROUTING_INTERFACE_QUERY = $c8000014;\r
+ function WSAIoctl(s: TSocket; code:integer; const Buf; len: Integer; var output; outlen:integer; var outreturned: Integer; overlapped:pointer; completion: pointer): Integer; stdcall; external 'ws2_32.dll' name 'WSAIoctl';\r
+\r
+function getlocalipforip(const ip:tbinip):tbinip;\r
+var\r
+ handle:integer;\r
+ a,b:integer;\r
+ inaddrv,inaddrv2:tinetsockaddrv;\r
+ srcx:winsock.tsockaddr absolute inaddrv2;\r
+begin\r
+ makeinaddrv(ip,'0',inaddrv);\r
+ handle := Socket(inaddrv.inaddr.family,SOCK_DGRAM,IPPROTO_UDP);\r
+ if WSAIoctl(handle, SIO_ROUTING_INTERFACE_QUERY, inaddrv, sizeof(inaddrv), inaddrv2, sizeof(inaddrv2), a, nil, nil) <> 0\r
+ then raise exception.create('getlocalipforip failed with error: '+inttostr(wsagetlasterror));\r
+ result := inaddrvtobinip(inaddrv2);\r
+ closesocket(handle);\r
+end;\r
+\r