PageRenderTime 22ms CodeModel.GetById 19ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/packages/fcl-net/examples/cnslookup.pp

https://github.com/slibre/freepascal
Puppet | 28 lines | 25 code | 3 blank | 0 comment | 2 complexity | 67a7d9fe75cf925b999c99dfc9cee0c7 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, LGPL-3.0
 1
 2{$mode objfpc}
 3uses cnetdb,sockets;
 4
 5var host : PHostEnt;
 6    h_addr: in_addr;
 7    s : ansistring;
 8
 9begin
10  if paramcount<>1 then
11    begin
12      writeln(stderr,'Usage: nslookup <inet_address>');
13      halt(1);
14    end;
15  s:=paramstr(1);
16  host:=gethostbyname(pansichar(s));
17  if not assigned(host) then
18    begin
19      writeln(stderr,'(mini) nslookup failed on ',s);
20      halt(1);
21    end;
22  //writeln(host^.h_addr_list[0]);
23  h_addr.s_addr:= pcardinal(host^.h_addr_list[0])^;
24  writeln(NetAddrToStr(h_addr));
25//            h_addr.s_addr = *((unsigned long *) host->h_addr_list[0]);
26//            fprintf(stdout, "%s\n", inet_ntoa(h_addr));
27  halt(0);
28end.