Hello all!

I investigate a little in IPv6 and make first steps. First thing on my roadmap 
is getaddrinfo. Can somebody look at code below and tell me whats wrong? 
It wotks on Windows XP, but not on Windows 2008. I always get 11001.


Thanks for any help & best Regards, Alexander Svetov

        ...
        
   in6_addr = record
      s6_addr : array[0..15] of u_char;
   end;
   TInAddr6 = in6_addr;

   sockaddr_in6 = record
      sin6_family: short;
      sin6_port: u_short;
      sin6_flowinfo: u_long;
      sin6_addr: TInAddr6;
      sin6_scope_id: u_long;
   end;
   TSockAddrIn6 = sockaddr_in6;

        // see http://msdn.microsoft.com/en-us/library/ms737530(VS.85).aspx
        // for information about getaddrinfo
        
   PAddrInfo = ^TAddrInfo;
        TAddrInfo = record
        ai_flags: integer;
      ai_family: integer;
      ai_socktype: integer;
      ai_protocol: integer;
      ai_addrlen: integer;
      ai_canonname: PChar;
      ai_addr: PSockAddr;
      ai_next: PAddrInfo;
   end;


        function getaddrinfo(const NodeName, ServName: PChar; const Hints: 
PAddrInfo; var Addrinfo: PAddrInfo): integer; stdcall; external 'ws2_32.dll';
   procedure freeaddrinfo(ai: PAddrInfo); stdcall; external 'ws2_32.dll';
        function connect6(s: TSocket; const name: sockaddr_in6; namelen: 
Integer): integer; stdcall; external 'ws2_32.dll' name 'connect';

        ...

var
   S: TSocket;
   SData: TWSAData;
   RetVal: integer;
   Hints: TAddrInfo;
   Addr: PAddrInfo;
   IP4Addr: TSockAddrIn;
   IP6Addr: TSockAddrIn6;
const
   hostname = 'localhost';
begin
   WSAStartup($0202, SData);

   ZeroMemory(@Hints, sizeof(Hints));
   Hints.ai_family := AF_UNSPEC;
   Hints.ai_socktype := SOCK_STREAM;
   Hints.ai_protocol := IPPROTO_TCP;
   // Hints.ai_flags := AI_NUMERICHOST; // if we want to convert IP to sockaddr.

   RetVal := GetAddrInfo(hostname, '80', @Hints, Addr);
   if Retval = 0 then // success
   begin
        if (Addr <> nil) then  Move(Addr^.ai_addr^, IP6Addr, Addr^.ai_addrlen);
   end
   else
   begin
      showmessage(inttostr(RetVal) + '  ' + SysErrorMessage(Retval));
   end;

   freeaddrinfo(addr);

   S := Socket(AF_INET, SOCK_STREAM, IPPROTO_IP);

   RetVal := connect6(S, IP6Addr, SizeOf(TSockAddrIn6));
   if Retval = 0 then // success
   begin
      showmessage('connect');
   end
   else
   begin
      showmessage(inttostr(RetVal) + '  ' + SysErrorMessage(Retval));
   end;

   CloseSocket(S);

   WSACleanUp;
end;
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to