help / color / mirror / Atom feed
* gnat -xdr flag confusion.
@ 2023-07-04 10:56 magardner2010
  2023-07-04 11:39 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 3+ messages in thread
From: magardner2010 @ 2023-07-04 10:56 UTC (permalink / raw)

I'm still working on the p2p one-to-many data streaming protocol thing 
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_INET6 = 1,

union inet_addr_type switch (family_type family) {
   case FAMILY_INET:
     opaque sin_v4[4];
   case FAMILY_INET6:
     opaque sin_v6[16];

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;

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).

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-06 17:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-04 10:56 gnat -xdr flag confusion magardner2010
2023-07-04 11:39 ` Dmitry A. Kazakov
2023-07-06 17:32   ` magardner2010

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