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!feeder.eternal-september.org!feeder.erje.net!1.eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: AI12-0218: What is the portable representation clause for processing IETF packets on little-endian machines? Date: Fri, 11 May 2018 01:44:19 +0300 Organization: Tidorum Ltd Message-ID: References: <9af47760-e731-4cb5-a1a0-d63e31019ce5@googlegroups.com> <877eob1cc6.fsf@nightsong.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net XaSuR0Hojdlnkqis13xY1wU1qn3XGZgauZFxyQ2+oFBTN9DdT+ Cancel-Lock: sha1:No8kKZZZUFfEv3qEzIzd7RKcnSM= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: Xref: reader02.eternal-september.org comp.lang.ada:52224 Date: 2018-05-11T01:44:19+03:00 List-Id: On 18-05-11 01:24 , Dan'l Miller wrote: > 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 >> <> ID:16, Flgs:3, FragOff:13, >> TTL:8, Proto:8, HdrChkSum:16, >> SrcIP:32, >> DestIP:32, RestDgram/binary>> 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. > > 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. Both the example, and the Erlang reference manual section linked from the example, describe an "endianness" attribute that can be given one of the values "big", "little", "native", with default "big". However, it seems this attribute applies only to a restricted set of types: integer, utf16, utf32 and float. It is not clearly explained how endianness is interpreted for fields that do not align with octet boundaries. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .