From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,812965ed29240012 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wn11feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: Making a Inet_Addr_Type out of octects (GNAT.Sockets) Reply-To: no to spamers (No@email.given.org) References: <910108d9-03a0-4e35-86d2-572501a82906@z6g2000pre.googlegroups.com> X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Wed, 08 Oct 2008 01:53:17 GMT NNTP-Posting-Host: 12.65.150.104 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1223430797 12.65.150.104 (Wed, 08 Oct 2008 01:53:17 GMT) NNTP-Posting-Date: Wed, 08 Oct 2008 01:53:17 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:2274 Date: 2008-10-08T01:53:17+00:00 List-Id: 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 , "Jeffrey R. Carter" 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