comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Adding offset to 'Address
Date: Sat, 13 Sep 2008 01:21:38 -0500
Date: 2008-09-13T01:21:38-05:00	[thread overview]
Message-ID: <h5KdnbqILrtvxlbVnZ2dnUVZ_uSdnZ2d@comcast.com> (raw)
In-Reply-To: ab194d94-6a10-4e83-bd2e-79966a07f90a@a2g2000prm.googlegroups.com

>  Raw_Bytes : access Unsigned_Char
>  for Ethernet_Header'Address use Raw_Bytes.all'Address;
>
>and additionally need something like:
>  for IP_Packet'Address use Raw_Bytes.all'Address + Ethernet_Header'Size;

It's not clear to me exactly what problem you are trying to get past.
How about something like:

with Ada.Unchecked_Conversion,
     Interfaces.C;
procedure Eiptest is
  type Ethernet_Header_Type is new Integer;          -- or whatever
  type IP_Packet_Type is array (1 .. 5) of Integer;  -- "

  type R_Type is record
    Ethernet_Header: Ethernet_Header_Type;
    IP_Packet: IP_Packet_Type;
    Other_Stuff : Integer;
  end record;
  for R_Type use record
    Ethernet_Header at 0 range 0 .. 31;
    IP_Packet at 4 range 0 .. 159;
    Other_Stuff at 30 range 0 .. 31;
  end record;

  type Lpvoid is access all Interfaces.C.Char;
  type R_Ptr_Type is access all R_Type;

  function Convert is new Ada.Unchecked_Conversion
    (Source => Lpvoid, Target => R_Ptr_Type);

  procedure Process(Raw_Bytes: in Lpvoid) is
    R_Ptr   : constant R_Ptr_Type := Convert(Raw_Bytes);
    This_IP_Packet: IP_Packet_Type renames R_Ptr.IP_Packet;
  begin
    null; -- do something with This_IP_Packet
  end Process;

  Buffer : Interfaces.C.Char_Array(1 .. 100);

begin
  Process(Buffer(1)'access);
end Eiptest;



  parent reply	other threads:[~2008-09-13  6:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-12  8:35 Adding offset to 'Address Kim Rostgaard Christensen
2008-09-12  9:47 ` Georg Bauhaus
2008-09-12 10:17   ` Kim Rostgaard Christensen
2008-09-12 11:18     ` petter_fryklund
2008-09-12 15:23 ` Adam Beneschan
2008-09-12 21:40   ` Robert A Duff
2008-09-13  0:37     ` Adam Beneschan
2008-09-13  6:21   ` tmoran [this message]
2008-09-17  9:15     ` Kim Rostgaard Christensen
2008-09-19  6:09       ` Randy Brukardt
2008-09-19  9:25         ` anon
2008-09-13 10:18 ` Björn
2008-09-17  9:18   ` Kim Rostgaard Christensen
replies disabled

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