testinet.pp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. program testinet;
  2. {
  3. Program to test the inet unit.
  4. (C) 1997,1998 by Michael Van Canneyt
  5. }
  6. uses inet;
  7. var p : PHostEnt;
  8. ph : Phostaddr;
  9. pn : PNetEnt;
  10. ps : PServEnt;
  11. pp : ppchar;
  12. host : THost;
  13. Net : TNet;
  14. service : TService;
  15. S : String;
  16. TheAddr : THostAddr;
  17. const
  18. { Lily is my machine. This may not work of you're on a
  19. standalone machine. In that case, replace the address by
  20. an address known to your machine, or, as a last resort, 127.0.0.1 }
  21. lily : THostAddr = (134,58,81,164);
  22. {lily : THostAddr = (127,0,0,1);}
  23. begin
  24. p:=gethostbyname ('LocalHost');
  25. if p=nil then
  26. begin
  27. Writeln ('GetHostByname : No entry');
  28. end
  29. else
  30. begin
  31. Writeln ('Data for localhost : ');
  32. with p^ do
  33. begin
  34. writeln ('Name : ',name);
  35. writeln ('Length : ',Addrlen);
  36. pp:=aliases;
  37. while pp^<>nil do
  38. begin
  39. writeln ('Alias : ',pp^);
  40. inc(longint(pp),4);
  41. end;
  42. ph:=PHostAddr(addrlist^);
  43. writeln ('Addres : ',ph^[1],'.',ph^[2],'.',ph^[3],'.',ph^[4]);
  44. end;
  45. end;
  46. p:=gethostbyaddr (@lily,4,2);
  47. if p=nil then
  48. begin
  49. Writeln ('Gethostbyaddr : No entry');
  50. end
  51. else
  52. begin
  53. Writeln ('Data for ',lily[1],'.',lily[2],'.',lily[3],'.',lily[4] );
  54. with p^ do
  55. begin
  56. writeln ('Name : ',name);
  57. writeln ('Length : ',Addrlen);
  58. pp:=aliases;
  59. while pp^<>nil do
  60. begin
  61. writeln ('Alias : ',pp^);
  62. inc(longint(pp),4);
  63. end;
  64. ph:=PHostAddr(addrlist^);
  65. writeln ('Addres : ',ph^[1],'.',ph^[2],'.',ph^[3],'.',ph^[4]);
  66. end;
  67. end;
  68. pn:=GetNetByName ('loopback');
  69. if pn=nil then
  70. begin
  71. writeln ('GetNetByName : No entry');
  72. end
  73. else
  74. begin
  75. Writeln ('Data for loopback : ');
  76. with pn^ do
  77. begin
  78. writeln ('Name : ',name);
  79. writeln ('Type : ',AddrType);
  80. pp:=aliases;
  81. while pp^<>nil do
  82. begin
  83. writeln ('Alias : ',pp^);
  84. inc(longint(pp),4);
  85. end;
  86. ph:=PHostAddr(@net);
  87. writeln ('Addres : ',ph^[4],'.',ph^[3],'.',ph^[2],'.',ph^[1]);
  88. end;
  89. end;
  90. pn:=GetNetByAddr ((127 shl 24),2);
  91. if pn=nil then
  92. begin
  93. writeln ('GetNetByAddr : No entry');
  94. end
  95. else
  96. begin
  97. Writeln ('Data for 127.0.0.0 : ');
  98. with pn^ do
  99. begin
  100. writeln ('Name : ',name);
  101. writeln ('Type : ',AddrType);
  102. pp:=aliases;
  103. while pp^<>nil do
  104. begin
  105. writeln ('Alias : ',pp^);
  106. inc(longint(pp),4);
  107. end;
  108. ph:=PHostAddr(@net);
  109. writeln ('Addres : ',ph^[4],'.',ph^[3],'.',ph^[2],'.',ph^[1]);
  110. end;
  111. end;
  112. ps:=GetServByName ('telnet','tcp');
  113. if ps=nil then
  114. begin
  115. writeln ('GetServByName : No entry ');
  116. end
  117. else
  118. with ps^ do
  119. begin
  120. writeln ('Name : ',name);
  121. writeln ('Protocol : ',proto);
  122. writeln ('Port ',port shr 8);
  123. pp:=aliases;
  124. while pp^<>nil do
  125. begin
  126. writeln ('Alias : ',pp^);
  127. inc(longint(pp),4);
  128. end;
  129. end;
  130. ps:=GetServByPort (23 shl 8 ,'tcp');
  131. if ps=nil then
  132. begin
  133. writeln ('GetServByPort : No entry ');
  134. end
  135. else
  136. with ps^ do
  137. begin
  138. writeln ('Name : ',name);
  139. writeln ('Protocol : ',proto);
  140. writeln ('Port ',port shr 8);
  141. pp:=aliases;
  142. while pp^<>nil do
  143. begin
  144. writeln ('Alias : ',pp^);
  145. inc(longint(pp),4);
  146. end;
  147. end;
  148. Writeln ('Creating Host Object with namelookup(tflily)');
  149. Host.NameLookup ('tflily');
  150. If Host.LastError=0 then
  151. begin
  152. Writeln ('Name : ',host.name);
  153. S:=Host.GetAlias (stfirst);
  154. While S<>'' do
  155. begin
  156. Writeln ('Host alias : ',S);
  157. S:=Host.GetAlias(stnext);
  158. end;
  159. S:=Host.GetAddress (stfirst);
  160. While S<>'' do
  161. begin
  162. Writeln ('Host address : ',S);
  163. S:=Host.GetAddress(stnext);
  164. end;
  165. end;
  166. Writeln ('Creating Host Object with Addresslookup(''tflily'')');
  167. Host.AddressLookup (lily);
  168. If Host.LastError=0 then
  169. begin
  170. Writeln ('Name : ',host.name);
  171. Writeln ('IP Address : ',host.IPstring);
  172. S:=Host.GetAlias (stfirst);
  173. While S<>'' do
  174. begin
  175. Writeln ('Host alias : ',S);
  176. S:=Host.GetAlias(stnext);
  177. end;
  178. S:=Host.GetAddress (stfirst);
  179. While S<>'' do
  180. begin
  181. Writeln ('Host address : ',S);
  182. S:=Host.GetAddress(stnext);
  183. end;
  184. end;
  185. Writeln ('Creating net Object with namelookup(''loopback'')');
  186. net.NameLookup ('loopback');
  187. If net.LastError=0 then
  188. begin
  189. Writeln ('Name : ',net.name);
  190. Writeln ('IP address : ',net.IPstring);
  191. S:=net.GetAlias (stfirst);
  192. While S<>'' do
  193. begin
  194. Writeln ('net alias : ',S);
  195. S:=net.GetAlias(stnext);
  196. end;
  197. end;
  198. Writeln ('Creating net Object with Addrlookup((127 shl 24))');
  199. net.AddressLookup ((127 shl 24));
  200. If net.LastError=0 then
  201. begin
  202. Writeln ('Name : ',net.name);
  203. Writeln ('IP address : ',net.IPstring);
  204. S:=net.GetAlias (stfirst);
  205. While S<>'' do
  206. begin
  207. Writeln ('net alias : ',S);
  208. S:=net.GetAlias(stnext);
  209. end;
  210. end;
  211. S:='134.58.81.164';
  212. TheAddr:=StrToHostAddr (S);
  213. Writeln (S,' = ',TheAddr[1],'.',theaddr[2],'.',theaddr[3],'.',theaddr[4]);
  214. Writeln ('Creating Service Object with Namelookup(''telnet'',''tcp'')');
  215. Service.Namelookup('telnet','tcp');
  216. If Service.LastError=0 then
  217. begin
  218. Writeln ('Name : ',Service.name);
  219. Writeln ('Protocol : ',service.protocol);
  220. Writeln ('Port : ',ShortNetToHost(service.port));
  221. S:=service.GetAlias (stfirst);
  222. While S<>'' do
  223. begin
  224. Writeln ('service alias : ',S);
  225. S:=service.GetAlias(stnext);
  226. end;
  227. end;
  228. Writeln ('Creating Service Object with Portlookup(23 shl 8 ,''tcp'')');
  229. Service.Portlookup(23 shl 8,'tcp');
  230. If Service.LastError=0 then
  231. begin
  232. Writeln ('Name : ',Service.name);
  233. Writeln ('Protocol : ',service.protocol);
  234. Writeln ('Port : ',ShortNetToHost(service.port));
  235. S:=service.GetAlias (stfirst);
  236. While S<>'' do
  237. begin
  238. Writeln ('service alias : ',S);
  239. S:=service.GetAlias(stnext);
  240. end;
  241. end;
  242. end. $Log$
  243. end. Revision 1.2 2000-07-13 11:33:26 michael
  244. end. + removed logs
  245. end.
  246. }