comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@bix.com
Subject: Re: Help with calling gethostbyname in Win32-winsock binding
Date: 2000/08/04
Date: 2000-08-04T00:00:00+00:00	[thread overview]
Message-ID: <VmIi5.129$Rw4.76908@news.pacbell.net> (raw)
In-Reply-To: 398B43E9.C5EE7187@acm.org

>   type HOSTENT is
>       record
>           h_name     : Win32.PSTR;
>           h_aliases  : PPCHAR;
>           h_addrtype : Win32.SHORT;
>           h_length   : Win32.SHORT;
>           h_addr_list: PPCHAR;
>       end record;

Extracted from the private part of Claw.Sockets' spec (approximately):

  type Network_Address_Type is new Interfaces.C.Unsigned_Long;
  -- In network byte order.

  type Ptr_To_Network_Address_Type is access all Network_Address_Type;

  Max_Host_Count : constant := 10;

  type Host_Address_List_Type is array(1 .. Max_Host_Count)
  of Ptr_To_Network_Address_Type;
  -- (1 .. N), null terminated.  Declare fixed size so no dope vector.

  type Host_Address_List_Ptr_Type is access all Host_Address_List_Type;

  subtype Host_Alias_Ptr_List_Type
  is Interfaces.C.Strings.Chars_Ptr_Array (1 .. Max_Host_Count);
  -- (1 .. N), null terminated.  Declare fixed size so no dope vector.

  type Host_Alias_List_Ptr_Type is access all Host_Alias_Ptr_List_Type;

  PF_INET : constant := 2;

  type HOSTENTs is record
      Host_Name_Ptr : Interfaces.C.Strings.Chars_Ptr;     -- h_name
      Host_Alias_Ptr_List : Host_Alias_List_Ptr_Type;     -- h_aliases
      Host_Address_Kind : Interfaces.C.Short:=PF_INET;    -- h_addrtype
      Host_Address_Length : Interfaces.C.Short:= 4;       -- h_length
      Host_Address_List_Ptr : Host_Address_List_Ptr_Type; -- h_addr_list
  end record;
  for Hostents use record
      Host_Name_Ptr at 0 range 0 .. 31;
      Host_Alias_Ptr_List at 4 range 0 .. 31;
      Host_Address_Kind at 8 range 0 .. 15;
      Host_Address_Length at 10 range 0 .. 15;
      Host_Address_List_Ptr at 12 range 0 .. 31;
  end record;
  for Hostents'size use 16*8;

  -- Note: in Claw.Win32, type Lpcstr is access all Interfaces.C.Char;

  function gethostbyname(name: Claw.Win32.LPCStr) return Hostent_Ptr_Type;
  pragma Import(Stdcall, gethostbyname, "gethostbyname");

  type Host_Info_Type is record
    Hostent : Hostents;
    ...

and in the body:

  function Host_Address (Info : in Host_Info_Type;
                         I    : in Positive) return Network_Address_Type is
  -- return the Ith network address in Info
  begin
    for j in Host_Address_List_Type'range loop
      exit when Info.Hostent.Host_Address_List_Ptr.all(j) = null;
      if I = j then
        return Info.Hostent.Host_Address_List_Ptr.all(j).all;
      end if;
    end loop;
    ...




  reply	other threads:[~2000-08-04  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-08-04  0:00 Help with calling gethostbyname in Win32-winsock binding Marin D. Condic
2000-08-04  0:00 ` tmoran [this message]
2000-08-05  0:00   ` Marin D. Condic
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox