From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.ada Subject: Re: AI12-0218: What is the portable representation clause for processing IETF packets on little-endian machines? Date: Thu, 10 May 2018 13:32:09 -0700 Organization: A noiseless patient Spider Message-ID: <877eob1cc6.fsf@nightsong.com> References: <9af47760-e731-4cb5-a1a0-d63e31019ce5@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="8ee8a87c586ad688bbbd7b3afaf6ee4e"; logging-data="2089"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/oY367fGRu/fXVZ+E9ZV7W" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) Cancel-Lock: sha1:Vyv0BO6rC0/3rsOxYZxcH8oFh7g= sha1:vyfmxudqqH7TizZQ39KMNM/TqvA= Xref: reader02.eternal-september.org comp.lang.ada:52212 Date: 2018-05-10T13:32:09-07:00 List-Id: "Dan'l Miller" writes: > And just in case anyone is thinking, “Oh, every single one of the new > designs of ISAs have been big-endian for decades No it's for real, you do have to consider enddianness in any network program, though like Dmitry I'm unconvinced that representation clauses are the way to do it in Ada. 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 <> when HLen>=5, 4*HLen= OptsLen = 4*(HLen - ?IP_MIN_HDR_LEN), <> = 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.