From: anon@anon.org (anon)
Subject: Re: Making a Inet_Addr_Type out of octects (GNAT.Sockets)
Date: Wed, 08 Oct 2008 01:53:17 GMT
Date: 2008-10-08T01:53:17+00:00 [thread overview]
Message-ID: <hoUGk.260392$102.193109@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: joPGk.376724$yE1.161337@attbi_s21
if you mean "4 octects" is 4 byte array, then
with GNAT.Sockets.Thin ;
use GNAT.Sockets.Thin ;
Bytes : array ( 0..3 ) of Interfaces.C.unsigned_char;
Sin_Addr : In_Addr ;
Sin_Addr.S_B1 := Bytes ( 0 ) ;
Sin_Addr.S_B2 := Bytes ( 1 ) ;
Sin_Addr.S_B3 := Bytes ( 2 ) ;
Sin_Addr.S_B4 := Bytes ( 3 ) ;
-- located with in GNAT.Socket package
with GNAT.Sockets.Thin ;
use GNAT.Sockets.Thin ;
Sin : aliased Sockaddr_In ;
Sin.Sin_Addr.S_B1 := 127 ;
Sin.Sin_Addr.S_B2 := 0 ;
Sin.Sin_Addr.S_B3 := 0 ;
Sin.Sin_Addr.S_B4 := 1 ;
Then there a string version:
with GNAT.Sockets ;
use GNAT.Sockets ;
localhost : constant Inet_Addr_Type := Inet_Addr ( "127.0.0.1" ) ;
As for "Inet_Addr_Type" it is defined in in GNAT.Sockets
copy edit out Family_Inet6 ( IPv6 ). Following is copied from
GNAT.Sockets.ads .
type Family_Type is (Family_Inet, Family_Inet6);
type Inet_Addr_Type (Family : Family_Type := Family_Inet) is private;
-- An Internet address depends on an address family (IPv4 contains 4
-- octets and Ipv6 contains 16 octets). Any_Inet_Addr is a special value
-- treated like a wildcard enabling all addresses. No_Inet_Addr provides a
-- special value to denote uninitialized inet addresses.
Broadcast_Inet_Addr : constant Inet_Addr_Type;
private
subtype Inet_Addr_Comp_Type is Natural range 0 .. 255;
-- Octet for Internet address
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;
-- set address value to IPv4 "255.255.255.255"
Broadcast_Inet_Addr : constant Inet_Addr_Type :=
(Family_Inet, (others => 255));
In <joPGk.376724$yE1.161337@attbi_s21>, "Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org> writes:
>mockturtle wrote:
>>
>> 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.
>
>I'm not aware of any way provided by the pkg other than that you outlined above.
>
>There are ways using Unchecked_Conversion and address overlays, but they are Not
>Recommended.
>
>--
>Jeff Carter
>"My legs are gray, my ears are gnarled, my eyes are old and bent."
>Monty Python's Life of Brian
>81
next prev parent reply other threads:[~2008-10-08 1:53 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 [this message]
2008-10-08 10:28 ` anon
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox