IPv6.pas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. { $HDR$}
  2. {**********************************************************************}
  3. { Unit archived using Team Coherence }
  4. { Team Coherence is Copyright 2002 by Quality Software Components }
  5. { }
  6. { For further information / comments, visit our WEB site at }
  7. { http://www.TeamCoherence.com }
  8. {**********************************************************************}
  9. {}
  10. { $Log: 14146: IPv6.pas
  11. {
  12. { Rev 1.2 9/8/2003 02:54:54 PM JPMugaas
  13. { IPv6Detection test should work.
  14. }
  15. {
  16. Rev 1.1 4/5/2003 3:39:56 PM BGooijen
  17. now checks for IPv6 support first
  18. }
  19. {
  20. { Rev 1.0 12-7-2002 12:42:54 BGooijen
  21. { Tests to check if IPv4 and IPv6 works.
  22. { This is done by connection a TCPClient to a TCPServer.
  23. { NOTE: the IPv6 test fails when there is no IPv6 support in the OS.
  24. }
  25. unit IPv6;
  26. interface
  27. uses
  28. IndyBox;
  29. type
  30. TIdv6Test = class(TIndyBox)
  31. procedure Test; override;
  32. end;
  33. TIPv6Box = class(TIndyBox)
  34. public
  35. procedure Test; override;
  36. end;
  37. implementation
  38. uses
  39. IdComponent, IdStack,
  40. IdTCPServer, IdTCPClient, IdException, IdServerIOHandlerStack, IdIOHandlerStack, IdCoreGlobal,IdWship6,
  41. SysUtils;
  42. function IPv6Supported : Boolean;
  43. var LCreated : Boolean;
  44. begin
  45. LCreated := False;
  46. if Assigned(GStack)=False then
  47. begin
  48. GStack := TIdStack.CreateStack;
  49. LCreated := True;
  50. end;
  51. Result := GStack.SupportsIP6;
  52. if LCreated then
  53. begin
  54. FreeAndNil(GStack);
  55. end;
  56. end;
  57. { TCommandHandlerProc }
  58. procedure TIPv6Box.Test;
  59. var
  60. LServer: TIdTCPServer;
  61. LServerIO:TIdServerIOHandlerStack;
  62. LClient: TIdTCPClient;
  63. LClientIO:TIdIOHandlerStack;
  64. begin
  65. LServer:= nil;
  66. LServerIO:= nil;
  67. LClient:= nil;
  68. LClientIO:= nil;
  69. If IPv6Supported = False then
  70. begin
  71. Status('IPv6-support not detected, skipping test');
  72. exit;
  73. end;
  74. //if not IdIPv6Available then begin
  75. // Status('IPv6-support not detected, skipping test');
  76. // exit;
  77. //end;
  78. try
  79. LServer:= TIdTCPServer.Create(nil);
  80. LServerIO:= TIdServerIOHandlerStack.Create(nil);
  81. LServer.IOHandler:= LServerIO;
  82. with LServer.Bindings.Add do begin
  83. IP:='::0';
  84. Port:=12987;
  85. IPVersion:=Id_IPv6;
  86. end;
  87. try
  88. LServer.Active:=true;
  89. except on e: EIdException do
  90. Check(false, 'The TIdTCPServer failed to start: '+e.message);
  91. end;
  92. Check(LServer.Active, 'The TIdTCPServer doesn''t seem to be running, but no exception occured?'); // BGO: Just to be sure
  93. LClient:= TIdTCPClient.Create(nil);
  94. LClientIO:= TIdIOHandlerStack.Create(nil);
  95. LClient.IOHandler:=LClientIO;
  96. LClientIO.Host:='::1';
  97. LClientIO.Port:=12987;
  98. LClientIO.IPVersion:=Id_IPv6;
  99. try
  100. LClient.Connect;
  101. except on e: EIdException do
  102. Check(false, 'The TIdTCPClient failed to connect: '+e.message);
  103. end;
  104. finally
  105. FreeAndNil( LServer );
  106. FreeAndNil( LServerIO );
  107. FreeAndNil( LClient );
  108. FreeAndNil( LClientIO );
  109. end;
  110. end;
  111. { TIdv6Test }
  112. procedure TIdv6Test.Test;
  113. begin
  114. If IPv6Supported then
  115. begin
  116. Status('IPv6-support detected');
  117. end
  118. else
  119. begin
  120. Status('IPv6-support not detected');
  121. end;
  122. end;
  123. initialization
  124. TIndyBox.RegisterBox(TIPv6Box, 'IPv6 Support', 'Misc');
  125. TIndyBox.RegisterBox(TIdv6Test,'IPv6 detection', 'Misc');
  126. end.