123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- program testinet;
- {
- Program to test the inet unit.
- (C) 1997,1998 by Michael Van Canneyt
- }
- uses inet;
- var p : PHostEnt;
- ph : Phostaddr;
- pn : PNetEnt;
- ps : PServEnt;
- pp : ppchar;
- host : THost;
- Net : TNet;
- service : TService;
- S : String;
- TheAddr : THostAddr;
- const
- { Lily is my machine. This may not work of you're on a
- standalone machine. In that case, replace the address by
- an address known to your machine, or, as a last resort, 127.0.0.1 }
- lily : THostAddr = (134,58,81,164);
- {lily : THostAddr = (127,0,0,1);}
- begin
- p:=gethostbyname ('LocalHost');
- if p=nil then
- begin
- Writeln ('GetHostByname : No entry');
- end
- else
- begin
- Writeln ('Data for localhost : ');
- with p^ do
- begin
- writeln ('Name : ',name);
- writeln ('Length : ',Addrlen);
- pp:=aliases;
- while pp^<>nil do
- begin
- writeln ('Alias : ',pp^);
- inc(longint(pp),4);
- end;
- ph:=PHostAddr(addrlist^);
- writeln ('Addres : ',ph^[1],'.',ph^[2],'.',ph^[3],'.',ph^[4]);
- end;
- end;
- p:=gethostbyaddr (@lily,4,2);
- if p=nil then
- begin
- Writeln ('Gethostbyaddr : No entry');
- end
- else
- begin
- Writeln ('Data for ',lily[1],'.',lily[2],'.',lily[3],'.',lily[4] );
- with p^ do
- begin
- writeln ('Name : ',name);
- writeln ('Length : ',Addrlen);
- pp:=aliases;
- while pp^<>nil do
- begin
- writeln ('Alias : ',pp^);
- inc(longint(pp),4);
- end;
- ph:=PHostAddr(addrlist^);
- writeln ('Addres : ',ph^[1],'.',ph^[2],'.',ph^[3],'.',ph^[4]);
- end;
- end;
- pn:=GetNetByName ('loopback');
- if pn=nil then
- begin
- writeln ('GetNetByName : No entry');
- end
- else
- begin
- Writeln ('Data for loopback : ');
- with pn^ do
- begin
- writeln ('Name : ',name);
- writeln ('Type : ',AddrType);
- pp:=aliases;
- while pp^<>nil do
- begin
- writeln ('Alias : ',pp^);
- inc(longint(pp),4);
- end;
- ph:=PHostAddr(@net);
- writeln ('Addres : ',ph^[4],'.',ph^[3],'.',ph^[2],'.',ph^[1]);
- end;
- end;
- pn:=GetNetByAddr ((127 shl 24),2);
- if pn=nil then
- begin
- writeln ('GetNetByAddr : No entry');
- end
- else
- begin
- Writeln ('Data for 127.0.0.0 : ');
- with pn^ do
- begin
- writeln ('Name : ',name);
- writeln ('Type : ',AddrType);
- pp:=aliases;
- while pp^<>nil do
- begin
- writeln ('Alias : ',pp^);
- inc(longint(pp),4);
- end;
- ph:=PHostAddr(@net);
- writeln ('Addres : ',ph^[4],'.',ph^[3],'.',ph^[2],'.',ph^[1]);
- end;
- end;
- ps:=GetServByName ('telnet','tcp');
- if ps=nil then
- begin
- writeln ('GetServByName : No entry ');
- end
- else
- with ps^ do
- begin
- writeln ('Name : ',name);
- writeln ('Protocol : ',proto);
- writeln ('Port ',port shr 8);
- pp:=aliases;
- while pp^<>nil do
- begin
- writeln ('Alias : ',pp^);
- inc(longint(pp),4);
- end;
- end;
- ps:=GetServByPort (23 shl 8 ,'tcp');
- if ps=nil then
- begin
- writeln ('GetServByPort : No entry ');
- end
- else
- with ps^ do
- begin
- writeln ('Name : ',name);
- writeln ('Protocol : ',proto);
- writeln ('Port ',port shr 8);
- pp:=aliases;
- while pp^<>nil do
- begin
- writeln ('Alias : ',pp^);
- inc(longint(pp),4);
- end;
- end;
- Writeln ('Creating Host Object with namelookup(tflily)');
- Host.NameLookup ('tflily');
- If Host.LastError=0 then
- begin
- Writeln ('Name : ',host.name);
- S:=Host.GetAlias (stfirst);
- While S<>'' do
- begin
- Writeln ('Host alias : ',S);
- S:=Host.GetAlias(stnext);
- end;
- S:=Host.GetAddress (stfirst);
- While S<>'' do
- begin
- Writeln ('Host address : ',S);
- S:=Host.GetAddress(stnext);
- end;
- end;
- Writeln ('Creating Host Object with Addresslookup(''tflily'')');
- Host.AddressLookup (lily);
- If Host.LastError=0 then
- begin
- Writeln ('Name : ',host.name);
- Writeln ('IP Address : ',host.IPstring);
- S:=Host.GetAlias (stfirst);
- While S<>'' do
- begin
- Writeln ('Host alias : ',S);
- S:=Host.GetAlias(stnext);
- end;
- S:=Host.GetAddress (stfirst);
- While S<>'' do
- begin
- Writeln ('Host address : ',S);
- S:=Host.GetAddress(stnext);
- end;
- end;
- Writeln ('Creating net Object with namelookup(''loopback'')');
- net.NameLookup ('loopback');
- If net.LastError=0 then
- begin
- Writeln ('Name : ',net.name);
- Writeln ('IP address : ',net.IPstring);
- S:=net.GetAlias (stfirst);
- While S<>'' do
- begin
- Writeln ('net alias : ',S);
- S:=net.GetAlias(stnext);
- end;
- end;
- Writeln ('Creating net Object with Addrlookup((127 shl 24))');
- net.AddressLookup ((127 shl 24));
- If net.LastError=0 then
- begin
- Writeln ('Name : ',net.name);
- Writeln ('IP address : ',net.IPstring);
- S:=net.GetAlias (stfirst);
- While S<>'' do
- begin
- Writeln ('net alias : ',S);
- S:=net.GetAlias(stnext);
- end;
- end;
- S:='134.58.81.164';
- TheAddr:=StrToHostAddr (S);
- Writeln (S,' = ',TheAddr[1],'.',theaddr[2],'.',theaddr[3],'.',theaddr[4]);
- Writeln ('Creating Service Object with Namelookup(''telnet'',''tcp'')');
- Service.Namelookup('telnet','tcp');
- If Service.LastError=0 then
- begin
- Writeln ('Name : ',Service.name);
- Writeln ('Protocol : ',service.protocol);
- Writeln ('Port : ',ShortNetToHost(service.port));
- S:=service.GetAlias (stfirst);
- While S<>'' do
- begin
- Writeln ('service alias : ',S);
- S:=service.GetAlias(stnext);
- end;
- end;
- Writeln ('Creating Service Object with Portlookup(23 shl 8 ,''tcp'')');
- Service.Portlookup(23 shl 8,'tcp');
- If Service.LastError=0 then
- begin
- Writeln ('Name : ',Service.name);
- Writeln ('Protocol : ',service.protocol);
- Writeln ('Port : ',ShortNetToHost(service.port));
- S:=service.GetAlias (stfirst);
- While S<>'' do
- begin
- Writeln ('service alias : ',S);
- S:=service.GetAlias(stnext);
- end;
- end;
-
- end. $Log$
- end. Revision 1.2 2000-07-13 11:33:26 michael
- end. + removed logs
- end.
- }
|