home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / comms / other / rxsocket / examples / rxresolve.rexx < prev    next >
OS/2 REXX Batch file  |  1998-05-09  |  2KB  |  86 lines

  1. /*
  2.     rxresolve: just like miamiresolve (and maybe more)
  3.  
  4.     Usage: rxresolve <host>
  5.            rxresolve -s <servicename>
  6. */
  7.  
  8. parse arg host "-s" serv .
  9.  
  10. if ~show("L","rxsocket.library") then
  11.     if ~addLib("rxsocket.library",0,-30) then do
  12.         say "can't find rxsocket.library"
  13.         exit
  14.     end
  15.  
  16. if host="" then
  17.     if serv="" then call usage()
  18.     else call findServ(serv)
  19. else
  20.     if host="?" then call usage()
  21.     else call findHost(host)
  22.  
  23. /****************************************************************************/
  24.  
  25. Usage: PROCEDURE
  26.     say "Usage: rxresolve host"
  27.     say "       rxresolve -s servicename"
  28.     exit
  29.  
  30. /****************************************************************************/
  31.  
  32. findServ: PROCEDURE
  33. parse arg serv
  34.  
  35.     if DataType(serv,NUM) then res = GetServByPort("SERV",serv,"tcp")
  36.     else res = GetServByName("SERV",serv,"tcp")
  37.  
  38.     if ~res then do
  39.         say "Service <" || serv || "> not found."
  40.         exit
  41.     end
  42.  
  43.     say "service:" serv.servname
  44.  
  45.     if serv.servaliases.num~=0 then do
  46.         say "aliases:"
  47.         do i = 0 to serv.servaliases.num-1
  48.             say "   " serv.servaliases.i
  49.         end
  50.     end
  51.  
  52.     say "port:" serv.servport
  53.  
  54.     exit
  55.  
  56. /****************************************************************************/
  57.  
  58. findHost: PROCEDURE
  59. parse arg host
  60.  
  61.     if IsDotAddr(host) then res = GetHostByAddr("HE",host)
  62.     else res = GetHostByname("HE",host)
  63.  
  64.     if ~res then do
  65.         say "Host <" || host || "> not found (" || HostErrorstring(HostErrorNo()) || ")."
  66.         exit
  67.     end
  68.  
  69.     say "host:" he.hostname
  70.  
  71.     if he.hostaliases.num ~= 0 then do
  72.         say "aliases:"
  73.         do i = 0 to he.hostaliases.num-1
  74.             say "   " he.hostaliases.i
  75.         end
  76.     end
  77.  
  78.     say "address list:"
  79.     do i = 0 to he.hostaddrlist.num-1
  80.         say "   " he.hostaddrlist.i
  81.     end
  82.  
  83.     exit
  84.  
  85. /****************************************************************************/
  86.