      subroutine csub.gethostbyname(hostname, h.name, h.aliases, h.addrs)
*
*
*
*
*
*
*
*
*
$catalog local
*
$include ccall.common
*
      equate libname to 'libc.so.6'
      equate fnname  to 'gethostbyname'

      $include ccall.getfn.include
*
      h.name = ''
      h.aliases = ''
      h.addrs = ''

      s1 = cc$nul4 : hostname : CC$NUL
      s2 = CC$FN.PUSHOFF : cc$4 :      ~
           CC$FN.CALLFN  : fn.handle : ~
           CC$FN.RTN32   : cc$0 :      ~
           CC$FN.EXIT

      hostent.ptr = ccall(s1,s2)[1,4]

      call csub.errno

      if hostent.ptr = cc$0 then
         return
      end
      hostent = ccall.getmem(hostent.ptr,20)

      if hostent[1,4] <> cc$0 then
         h.name = ccall.getstr(hostent[1,4],512)
      end

      if hostent[5,4] <> cc$0 then
         ptr = bin2int(hostent[5,4])
         loop
            t = int2bin(ptr,4)
            alias.ptr = ccall.getmem(t,4)
         until alias.ptr = cc$0 do
            h.aliases<1,-1> = ccall.getstr(alias.ptr,512)
            ptr += 4
         repeat
      end

      addr.len = bin2int(hostent[13,4])
      if addr.len = 4 then
         if hostent[17,4] <> cc$0 then
            ptr = bin2int(hostent[17,4])
            loop
               t = int2bin(ptr,4)
               addr.ptr = ccall.getmem(t,4)
            until addr.ptr = cc$0 do
               t = ccall.getmem(addr.ptr,4)
               h.addrs<1,-1> = bin2ip(t)
               ptr += 4
            repeat
         end
      end

      return
   end
