testdns.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2003 by the Free Pascal development team
  5. test netdb unit, host part
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$mode objfpc}
  13. {$h+}
  14. program testdns;
  15. uses netdb;
  16. Procedure DumpHostEntry(Const H : THostEntry);
  17. begin
  18. With H do
  19. begin
  20. Writeln('Name : ',Name);
  21. Writeln('Addr : ',HostAddrToStr(Addr));
  22. Writeln('Aliases : ',Aliases);
  23. Writeln;
  24. end;
  25. end;
  26. Procedure TestAddr(Addr : string);
  27. Var
  28. H : THostEntry;
  29. begin
  30. If ResolveHostByAddr(StrToHostAddr(Addr),H) then
  31. DumpHostEntry(H)
  32. else
  33. Writeln('No entry for address ',Addr)
  34. end;
  35. Procedure TestName(Const N : string);
  36. Var
  37. H : THostEntry;
  38. begin
  39. If ResolveHostByName(N,H) then
  40. DumpHostEntry(H)
  41. else
  42. Writeln('No entry for hostname ',N)
  43. end;
  44. Var
  45. I,l : INteger;
  46. Ans : Array [1..10] of THostAddr;
  47. H : THostAddr;
  48. NAns : Array[1..10] of String;
  49. begin
  50. Writeln('Resolving name ');
  51. l:=ResolveName('malpertuus.wisa.be',Ans);
  52. Writeln('Got : ',l,' answers');
  53. For I:=1 to l do
  54. Writeln(i:2,': ',hostAddrtostr(Ans[i]));
  55. Writeln('Resolving address ');
  56. H:=StrtoHostAddr('212.224.143.202');
  57. L:=ResolveAddress(H,NAns);
  58. Writeln('Got : ',l,' answers');
  59. For I:=1 to l do
  60. Writeln(i:2,': ',NAns[i]);
  61. Writeln('ResolveHostByName:');
  62. testname('malpertuus.wisa.be');
  63. Writeln('ResolveHostByAddr:');
  64. testaddr('212.224.143.202');
  65. end.
  66. {
  67. $Log$
  68. Revision 1.2 2003-05-17 20:54:03 michael
  69. + uriparser unit added. Header/Footer blocks added
  70. }