comp.lang.ada
 help / color / mirror / Atom feed
* Re: Help with calling gethostbyname in Win32-winsock binding
  2000-08-04  0:00 Help with calling gethostbyname in Win32-winsock binding Marin D. Condic
@ 2000-08-04  0:00 ` tmoran
  2000-08-05  0:00   ` Marin D. Condic
  0 siblings, 1 reply; 3+ messages in thread
From: tmoran @ 2000-08-04  0:00 UTC (permalink / raw)


>   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;
    ...




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Help with calling gethostbyname in Win32-winsock binding
@ 2000-08-04  0:00 Marin D. Condic
  2000-08-04  0:00 ` tmoran
  0 siblings, 1 reply; 3+ messages in thread
From: Marin D. Condic @ 2000-08-04  0:00 UTC (permalink / raw)


I'm trying to use the Win32-winsock interface provided with the GNAT
compiler to get the dotted quad(s) for the machine I'm running on. The
binding provides the following call:

    function gethostbyname(
                name: Win32.PCSTR)
               return PHOSTENT;

where:

    type PHOSTENT is access all HOSTENT;

    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;

    type PPCHAR is access all Win32.PSTR;

What I'm having a hard time figuring out is how to actually call this
thing. The confusion lies with the multitude of data types here, in
particular the PPCHAR type which is supposed to be, as far as I can
figure, a pointer to a list of pointers to strings. Has anybody used
this before? Could someone possibly post a code segment that shows how
to declare appropriate parameters and access them? Thanks.

MDC
-- 
======================================================================
Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
Visit my web site at:  http://www.mcondic.com/

"Nothing in the world is more dangerous than sincere ignorance and
conscientious stupidity."

    -- Martin Luther King, Jr
======================================================================




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Help with calling gethostbyname in Win32-winsock binding
  2000-08-04  0:00 ` tmoran
@ 2000-08-05  0:00   ` Marin D. Condic
  0 siblings, 0 replies; 3+ messages in thread
From: Marin D. Condic @ 2000-08-05  0:00 UTC (permalink / raw)


tmoran@bix.com wrote:
> 
> Extracted from the private part of Claw.Sockets' spec (approximately):
> 
<snip>

Thanks. This clarifies considerably. I'll try it in my own context and
see if I can make it work from there....

MDC
-- 
======================================================================
Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
Visit my web site at:  http://www.mcondic.com/

"Nothing in the world is more dangerous than sincere ignorance and
conscientious stupidity."

    -- Martin Luther King, Jr
======================================================================




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-08-05  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-04  0:00 Help with calling gethostbyname in Win32-winsock binding Marin D. Condic
2000-08-04  0:00 ` tmoran
2000-08-05  0:00   ` Marin D. Condic

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