NSPR sockets between NT and SGI

RESOLVED INVALID

Status

P3
blocker
RESOLVED INVALID
18 years ago
18 years ago

People

(Reporter: ktoishi, Assigned: wtc)

Tracking

x86
Windows NT

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

18 years ago
When sending an integer, float, double, or long double between a SGI and NT 
machine using PR_Send and PR_Recv, the number recieved has a different byte 
order than the number sent.

the following data table shows the binary representation of an integer just 
before sending and just after being recieved between an SGI and NT machine.

int x = 1147499097 

          0123 4567 8901 2345 6789 0123 4567 8901 
  SGI     1001 1010 0100 1110 1010 0110 0010 0010         sender 
  PC      0010 0010 1010 0110 0100 1110 1001 1010         reciever 


int x = 1238380906 

          0123 4567 8901 2345 6789 0123 4567 8901 
  PC      0101 0110 1000 1100 0000 1011 1001 0010         sender 
  SGI     1001 0010 0000 1011 1000 1100 0101 0110         reciever 


bits 0-7   are shifted to  24-31 
bits 8-15  are shifted to  16-23 
bits 16-23 are shifted to  8-15 
bits 24-31 are shifted to  0-7



the problem does not occur when sending NT to NT or SGI to SGI.



Any help would be greatly appreciated.


Thank you,
Kevin Oishi
Sandia National Laboratories
(Assignee)

Comment 1

18 years ago
This has to do with the byte order (little endian
vs. big endian).

If you need to exchange binary integer data
between different machines, it is best to convert
the data to the "network byte order" before passing
it to PR_Send(), and on the receiving side, convert
the received data back to the "host byte order"
before use.

PR_htons converts a PRUint16 from host byte order
to network byte order.
PR_htonl converts a PRUint32 from host byte order
to network byte order.
PR_ntohs and PR_ntohl convert in the other direction.

I am not sure about binary float, double, and long
double data though.

The most portable way to exchange data between
machines is to convert the binary data into strings
and exchange the strings.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 18 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.