From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,1064b0b019242d0f X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1994-03-14 11:55:11 PST Path: gmd.de!xlink.net!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!decwrl!pa.dec.com!nntpd.lkg.dec.com!alingo.zk3.dec.com!werme From: werme@alingo.uucp (Eric Werme USSG) Newsgroups: comp.unix.osf.osf1 Subject: Re: Under what conditions do xdr_long work? Date: 14 Mar 94 19:55:11 GMT Organization: Digital Equipment Corporation Message-ID: References: <1994Mar11.180129.3253@ida.liu.se> Reply-To: werme@zk3.dec.com NNTP-Posting-Host: alingo.zk3.dec.com Keywords: xdr_long, RPC, UDP, OSF V1.3 marsj@ida.liu.se (Martin Sjolin) writes: >I have problems understanding under >what conditions xdr_long works! >On HP-UX, Sun, Linux, Ultrix, SGI, etc sizeof(long) == sizeof(int). >Of course, I changed the existing xdr_long to use xdr_int instead. >Everything works, but then I would like to use long integer and started >to play with the xdr_long routines ... A lot of the xdr routines are confusingly named, so you probably should be confused. The XDR support in V1.2 and I think in V1.3 is also a little confused, but things are better in V2.0, which is now shipping. xdr_long() encodes longs in the XDR stream. Unfortunately, the stream only allocates 32 bits to the data. Therefore, there are new routines for 64 bit data. The man pages now explain the difficulty. Here are some that don't quite match V2.0, but are close enough. xdr_long(xdrs, lp) XDR *xdrs; long *lp; A filter primitive that translates between C long integers and their external representations. This routine returns one if it succeeds, zero otherwise. Note that the argument lp must be the C language type long. The amount of data encoded to the XDR stream is only 4 bytes (not the full 8 bytes of data represented by the C long type). This is because in the context of XDR streams a long type is considered to be 4 bytes. When data is encoded from the XDR stream, 4 bytes will be received from the XDR stream; the xdr_long interface then then sign extends the high order 4 bytes of the C long type. Prior to serializing the data on the ENCODE side the xdr_long performs a validity check to insure that the value represents a valid 32-bit signed number. This involves determining that the signed value is no less than the most negative 32-bit signed quantity (which is the hexa- decimal value 0x80000000) and no greater than the most positive 32-bit signed quantity (which is the hexadecimal value 0x7fffffff). If the value pointed to by the argument lp is not within this range the xdr_long interface returns an error. To translate the full 8 bytes of a C long, use the xdr_hyper inter- face. See the following section that explains the differences between xdr_long and xdr_hyper. xdr_longlong_t(xdrs, hp) XDR *xdrs; longlong_t *hp; A filter primitive that translates between C long integers and their external representations. (The typedef longlong_t is defined as long in the file , which is included from the file .) This routine will translate all 8 bytes of data to the XDR stream. Note that this differentiates this routine from xdr_long in that they both take a pointer to a long as an argument, while xdr_long only translates 4 bytes of data to the XDR stream. This rou- tine returns one if it succeeds, zero otherwise. The xdr_longlong_t routine is functionally equivalent to the xdr_hyper routine. See the following section that explains the differences between xdr_long and xdr_hyper. Differences Between xdr_long and xdr_hyper Routines On DEC OSF/1 platforms, the C programming language and the XDR routines apply different conventions to the definitions of the long data type. On DEC OSF/1 platforms, the C programming language applies the following conventions for int and long data types: __________________________ Data Type bits bytes __________________________ int 32 4 bytes long 64 8 bytes __________________________ The XDR routines apply the following conventions: __________________________ Data Type bits bytes __________________________ int 32 4 bytes long 32 4 bytes hyper 64 8 bytes __________________________ 8 bytes The xdr_long() and xdr_u_long() interfaces serialize 4 bytes of data. The xdr_hyper() and xdr_u_hyper() serialize 8 bytes of data. On DEC OSF/1 systems, the second argument to both xdr_long and xdr_hyper must be either a pointer or of the C language type long (8 bytes). When xdr_hyper is called with a parameter that points to a long all 8-bytes are serialized. In contrast, when xdr_long is called with a parameter that points to a long only the low order 4-bytes are serialized. When calling xdr_long on the DECODE operation, the upper 4-bytes of the long are sign extended in accordance with the high order bit of the lower 4-byte quantity. This is necessary to maintain the XDR convention of xdr_long serializing 4-bytes. If you want all 8-bytes to be serialized, use the xdr_hyper interface. The xdr_longlong_t and the xdr_u_longlong_t perform the same function as the xdr_hyper and the xdr_u_hyper interfaces respectively. >Now, why is that: >1). using xdrmem_create/xdrstdio_create to create a xdr stream > and then using xdr_long to encode a long (64bits) integer > worked(!), but If your long was beteween -2^32 and 2^32-1 it should have (though I think V1.3 would accept any value). >2). then I tried to use xdr_long within our xdr routines called > by callrpc/registerrpc (using UDP/IP as transport medium), > and of course the callrpc fails! I think it should have worked. I hope the above will explain the behaviour you see. BTW, xdr_hyper() was first, but I think xdr_longlong_t() is supplanting xdr_hyper(). I use xdr_longlong_t(). -- Eric (Ric) Werme | werme@zk3.dec.com Digital Equipment Corp. | This space intentionally left blank.