2
0

testhst.pp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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, hosts 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. program testhst;
  12. uses netdb,sockets;
  13. Procedure DumpHostEntry(Const H : THostEntry);
  14. begin
  15. With H do
  16. begin
  17. Writeln('Name : ',Name);
  18. Writeln('Addr : ',HostAddrToStr(Addr));
  19. Writeln('Aliases : ',Aliases);
  20. Writeln;
  21. end;
  22. end;
  23. Procedure TestAddr(Addr : string);
  24. Var
  25. H : THostEntry;
  26. begin
  27. If GetHostByAddr(StrToHostAddr(Addr),H) then
  28. DumpHostEntry(H)
  29. else
  30. Writeln('No entry for address ',Addr)
  31. end;
  32. Procedure TestName(Const N : string);
  33. Var
  34. H : THostEntry;
  35. begin
  36. If GetHostByName(N,H) then
  37. DumpHostEntry(H)
  38. else
  39. Writeln('No entry for hostname ',N)
  40. end;
  41. begin
  42. testaddr('127.0.0.1');
  43. testaddr('212.224.143.213');
  44. testname('LOCALHOST');
  45. testname('www.freepascal.org');
  46. testname('obelix.wisa.be');
  47. end.