From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: magardner2010 Newsgroups: comp.lang.ada Subject: gnat -xdr flag confusion. Date: Tue, 4 Jul 2023 13:56:26 +0300 Organization: A noiseless patient Spider Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 4 Jul 2023 10:56:27 -0000 (UTC) Injection-Info: dont-email.me; posting-host="8b58e21d8aa207bd5829e6e61f9e0d23"; logging-data="101854"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tMcdlOxeSQZQE0dz1PxHRVSGGoROuGoc=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Cancel-Lock: sha1:tz+SJ4kSBFD7kINmNsRvFYUfZm0= Content-Language: en-GB Xref: news.eternal-september.org comp.lang.ada:65422 List-Id: I'm still working on the p2p one-to-many data streaming protocol thing (at https://github.com/smeagolthellama/szakdolgozat-notes/tree/main/ada) and I'm trying to get it to communicate with a C thing via the xdr protocol. I'm trying to transfer a Child_Set, where ``` type Child_Number is range 0 .. 2; subtype Child_Index is Child_Number range 1 .. Child_Number'Last; type Child_Set is array (Child_Index) of GNAT.Sockets.Sock_Addr_Type; ``` With the help of chatGPT, I wrote the following xdr spec file: ``` const CHILD_NUMBER = 2; typedef unsigned int uint32; typedef unsigned char uint8; enum family_type { FAMILY_INET = 0, FAMILY_INET6 = 1, FAMILY_UNIX = 2, FAMILY_UNSPEC = 3 }; union inet_addr_type switch (family_type family) { case FAMILY_INET: opaque sin_v4[4]; case FAMILY_INET6: opaque sin_v6[16]; default: void; }; struct address_and_port{ inet_addr_type addr; unsigned int port; }; union sock_addr_type switch (family_type family) { case FAMILY_UNIX: string name<>; case FAMILY_INET: address_and_port anp4; case FAMILY_INET6: address_and_port anp6; case FAMILY_UNSPEC: void; }; struct child_set { sock_addr_type child_set_array[CHILD_NUMBER]; }; ``` and using rpcgen, generated a C thing to encode/decode the messages the ada program is sending. However, if the ada code encodes the object with 'write, then it creates something about 4 bytes too short, and if I use 'output, it is parsed as starting with family_type 256, which is not a member of the enum. Given that the gnat documentation for the -xdr flag is literally two lines, I don't really know where to look for more information on what I'm doing wrong. My current hypotheses include the C code having the family type recorded too many times (but I don't know how to check or fix that in the .x file) or the ada code not encoding the data according to the xdr standard correctly (but I am using the flag, and neither 'write or 'output fixes it).