[comp.sys.dec] Problems with ntohs

goldstn@evax.arl.utexas.edu (David Goldstein) (02/19/91)

I have run into a seemingly insurmountable problem when communicating
between DEC (Ultrix) and Sun machines using TCP/IP.  The two machines
reverse bytes, which is handled by the ntohs, ntohl commands.  However,
I have an application sending floats.  Interestingly, if one does:

printf("The value should be %f",ntohs(x));   

then one gets a sort-of reasonable, predictable answer.  However, if one
does:

x = ntohs(x);
printf("x is now %f",x);

then one realizes that the Vax SEEMS to do some funny things with the
high order bits, transforming a very small number into an incorrect,
large one....
any experiences or suggestions on surmounting this would be
appreciated! thanks!
david

warren@atmos.washington.edu (David Warren) (02/20/91)

Are we discussing VAX ULTRIX or risc ULTRIX. If your ULTRIX is on a
DECstation, you should be able to just reverse the byte order. (I
believe that NFS will even do it for you automatically). If, however,
you ULTRIX is on VAX architecture you will need to also convert
between VAX and IEEE floating point. On a DECstation there are the
routines ftoi, itof, dtoi, itod, gtoi and itog that take care of this. I
have also seen programs that run under VMS to do the same things.
There is probably someone out there that already has them under SUNOS.
--
David Warren 		INTERNET: warren@atmos.washington.edu
(206) 543-0945		UUCP:	  uw-beaver!atmos.washington.edu!warren
Dept of Atmospheric Sciences, AK-40
University of Washington

fkittred@bbn.com (Fletcher Kittredge) (02/20/91)

In article <WARREN.91Feb19143825@rainbow.atmos.washington.edu> warren@atmos.washington.edu (David Warren) writes:
>Are we discussing VAX ULTRIX or risc ULTRIX. If your ULTRIX is on a
>DECstation, you should be able to just reverse the byte order. (I
>believe that NFS will even do it for you automatically). If, however,
>you ULTRIX is on VAX architecture you will need to also convert
>between VAX and IEEE floating point. On a DECstation there are the
>routines ftoi, itof, dtoi, itod, gtoi and itog that take care of this. I
>have also seen programs that run under VMS to do the same things.
>There is probably someone out there that already has them under SUNOS.

I suspect the cleanest solution to your problem is to use XDR.  XDR is
avaliable, documented and supported on the Sun.  XDR is available and
undocumented on Ultrix.  I have no idea if DEC is supporting its use
or not.  Since NCS seems to be lacking this feature (A general purpose,
standalone data conversion facility), it would be in DEC's interest to
to support XDR (which probably means they won't).

RPC/XDR is in the public domain and is floating around the net.  A copy of
an implementation lives on uunet.uu.net, available for anonymous FTP.

regards,
fletcher

Fletcher Kittredge
Platforms and Tools Group, BBN Software Products
10 Fawcett Street,  Cambridge, MA. 02138
617-873-3465  /  fkittred@bbn.com  /  fkittred@das.harvard.edu