comp.lang.ada
 help / color / mirror / Atom feed
From: "Dan'l Miller" <optikos@verizon.net>
Subject: Re: AI12-0218:  What is the portable representation clause for processing IETF packets on little-endian machines?
Date: Thu, 10 May 2018 15:24:42 -0700 (PDT)
Date: 2018-05-10T15:24:42-07:00	[thread overview]
Message-ID: <c9986056-cc3d-432b-839d-fa226eb6e5f8@googlegroups.com> (raw)
In-Reply-To: <877eob1cc6.fsf@nightsong.com>

On Thursday, May 10, 2018 at 3:32:11 PM UTC-5, Paul Rubin wrote:
> "Dan'l Miller" writes:
> …  In C programs you usually just call some
> macros to convert machine integers to and from network byte order.  In
> the case where the machine int's bytes are already in network order, the
> macro does nothing.
> 
> Example 4 of this page
> 
>   http://erlang.org/doc/programming_examples/bit_syntax.html
> 
> shows how you describe an IP datagram in Erlang:
> 
>     -define(IP_VERSION, 4).
>     -define(IP_MIN_HDR_LEN, 5).
> 
>     DgramSize = byte_size(Dgram),
>     case Dgram of 
>         <<?IP_VERSION:4, HLen:4, SrvcType:8, TotLen:16, 
>           ID:16, Flgs:3, FragOff:13,
>           TTL:8, Proto:8, HdrChkSum:16,
>           SrcIP:32,
>           DestIP:32, RestDgram/binary>> when HLen>=5, 4*HLen=<DgramSize ->
>             OptsLen = 4*(HLen - ?IP_MIN_HDR_LEN),
>             <<Opts:OptsLen/binary,Data/binary>> = RestDgram,
>         ...
>     end.
> 
> It isn't bad, if you are used to Erlang syntax.  Those fields like
> FragOff:13 are bit fields of the specified lengths.

Ummmmmm, Paul, neither your example of C-esque bitfields in Erlang nor the Erlang tutorial page that you provided nor the Erland reference manual link in that tutorial page provided a solution to the byte-swapping.  How to actually accomplish the byte-swapping portably is the core topic of this entire thread and the core topic of AI12-0218.  Why post clearly off-topic material?  (Not only Erlang is prima facie off-topic, but bit fields in local-machine's endianness without any byte swapping is evermore off-topic, which could have been made somewhat on-topic if anything in Erlang demonstrated byte-swapping in opposing-endianness inter-machine communications, with an air of:  if Erlang can elegantly declare the byte-swapping portably on heterogenous endianness, then is there an analogous design in pre-AI12-0218 Ada?)

Everyone:
For example, in standard Ada without AI12-0218's proposal, how can one code up byte-swapping the fields of network byte order (big-endian) IETF packet headers on a little-endian machine?  Is there some clever switcheroo with processor-specific choice of child packages that contain little- versus big-endian subroutines analogous to the conditionally-compiled different definitions of C macros that both Paul and I have mentioned?

Paul:
Btw, bitfields in C and in Erlang are •the• roughly analogous language feature corresponding to representation clauses in Ada; all the undefined behavior regarding bitfields in C notwithstanding.  Indeed, AIUI, C's bitfields & their 1970s-known undefined behavior when porting among different processors were the public enemy #1 on Ichbiah et al's minds when they put bitwise representation clauses in Ada.  So you undermined your own line of reasoning there.


  reply	other threads:[~2018-05-10 22:24 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 [this message]
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
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