2
0

ip6test.pp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. program ip6test;
  2. uses
  3. sockets,
  4. unix,
  5. errors,
  6. netdb,
  7. baseunix;
  8. var
  9. dest: TInetSockAddr6;
  10. sock: LongInt;
  11. s: shortstring;
  12. i: integer;
  13. t1,t2:text;
  14. x: array of thostaddr6;
  15. hname : string;
  16. Const
  17. ip6hosttest = 'whatismyv6.com';
  18. begin
  19. hname:=ip6hosttest;
  20. if paramcount>0 then
  21. hname:=paramstr(1);
  22. setlength(x, 100);
  23. i:=resolvename6(hname, x);
  24. if i=-1 then
  25. begin
  26. writeln('Domain not found, ',hname);
  27. halt;
  28. end;
  29. setlength(x,i);
  30. if length(x) = 0 then halt(2);
  31. with dest do begin
  32. sin6_family := PF_INET6;
  33. sin6_port := shorthosttonet(80);
  34. sin6_addr.u6_addr16 := x[0].u6_addr16;
  35. end;
  36. sock := fpsocket(PF_INET6, SOCK_STREAM, 6 {TCP});
  37. if fpConnect(sock, @dest, sizeof(dest))=0 then begin
  38. sock2text(sock,t1,t2);
  39. writeln(t2, 'GET / HTTP/1.0');
  40. writeln(t2);
  41. while not eof(t1) do begin
  42. readln(t1, s);
  43. writeln(s);
  44. end;
  45. end else begin
  46. writeln('not connected: ',socketerror, ': ', StrError(socketerror));
  47. end;
  48. closesocket(sock);
  49. end.