testdns.pp 1.7 KB

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