comp.lang.ada
 help / color / mirror / Atom feed
From: anon@anon.org (anon)
Subject: Re: Making a Inet_Addr_Type out of octects (GNAT.Sockets)
Date: Wed, 08 Oct 2008 10:28:47 GMT
Date: 2008-10-08T10:28:47+00:00	[thread overview]
Message-ID: <zX%Gk.64090$Mh5.42428@bgtnsc04-news.ops.worldnet.att.net> (raw)
In-Reply-To: 910108d9-03a0-4e35-86d2-572501a82906@z6g2000pre.googlegroups.com

--
-- A.adb -- a simple test program that converts 4 8-bit words (Octets)
--            into GNAT.Sockets.Inet_Addr_Type variable and prints results.
--
with Ada.Text_IO ;
use  Ada.Text_IO ;
with Ada.Unchecked_Conversion ;

with GNAT.Sockets ;
use  GNAT.Sockets ;


procedure a is

   subtype Inet_Addr_Comp_Type is Natural range 0 .. 255;

   type Inet_Addr_VN_Type is array (Natural range <>) of Inet_Addr_Comp_Type;

   subtype Inet_Addr_V4_Type is Inet_Addr_VN_Type (1 ..  4);
   subtype Inet_Addr_V6_Type is Inet_Addr_VN_Type (1 .. 16);

   type Inet_Addr_Type (Family : Family_Type := Family_Inet) is record
      case Family is
         when Family_Inet =>
            Sin_V4 : Inet_Addr_V4_Type := (others => 0);

         when Family_Inet6 =>
            Sin_V6 : Inet_Addr_V6_Type := (others => 0);
      end case;
   end record;


   function To_Gnat is new Ada.Unchecked_Conversion
                      ( Inet_Addr_Type, GNAT.Sockets.Inet_Addr_Type ) ;


  newip : Inet_Addr_Type ;
  sysip : GNAT.Sockets.Inet_Addr_Type ;

begin -- a 

  -- Set 'newip' to 127.0.0.1

  newip.Sin_V4  ( 1 ) := 16#7F# ;
  newip.Sin_V4  ( 2 ) := 16#00# ;
  newip.Sin_V4  ( 3 ) := 16#00# ;
  newip.Sin_V4  ( 4 ) := 16#01# ;

  sysip := To_Gnat ( newip );

  Put_Line ( Image (  sysip ) ) ;

end a ;

In <910108d9-03a0-4e35-86d2-572501a82906@z6g2000pre.googlegroups.com>, mockturtle <framefritti@gmail.com> writes:
>Dear.all,
>a very simple (almost silly) question whose answer, I fear, is
>"no."...
>
>I have 4 octects (read by a received packet) which rappresent
>an IP address and  I want to convert them into a Inet_Addr_Type
>(using GNAT.Sockets). Of course I could convert the 4 octects
>into a string to be given to function Inet_Addr_Type, but it seems
>a bit "convoluted" (it sounds like the joke about the mathematician's
>algorithm to make a pot of hot water :-).   My question is: there
>is a  function which  allows me to do such a conversion in a
>more direct way? I looked at g-sockets, searching for
>"Inet_Addr_Type", but I could not  find anything.
>
>Thank you in advance.




      parent reply	other threads:[~2008-10-08 10:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-07 19:43 Making a Inet_Addr_Type out of octects (GNAT.Sockets) mockturtle
2008-10-07 20:11 ` Jeffrey R. Carter
2008-10-08  1:53   ` anon
2008-10-08 10:28 ` anon [this message]
replies disabled

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