From: Kim Rostgaard Christensen <krc@greenpc.dk>
Subject: Re: Adding offset to 'Address
Date: Wed, 17 Sep 2008 11:15:11 +0200
Date: 2008-09-17T11:15:11+02:00 [thread overview]
Message-ID: <gaqhs6$690$1@jacob-sparre.dk> (raw)
In-Reply-To: <h5KdnbqILrtvxlbVnZ2dnUVZ_uSdnZ2d@comcast.com>
tmoran@acm.org wrote:
>> 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.
The problem was basically to perform arithmethics on system addresses
> 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;
This is a nice approch, I will try it out.
- Kim
next prev parent reply other threads:[~2008-09-17 9:15 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
2008-09-17 9:15 ` Kim Rostgaard Christensen [this message]
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