comp.lang.ada
 help / color / mirror / Atom feed
From: AdaMagica <christ-usch.grein@t-online.de>
Subject: Re: AI12-0218:  What is the portable representation clause for processing IETF packets on little-endian machines?
Date: Fri, 11 May 2018 07:21:32 -0700 (PDT)
Date: 2018-05-11T07:21:32-07:00	[thread overview]
Message-ID: <235d41bc-d7a5-4c66-9dac-640dce5f20c5@googlegroups.com> (raw)
In-Reply-To: <ec0145a4-9698-41f2-bc70-964dc1850e50@googlegroups.com>

Am Donnerstag, 10. Mai 2018 19:45:43 UTC+2 schrieb Dan'l Miller:
> The Challenge:
> Without the proposed solution in AI12-0218, I challenge anyone to write an Ada representation clause that is •portable• to both little-endian and big-endian processors for either of the following IETF packet formats that must always be in big-endian network byte order:
> https://en.wikipedia.org/wiki/IPv4#Packet_structure
> https://en.wikipedia.org/wiki/IPv6_packet

I'm not sure this is what you are looking for:

  for IPv4 use record
    Version                at  0 range  0 ..  3;
    IHL                    at  0 range  4 ..  7;
    DSCP                   at  0 range  8 .. 13;
    ECN                    at  0 range 14 .. 15;
    Total_Length           at  0 range 16 .. 31;
    Identification         at  4 range  0 .. 15;
    Flags                  at  4 range 16 .. 18;
    Fragment_Offset        at  4 range 19 .. 31;
    Time_to_Live           at  8 range  0 ..  7;
    Protocol               at  8 range  8 .. 15;
    Header_Checksum        at  8 range 16 .. 31;
    Source_IP_Address      at 12 range  0 .. 31;
    Destination_IP_Address at 16 range  0 .. 31;
  end record;
  for IPv4'Bit_Order use System.High_Order_First;

Of course you have to byte-swap after a transfer.

GNAT reports this upne compilation:
reverse bit order in machine scalar of length 32
little-endian range for component "Version" is 28 .. 31
reverse bit order in machine scalar of length 32
little-endian range for component "IHL" is 24 .. 27
reverse bit order in machine scalar of length 32
little-endian range for component "DSCP" is 18 .. 23
reverse bit order in machine scalar of length 32
little-endian range for component "ECN" is 16 .. 17
reverse bit order in machine scalar of length 32
little-endian range for component "Total_Length" is 0 .. 15
reverse bit order in machine scalar of length 32
little-endian range for component "Identification" is 16 .. 31
reverse bit order in machine scalar of length 32
little-endian range for component "Flags" is 13 .. 15
reverse bit order in machine scalar of length 32
little-endian range for component "Fragment_Offset" is 0 .. 12
reverse bit order in machine scalar of length 32
little-endian range for component "Time_to_Live" is 24 .. 31
reverse bit order in machine scalar of length 32
little-endian range for component "Protocol" is 16 .. 23
reverse bit order in machine scalar of length 32
little-endian range for component "Header_Checksum" is 0 .. 15
reverse bit order in machine scalar of length 32
little-endian range for component "Source_IP_Address" is 0 .. 31
reverse bit order in machine scalar of length 32
little-endian range for component "Destination_IP_Address" is 0 .. 31

You might want to look at:
https://en.wikibooks.org/wiki/Ada_Programming/Attributes/%27Bit_Order

  parent reply	other threads:[~2018-05-11 14:21 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-10 17:45 AI12-0218: What is the portable representation clause for processing IETF packets on little-endian machines? Dan'l Miller
2018-05-10 19:24 ` Dan'l Miller
2018-05-10 20:32   ` Paul Rubin
2018-05-10 22:24     ` Dan'l Miller
2018-05-10 22:44       ` Niklas Holsti
2018-05-10 23:14         ` Paul Rubin
2018-05-11  2:38         ` Dan'l Miller
2018-05-11  7:55           ` Simon Wright
2018-05-11 12:11             ` Lucretia
2018-05-11 13:49               ` Simon Wright
2018-05-11 16:11                 ` Jeffrey R. Carter
2018-05-11 16:48                   ` Simon Wright
2018-05-11 19:08                     ` Jeffrey R. Carter
2018-05-11 21:39                       ` Simon Wright
2018-05-11 21:56                         ` Jeffrey R. Carter
2018-05-12  7:08                           ` Simon Wright
2018-05-12  7:53                             ` Jeffrey R. Carter
2018-05-14 22:43                             ` Randy Brukardt
2018-05-11 13:46             ` Simon Wright
2018-05-11 22:12           ` Randy Brukardt
2018-05-12 10:33             ` Björn Lundin
2018-05-12 13:08               ` Simon Wright
2018-05-12 14:21                 ` Björn Lundin
2018-05-10 23:07       ` Paul Rubin
2018-05-11  0:14         ` Dan'l Miller
2018-05-11  0:30           ` Paul Rubin
2018-05-11  0:50             ` Dan'l Miller
2018-05-11  1:34               ` Paul Rubin
2018-05-11  2:11                 ` Dan'l Miller
2018-05-11 22:32                   ` Randy Brukardt
2018-05-11  8:02         ` Simon Wright
2018-05-11 22:14         ` Randy Brukardt
2018-05-10 19:28 ` Simon Wright
2018-05-10 22:40   ` Randy Brukardt
2018-05-10 22:50     ` Dan'l Miller
2018-05-11 22:00       ` Randy Brukardt
2018-05-12  1:15         ` Paul Rubin
2018-05-14 22:54           ` Randy Brukardt
2018-05-15  0:43             ` Paul Rubin
2018-05-15 21:39               ` Randy Brukardt
2018-05-15  0:44             ` Dennis Lee Bieber
2018-05-11  8:09     ` Simon Wright
2018-05-10 19:34 ` Dmitry A. Kazakov
2018-05-10 20:06   ` Dan'l Miller
2018-05-10 22:44     ` Paul Rubin
2018-05-10 22:50     ` Randy Brukardt
2018-05-11  9:40       ` Niklas Holsti
2018-05-11 11:40         ` Dan'l Miller
2018-05-11 20:16           ` Niklas Holsti
2018-05-11  9:40     ` Dmitry A. Kazakov
2018-05-11 14:21 ` AdaMagica [this message]
2018-05-26 16:15 ` Dan'l Miller
2018-05-26 19:02   ` AdaMagica
2018-05-26 21:01     ` Dan'l Miller
2018-05-27 14:58       ` AdaMagica
2018-05-27 18:03         ` Simon Wright
2018-05-29 22:17           ` Randy Brukardt
2018-05-30  6:39             ` Simon Wright
2018-05-30  7:25               ` Dmitry A. Kazakov
2018-05-30 15:01                 ` Simon Wright
2018-05-30 15:59                   ` Dan'l Miller
2018-05-30 19:38               ` Randy Brukardt
2018-05-27 18:04         ` Dan'l Miller
replies disabled

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