home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / SREFPRC1 / HOSTINFO.SRF < prev    next >
Text File  |  1996-10-04  |  2KB  |  68 lines

  1. /*-----------------------------*/
  2. /* use ip address and host info to return datadir, etc. 
  3. Only call this if there are multiple hosts defined (using the HOSTS.
  4. stem variable)
  5. */
  6. /* ----------------------------*/
  7. sref_host_info:
  8. parse upper arg myaddr0 , nhosts,enmadd
  9.  
  10. if enmadd=' ' then do
  11.    ap=extract('serverport')
  12.    enmadd='SREF_'||ap||'_'
  13. end
  14. if myaddr0=' ' | myaddr0=0 then  
  15.     myaddr0=extract('serveraddr')
  16. if nhosts=' ' then 
  17.    nhosts=value(enmadd||'HOSTS.0',,'os2environment')
  18.  
  19. myaddr=strip(myaddr0)
  20. myhost=reqfield('Host:')
  21. isname=0
  22.  
  23. /* check for possible wierd host remapping (but not desired) situation */
  24. isnumhost=verify(myhost,'1234567890.')
  25. if isnumhost=0 then do          /*a host:151.121.121.51 type header */
  26.     myaddr=myhost
  27.     myhost=''
  28.     isname=1            /* we want to lookup, but Also check myaddr address
  29.                        (almost always the same, to it's possibly duplicative*/
  30.  
  31. end
  32.  
  33.  
  34. try2: 
  35. if myhost<>"" then do
  36.     isname=1
  37.     myaddr=strip(upper(myhost))
  38. end
  39. else do
  40.    do ii=1 to nhosts   /* convert ipnumber to ipname, if specified in HOSTS. */
  41.      ahost=value(enmadd||'HOSTS_IP.'||ii,,'os2environment')
  42.      parse var ahost caddr cname
  43.      if strip(caddr)=myaddr then do
  44.          myaddr=strip(cname)
  45.          leave
  46.      end
  47.    end
  48. end
  49.  
  50. /* scan through hosts. entries looking for a match (host entries are 
  51. stored by servername) -- hence the loop above */
  52. do ii=1 to nhosts
  53.   ahost=value(enmadd||'HOSTS.'||ii,,'os2environment')
  54.   parse var ahost chost ',' .
  55.   if strip(chost)<>myaddr then iterate
  56.   return ahost    /* got match */
  57. end
  58.  
  59. if isname=1 then do
  60.    myhost=""
  61.    myaddr=strip(myaddr0)
  62.    isname=0
  63.    signal try2          /* try using numeric address, rather then non matching name */
  64. end
  65.  
  66. return 0   /* if here, no match found */
  67.  
  68.