From: Adam Beneschan <adam@irvine.com>
Subject: Re: Adding offset to 'Address
Date: Fri, 12 Sep 2008 08:23:23 -0700 (PDT)
Date: 2008-09-12T08:23:23-07:00 [thread overview]
Message-ID: <ab194d94-6a10-4e83-bd2e-79966a07f90a@a2g2000prm.googlegroups.com> (raw)
In-Reply-To: gad9lc$77a$1@jacob-sparre.dk
On Sep 12, 1:35 am, Kim Rostgaard Christensen <k...@greenpc.dk> wrote:
> Hi
>
> How does one go about setting a 'Address + (size of other record) to a
> record at runtime ?
>
> In brief, I am switching over "Frametype" in a Ethernet frame record, to
> dynamically assign the next record by type (IPv4,IPv6,ARP, etc.)
> My "datablob" is a *u_char from a imported C function.
>
> So I have:
>
> 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;
Well, 'Size gives you a value in bits, not bytes, so this needs to be
changed. The value in "storage units" (which is 8-bit bytes on most
machines but is occasionally something different) would be given by
(Ethernet_Header'Size + System.Storage_Unit - 1) /
System.Storage_Unit
which rounds the size in bits up to the next multiple of
System.Storage_Unit. [System.Storage_Unit will equal 8 on most
systems.]
Then, there's a "+" function in System.Storage_Elements that adds an
Address to a Storage_Offset and yields an Address (and another "+"
function that takes the arguments in the other order). If you say
"use System.Storage_Elements" or "use type
System.Storage_Elements.Storage_Offset", then you can say
for IP_Packet'Address use Raw_Bytes.all'Address +
((Ethernet_Header'Size + System.Storage_Unit - 1) /
System.Storage_Unit);
assuming that the IP packet always starts at the next memory location
after the Ethernet_Header.
-- Adam
next prev parent reply other threads:[~2008-09-12 15:23 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 [this message]
2008-09-12 21:40 ` Robert A Duff
2008-09-13 0:37 ` Adam Beneschan
2008-09-13 6:21 ` tmoran
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